Skip to contents

Estimates a Vector Autoregression model with optional exogenous variables using ordinary least squares (OLS). Optimised for maximum speed and memory efficiency via RcppArmadillo.

Usage

fVAR(y, p, c, exog = NULL)

Arguments

y

A numeric matrix of time series data with T rows (time periods) and N columns (endogenous variables).

p

An integer specifying the number of lags to include in the VAR.

c

An integer indicator for including a constant term (1 = include intercept, 0 = no intercept).

exog

An optional T x M matrix of exogenous variables. If provided, these variables enter contemporaneously (not lagged). Default is NULL.

Value

A list with elements: beta — coefficient matrix of dimensions (Np + c + M) x N, where the first row is the intercept (if c = 1), followed by N*p lag-coefficient rows, then M exogenous-coefficient rows; residuals — (T-p) x N matrix of OLS residuals; sigma_full — N x N residual covariance matrix normalised by (n_obs - 1); p — lag order (echoed from input); c — intercept indicator (echoed from input); n_exog — number of exogenous variables (0 if none provided).

Details

The model is $$Y_t = c + A_1 Y_{t-1} + \cdots + A_p Y_{t-p} + B X_t + e_t$$ where \(X_t\) are contemporaneous exogenous variables. Without exogenous variables the model reduces to a standard VAR(p). Estimation uses arma::solve for numerical stability.

Examples

if (FALSE) { # \dontrun{
# VAR(2) without exogenous variables
y      <- matrix(rnorm(200), ncol = 2)
result <- fVAR(y, p = 2, c = 1)

# VAR(2) with one exogenous variable
exog   <- matrix(rnorm(100), ncol = 1)
result <- fVAR(y, p = 2, c = 1, exog = exog)
} # }