Varmapack simulates Gaussian vector autoregressive-moving-average models with exact stationary initialization. The first returned values therefore have the model-implied distribution without discarding a burn-in segment.
Create a model from coefficient matrices and its innovation
covariance. A single lag may be supplied as a matrix; multiple lags use
an r by r by lag array.
A <- matrix(c(0.5, 0.1,
0.0, 0.3), 2, 2)
B <- matrix(c(0.2, 0.0,
0.1, 0.1), 2, 2)
model <- varmapack_model(A = A, B = B, Sig = diag(2))
rng <- randompack_rng()
rng$seed(123)
X <- model$sim(100, nrep = 3, rng = rng)
dim(X)
#> [1] 2 100 3The first dimension is the series dimension, the second is time, and the third selects the replicate. Requesting shocks returns a named list.
out <- model$sim(20, nrep = 2, rng = rng, return_shocks = TRUE)
names(out)
#> [1] "X" "E"
dim(out$E)
#> [1] 2 20 2Built-in testcases return model objects.
varmapack_testcases()
#> index name p q r
#> 1 1 tinyAR 1 0 1
#> 2 2 tinyMA 0 1 1
#> 3 3 tinyARMA 1 1 1
#> 4 4 smallAR1 1 0 2
#> 5 5 smallAR2 2 0 2
#> 6 6 smallMA1 0 1 2
#> 7 7 smallMA2 0 2 2
#> 8 8 smallARMA1 1 1 2
#> 9 9 smallARMA2 1 2 2
#> 10 10 mediumAR 1 0 3
#> 11 11 mediumMA1 0 1 3
#> 12 12 mediumARMA1 3 3 3
#> 13 13 mediumARMA2 3 3 3
#> 14 14 mediumMA2 0 2 3
#> 15 15 largeAR 5 0 7
#> 16 16 largeARMA 3 3 7
test_model <- varmapack_testcase("smallARMA1")
test_model$specrad()
#> [1] 0.4561553Model methods provide theoretical autocovariances, impulse responses, and the AR and MA spectral radii.
Gamma <- model$acvf(10)
Psi <- model$psi(10)
Theta <- model$irf(10)
model$specrad()
#> [1] 0.5
model$ma_specrad()
#> [1] 0.2The varmapack_autocov() function computes sample
autocovariances for an observed time-series matrix with variables in
rows.
varmapack_autocov(X[, , 1], maxlag = 5)
#> , , 1
#>
#> [,1] [,2]
#> [1,] 1.9132623 0.1434708
#> [2,] 0.1434708 1.2919753
#>
#> , , 2
#>
#> [,1] [,2]
#> [1,] 1.21377633 0.1515631
#> [2,] 0.07749958 0.4225508
#>
#> , , 3
#>
#> [,1] [,2]
#> [1,] 0.47340727 0.04288008
#> [2,] 0.01557136 0.03237842
#>
#> , , 4
#>
#> [,1] [,2]
#> [1,] 0.03137436 -0.07033934
#> [2,] 0.06512048 -0.04655784
#>
#> , , 5
#>
#> [,1] [,2]
#> [1,] -0.18629507 -0.1520553
#> [2,] -0.04585966 -0.1965071
#>
#> , , 6
#>
#> [,1] [,2]
#> [1,] -0.1454214 -0.07693178
#> [2,] -0.3255877 -0.11697233VARMAX models use exogenous coefficient matrices C and
input values z. They require fixed starting values
X0.