varmapack simulates and analyzes Gaussian VAR, VMA, VARMA, and VARMAX
time-series models. Simulated stationary series have the correct
distribution from the first returned term, without discarding a burn-in
segment. The package also provides model testcases, theoretical and
sample autocovariances, covariance-to-correlation conversion,
innovation-covariance recovery, spectral radii, and impulse response
functions.
The Getting Started with Varmapack vignette shows model construction, simulation, testcases, and analysis. The Mathematical Description of Varmapack vignette defines the supported models and describes the simulation method.
After installing the CRAN release, open the vignettes with
vignette("getting-started", package = "varmapack") and
vignette("mathematical-description", package = "varmapack"). The
installed reference documentation is available through
help(package = "varmapack"). For information about the underlying C
library, see the C
README.
The package will be installable from CRAN when released:
install.packages("varmapack")
For the development version, install the companion randompack package
first:
remotes::install_github("jonasson2/randompack", subdir = "r-package")
remotes::install_github("jonasson2/varmapack", subdir = "r-package")
model <- varmapack_testcase("smallARMA1")
gamma <- model$acvf(maxlag = 2)
corr <- varmapack_cov2corr(gamma)
Sig <- varmapack_cov2sig(gamma[, , 1], A = model$A, B = model$B)
varmapack_cov2corr() converts theoretical or sample autocovariances to
correlations by dividing each entry by the product of the corresponding
lag-zero marginal standard deviations. The returned array has the same
shape as the input. Lag-zero diagonal entries are exactly one. Other
entries are not clipped to [-1,1], so correlations obtained from
lag-corrected sample autocovariances may lie outside that interval.
varmapack_cov2sig(cov, A = NULL, B = NULL) recovers innovation
covariance from a specified lag-zero model covariance and fixed AR and
MA coefficients. cov is a single r by r matrix; only its lower
triangle is used. The returned matrix is symmetric, and inputs are
unchanged. The AR model must be stationary, and both covariances must be
positive semidefinite; singular covariances are allowed. Incompatible
targets and unreliable inverse problems raise errors.
rng <- randompack::randompack_rng()
rng$seed(123)
t <- varmapack_gamma_times(100, shape = 16, mean_gap = 1, rng = rng)
model <- varmapack_ou_model(c(1, 2), matrix(c(1, .5, .5, 1), 2))
X <- model$sim(t, nrep = 10, rng = rng) # 2 by 100 by 10
The OU model simulates exact stationary Gaussian paths at supplied
times, without burn-in. cov is the stationary covariance, not
innovation covariance; it and the driving covariance must be positive
semidefinite. For diagonal drift, tau gives the persistence times. For
a full drift matrix, use varmapack_ou_model(cov = cov, drift = K),
with drift -K %*% (X - mu). The autoregressive coefficient matrix over
a gap d is the matrix exponential of -K*d. Gamma gaps have CV
1/sqrt(shape), without normalization of the realized mean;
shape = Inf gives equal spacing.
varmapack_slepian_model(theta = matrix(.5), cov = matrix(1.25)) uses
the same sim interface for a Slepian-based model, which reduces to
MA(1) at unit spacing. Both models have an acvf method for fractional
lags; the OU model also has a specrad method for the autoregressive
matrix at a given time gap.
An additional European stock-index
example
fits a VAR(1) to the built-in EuStockMarkets log returns and generates
exact stationary simulations from the fitted model.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.