fitVAR: Fit VAR Model with Elastic Net via Cross Validation

View source: R/main_function.R

fitVARR Documentation

Fit VAR Model with Elastic Net via Cross Validation

Description

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").

Usage

fitVAR(data, p = 1, ...)

Arguments

data

A numeric matrix or data frame with time series data (observations in rows, variables in columns).

p

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.

Value

A list with the following components:

mu

A vector of means for each variable.

A

A list (of length p) of the estimated coefficient matrices for the VAR process.

fit

(Optional) The complete results of the penalized least squares estimation.

lambda

The chosen lambda value (by cross validation).

mse

The minimum mean squared error from cross validation.

mse_sd

The standard deviation of the mean squared error.

time

Elapsed time for the estimation.

series

The (possibly transformed) input time series.

residuals

The residuals of the VAR model.

sigma

The estimated variance/covariance matrix of the residuals.

References

The original source code is adapted from the sparsevar package, which is distributed under the GNU General Public License v2.


VARcpDetectOnline documentation built on April 12, 2025, 1:44 a.m.