Skip to contents

Select randomly a periodic autoregression model and return the periodic autocovariances associated with it.

Usage

sim_parAcvf(period, order, sigma2)

Arguments

period

the period, a positive integer.

order

the AR order, a vector of non-negative integers.

sigma2

the variances of the innovations, a numeric vector of length period (todo: or one?).

Details

Uses sim_parCoef() to generate a random PAR model.

Value

an object of class "matrix". In addition, the specification of the model is in attribute "model" which is a list with the following components:

ar

a matrix, the coefficients of the PAR model,

sigma2

numeric, the innovation variances,

order

the PAR order.

References

Boshnakov GN, Iqelan BM (2009). “Generation of time series models with given spectral properties.” J. Time Series Anal., 30(3), 349--368. ISSN 0143-9782, doi: 10.1111/j.1467-9892.2009.00617.x .

Author

Georgi N. Boshnakov

Examples

sim_parAcvf(2, 5)
#>          [,1]     [,2]      [,3]     [,4]        [,5]       [,6]
#> [1,] 9.358814 2.522674 2.5124571 0.856207 -2.40770958 -0.8544942
#> [2,] 2.112913 1.884455 0.7005551 2.289959 -0.07141546 -0.2990444
#> attr(,"model")
#> attr(,"model")$ar
#>      [,1]      [,2]       [,3]      [,4]       [,5]       [,6]
#> [1,]    1 2.4817868 -0.1287243 0.4691656 -1.1946248 1.00237503
#> [2,]    1 0.2076349 -0.1122449 0.3412125 -0.5485619 0.06778367
#> 
#> attr(,"model")$sigma2
#> [1] 1 1
#> 
#> attr(,"model")$order
#> [1] 5
#> 
sim_parAcvf(3, 5)
#>           [,1]      [,2]      [,3]      [,4]      [,5]      [,6]
#> [1,]  5.549885 -6.570274  4.887329 -2.372852  2.032531 -6.390012
#> [2,] 12.945914  3.088179 -5.663175 -5.053098 -4.313226  8.962977
#> [3,] 14.090953 -2.984629  5.917724 -9.868204  8.222589 -3.435384
#> attr(,"model")
#> attr(,"model")$ar
#>      [,1]       [,2]       [,3]       [,4]        [,5]        [,6]
#> [1,]    1 -0.2301267  0.3685835 -0.4352324 -0.08414653 -0.05865233
#> [2,]    1  2.4366551  0.3492087 -1.2693042  1.38636587  0.66546053
#> [3,]    1 -0.3805371 -0.3151011 -0.3951479  0.76598366 -1.05435211
#> 
#> attr(,"model")$sigma2
#> [1] 1 1 1
#> 
#> attr(,"model")$order
#> [1] 5
#> 

res <- sim_parAcvf(2, 6)
res
#>          [,1]     [,2]      [,3]      [,4]      [,5]       [,6]       [,7]
#> [1,] 292.9796  33.0503 140.31049 -94.47060 -146.7802 -117.26143 -265.28835
#> [2,]  63.8744 131.4541  28.53415  88.76269  -35.7699  -45.78448  -58.83145
#> attr(,"model")
#> attr(,"model")$ar
#>      [,1]       [,2]      [,3]        [,4]       [,5]       [,6]       [,7]
#> [1,]    1 -4.5725434 2.3809656  1.22061700 -0.8770059 -2.4880512 0.73933919
#> [2,]    1  0.3318615 0.5358023 -0.07277562 -0.5674673  0.1295568 0.06706686
#> 
#> attr(,"model")$sigma2
#> [1] 1 1
#> 
#> attr(,"model")$order
#> [1] 6
#> 
slMatrix(res)[3, 4, type = "tt"]
#>          [,1]
#> [1,] 131.4541

res <- sim_parAcvf(2, 4)
attr(res, "model")
#> $ar
#>      [,1]        [,2]      [,3]         [,4]        [,5]
#> [1,]    1  0.04749011 0.1370366  0.001487516 -0.01430092
#> [2,]    1 -2.69264664 0.4206360 -0.366223772 -0.06669012
#> 
#> $sigma2
#> [1] 1 1
#> 
#> $order
#> [1] 4
#> 
acv <- res[ , ] # drop attributes

acv[2, 1 + 0]
#> [1] 10.72522
acv[2, 1 + 1]
#> [1] -2.67572
slMatrix(acv)[2, 0]
#> [1] 10.72522
slMatrix(acv)[2, 1]
#> [1] -2.67572
slMatrix(acv)[3, 4, type = "tt"]
#>          [,1]
#> [1,] -2.67572
slMatrix(acv)[1:2, 1:2, type = "tt"]
#>           [,1]     [,2]
#> [1,]  1.011482 -2.67572
#> [2,] -2.675720 10.72522
slMatrix(acv)[1:4, 1:4, type = "tt"]
#>             [,1]       [,2]        [,3]      [,4]
#> [1,]  1.01148176 -2.6757202  0.01162881 -1.538695
#> [2,] -2.67572020 10.7252169  0.17168811  4.714611
#> [3,]  0.01162881  0.1716881  1.01148176 -2.675720
#> [4,] -1.53869505  4.7146112 -2.67572020 10.725217

## TODO: need method for autocorrelation()
## pc.acrf(acv)

## TODO: these need changing, after the change of the return values of sim_parAcvf
## pc.fcoeffs(acv, 2)
## pc.fcoeffs(acv, 3)
## pc.fcoeffs(acv, 4)
pcts:::calc_predictionCoefficients(acv, c(2, 2))
#>      [,1]        [,2]       [,3]
#> [1,]    1 -0.05551134 -0.1583436
#> [2,]    1  2.72737196 -0.4832414
pcts:::calc_predictionCoefficients(acv, c(3, 3))
#>      [,1]       [,2]       [,3]         [,4]
#> [1,]    1 -0.0501526 -0.1435260 -0.003781037
#> [2,]    1  2.6934964 -0.3261654  0.627441294
pcts:::calc_predictionCoefficients(acv, c(4, 4))
#>      [,1]        [,2]       [,3]         [,4]       [,5]
#> [1,]    1 -0.04749011 -0.1370366 -0.001487516 0.01430092
#> [2,]    1  2.69264664 -0.4206360  0.366223772 0.06669012