Estimates a (possibly high-dimensional) VAR model using penalized least squares with an elastic net penalty and cross validation. This function is adapted from the sparsevar package (https://github.com/svazzole/sparsevar/tree/master), which is distributed under the GNU General Public License v2. The code has been modified to specifically implement the elastic net penalty (penalty = "ENET") and cross validation (method = "cv").
fitVAR(data, p = 1, ...)
A list with the following components:
A vector of means for each variable.
A list (of length p
) of the estimated coefficient matrices for the VAR process.
(Optional) The complete results of the penalized least squares estimation.
The chosen lambda value (by cross validation).
The minimum mean squared error from cross validation.
The standard deviation of the mean squared error.
Elapsed time for the estimation.
The (possibly transformed) input time series.
The residuals of the VAR model.
The estimated variance/covariance matrix of the residuals.
A numeric matrix or data frame with time series data (observations in rows, variables in columns).
Integer. The order of the VAR model.
Additional options for estimation. Global options include:
threshold
: Logical. If TRUE
, all entries smaller than the oracle
threshold are set to zero.
scale
: Logical. Whether to scale the data (default is FALSE
).
nfolds
: Integer. The number of folds used for cross validation (default is 10).
parallel
: Logical. If TRUE
, use multicore backend (default is FALSE
).
ncores
: Integer. If parallel = TRUE
, specify the number of cores to use.
alpha
: Numeric. The elastic net mixing parameter (default is 1, i.e. LASSO).
type.measure
: Character. The error measure for CV (e.g., "mse"
or "mae"
).
nlambda
: Integer. The number of lambda values to use in cross validation (default is 100).
leaveOut
: Integer. In time slice validation, leave out the last observations (default is 15).
horizon
: Integer. The forecast horizon to use for estimating error (default is 1).
lambda
: Either a numeric vector of lambda values or a string indicating which
lambda to use (default is "lambda.min"
).
return_fit
: Logical. If TRUE
, return the complete fit object.
The original source code is adapted from the sparsevar package, which is distributed under the GNU General Public License v2.