VAR
VAR
Vector Autoregressive (VAR) model in matrix form.
A VAR of lag order p
is specified as:
where: - e_t
is a vector of deterministic components (constant, trends, etc). - C, B_i
are conformable coefficient matrices. - u_t
is vector white noise.
Compac```{.matlab}orm:
y_t' = z_t' B_+' + u_t'
with: - z_t = [e_t; y_{t-1}; ...; y_{t-p}]
- B_+ = [C, B_1, ..., B_p]
Stacking from ```{.matlab} p+1
to T
:
Y = X B_+' + U
Properties
B
(matrix): Coefficient matrix `[C B_1 … B_p].SigmaU
(matrix): Covariance matrix of the error term.p
(integer): Lag order of the VAR.trendExponents
(vector): Time trend exponents (e.g.,[0, 1]
implies constant and linear trend).inputData
(table or matrix): Original data used to estimate the VAR.Y
(matrix): Left-hand side outcomesy_t
, size(T-p) x k
.X
(matrix): Right-hand side regressorsz_t
, size(T-p) x (k*p + m)
wherem
is the number of deterministic domponents.U
(matrix): Residualsu_t
, size(T-p) x k
.Yhat
(matrix): Fitted valuesX * B_+'
, size(T-p) x k
.
makeCompanionMatrix_
Form the companion matrix of a VAR model.
C = makeCompanionMatrix_(B, p, m)
constructs the companion matrix for a VAR(p) model given its coefficient matrix B
.
Arguments
B
(matrix): Coefficient matrix[C B_1 ... B_p]
, whereC
are coefficients on deterministic components andB_i
are lag matrices.p
(integer): Lag order of the VAR.m
(integer): Number of deterministic components.
Returns
C
(matrix): Companion matrix of the VAR(p) system.
Notes
- The companion matrix has the structure:
\[ \begin{bmatrix} B_1 & B_2 & \cdots & B_p \\ I & 0 & \cdots & 0 \\ 0 & I & \cdots & 0 \\ \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \cdots & I \end{bmatrix} \]
fitted
Return the fitted values of the VAR model.
Yhat = fitted(obj)
returns the matrix of fitted values with size (T-p) x k
, where T
is the number of observations and k
is the number of variables.
Arguments
obj
(VAR): VAR model object.
Returns
Yhat
(matrix): Matrix of fitted values.
sic_
Compute Schwarz Information Criterion (SIC/BIC).
val = sic_(SigmaU, nCoeffs, T)
returns the SIC value given the residual covariance matrix, number of coefficients, and sample size.
Arguments
SigmaU
(matrix): Covariance matrix of the VAR residuals.nCoeffs
(integer): Total number of estimated coefficients.T
(integer): Number of effective observations.
Returns
val
(number): Computed SIC value.
IRF_
Compute impulse response functions for a VAR model.
irfs = IRF_(B, p, maxHorizon)
computes impulse response functions (IRFs) for horizons from 0 to maxHorizon
, given a coefficient matrix B
.
Arguments
B
(matrix): Stacked coefficient matrix[B_1 ... B_p]
, excluding deterministic components.p
(integer): Lag order of the VAR.maxHorizon
(integer): Maximum horizon for IRFs.
Returns
irfs
(3D array): Impulse responses of size(k x k x (maxHorizon+1))
, where:- First dimension: Endogenous variables (responses).
- Second dimension: Shocks (impulses).
- Third dimension: Horizon.
Notes
B
must not include coefficients on deterministic components (such as constants or trends).
transmission
Compute transmission effects in a VAR model.
effects = transmission(obj, shock, condition, order, maxHorizon, varargin)
computes the transmission effects of a shock
under a condition
, using the transmission matrix defined by order
, up to maxHorizon
.
Arguments
obj
(VAR): VAR model object.shock
(integer): Index of the shock variable.condition
(Q): Transmission condition object.order
(cell array of char): Variable transmission ordering.maxHorizon
(integer): Maximum horizon.varargin
: Name-value pairs for options:identificationMethod
(IdentificationMethod
): Required method to compute structural IRFs.
Returns
effects
(3D array): Transmission effects over horizons, where:- First dimension: Endogenous variables (responses).
- Second dimension: Shocks (of size one for the single selected shock).
- Third dimension: Horizon.
See also VAR.through
, VAR.notThrough
hqc_
Compute Hannan-Quinn Information Criterion (HQC).
val = hqc_(SigmaU, nCoeffs, T)
returns the HQC value given the residual covariance matrix, number of coefficients, and sample size.
Arguments
SigmaU
(matrix): Covariance matrix of the VAR residuals.nCoeffs
(integer): Total number of estimated coefficients.T
(integer): Number of effective observations.
Returns
val
(number): Computed HQC value.
spectralRadius_
Compute the spectral radius of a matrix.
rho = spectralRadius_(C)
returns the spectral radius of the companion matrix C
, defined as the maximum absolute value of its eigenvalues.
Arguments
C
(matrix): Companion matrix of the VAR model.
Returns
rho
(number): Spectral radius of the companion matrix.
See also makeCompanionMatrix_
sic
Compute Schwarz Information Criterion (SIC) for VAR model.
Arguments
obj
(VAR): VAR model object.
Returns
val
(number): SIC value.
See also aic
, hqc
, bic
, fit
aic_
Compute Akaike Information Criterion (AIC).
val = aic_(SigmaU, nCoeffs, T)
returns the AIC value given the residual covariance matrix, number of coefficients, and sample size.
Arguments
SigmaU
(matrix): Covariance matrix of the VAR residuals.nCoeffs
(integer): Total number of estimated coefficients.T
(integer): Number of effective observations.
Returns
val
(number): Computed AIC value.
makeCompanionMatrix
Form the companion matrix of the VAR model.
C = makeCompanionMatrix(obj)
constructs the companion matrix for the fitted VAR(p) model.
Arguments
obj
(VAR): VAR model object.
Returns
C
(matrix): Companion matrix of the VAR(p)
fit
Estimate the VAR model using ordinary least squares (OLS).
Arguments
obj
(VAR): VAR model object.
VAR
Construct a VAR(p) model.
obj = VAR(data, p, varargin)
creates a VAR with lag length p
based on the provided dataset.
Arguments
data
(table or matrix): Input dataset for the VAR model.p
(integer): Lag order of the VAR.varargin
: Name-value pairs for optional arguments:trendExponents
(vector): Exponents for deterministic trends. Defaults to[0]
(constant term).B
(matrix): Coefficient matrix. Default is empty (must be estimated).SigmaU
(matrix): Covariance matrix of residuals. Default is empty (must be estimated).
Returns
obj
(VAR): A VAR model.
See also fit
, simulate
bic
Compute Bayesian Information Criterion (BIC) for VAR model.
Arguments
obj
(VAR): VAR model object.
Returns
val
(number): BIC value.
See also aic
, hqc
, sic
, fit
ic_
Compute a generic information criterion value.
val = ic_(SigmaU, nCoeffs, ct)
returns the value of an information criterion based on the log determinant of the residual covariance matrix and a complexity penalty term.
Arguments
SigmaU
(matrix): Covariance matrix of the VAR residuals.nCoeffs
(integer): Total number of estimated coefficients.ct
(number): Complexity term adjusting for sample size.
Returns
val
(number): Computed information criterion value.
simulate
Simulate a VAR process given errors or time periods.
Y = simulate(errorsOrT, B, varargin)
simulates a VAR model using either provided error terms or by generating new errors from a Normal distribution.
Arguments
errorsOrT
(matrix or integer): Either a(k x T)
matrix of error terms or an integer specifying the number of periodsT
to simulate.B
(matrix): Coefficient matrix[C B_1 ... B_p]
wherep
is the lag order.varargin
: Name-value pairs for optional arguments:trendExponents
(vector): Exponents for deterministic trends. Default is[0]
(constant term).initial
(vector): Initial values for lags, size(p*k, 1)
. Default is zeros.SigmaU
(matrix): Covariance matrix for error generation if simulating errors. Default is identity matrix.
Returns
Y
(matrix): Simulated data matrix, size(T x k)
.
coeffs
Return the VAR coefficient matrix.
B = coeffs(obj, excludeDeterministic)
returns the VAR coefficient matrix [C, B_1, ..., B_p]
. If excludeDeterministic
is true, returns [B_1, ..., B_p]
instead, excluding deterministic components.
Arguments
obj
(VAR): VAR model object.excludeDeterministic
(logical, optional): If true, exclude coefficients on deterministic components. Defaults to false.
Returns
B
(matrix): VAR coefficient matrix.
residuals
Return the residuals of the VAR model.
U = residuals(obj)
returns the matrix of VAR residuals with size (T-p) x k
, where T
is the number of observations and k
is the number of variables.
Arguments
obj
(VAR): VAR model object.
Returns
U
(matrix): Matrix of residuals.
fitAndSelect
Estimate and select the best VAR model by IC.
[modelBest, icTable] = fitAndSelect(obj, icFunction)
fits the VAR model for different lag lengths and selects the one minimizing the information criterion. Maximum lag length is given by the lag length of the provided model.
Arguments
obj
(VAR): VAR model object.icFunction
(function handle, optional): Information criterion function to minimize. Defaults toaic
.
Returns
modelBest
(VAR): Best fitting model.icTable
(table): Table of lag lengths and IC values.
See also fit
, aic
, bic
, hqc
, sic
bic_
Compute Bayesian Information Criterion (SIC/BIC).
val = sic_(SigmaU, nCoeffs, T)
returns the BIC value given the residual covariance matrix, number of coefficients, and sample size.
Arguments
SigmaU
(matrix): Covariance matrix of the VAR residuals.nCoeffs
(integer): Total number of estimated coefficients.T
(integer): Number of effective observations.
Returns
val
(number): Computed BIC value.
Notes
- BIC is the same as SIC.
spectralRadius
Compute the spectral radius of the VAR model.
rho = spectralRadius(obj)
returns the spectral radius of the companion matrix associated with the fitted VAR model.
Arguments
obj
(VAR): VAR model object.
Returns
rho
(number): Spectral radius of the companion matrix.
aic
Compute Akaike Information Criterion (AIC) for VAR model.
Arguments
obj
(VAR): VAR model object.
Returns
val
(number): AIC value.
See also hqc
, sic
, bic
, fit
isStable
Check if the VAR model is stable.
flag = isStable(obj)
returns true if the spectral radius of the companion matrix is less than 1.
Arguments
obj
(VAR): VAR model object.
Returns
flag
(logical): True if the model is stable, false otherwise.
hqc
Compute Hannan-Quinn Criterion (HQC) for VAR model.
Arguments
obj
(VAR): VAR model object.
Returns
val
(number): HQC value.
See also aic
, sic
, bic
, fit
IRF
Compute impulse response functions for the VAR model.
irfObj = IRF(obj, maxHorizon, varargin)
computes IRFs up to horizon maxHorizon
. If an identificationMethod
is provided, structural IRFs are computed.
Arguments
obj
(VAR): VAR model object.maxHorizon
(integer): Maximum horizon for IRFs.varargin
: Name-value pairs for options:identificationMethod
(anIdentificationMethod
): Optional method to compute structural IRFs.
Returns
irfObj
(IRFContainer): Object containing computed IRFs.
Notes
- Without an identification method, reduced-form IRFs are computed.
- With an identification method, structural IRFs are computed.
See also IRF_
, IRFContainer
, fit
, IdentificationMethod
coeffsToCellArray_
Transform coefficient matrix into cell array of lag matrices.
BCellArray = coeffsToCellArray_(B)
converts the coefficient matrix [B_1 B_2 ... B_p]
into a cell array where each element corresponds to one lag matrix B_i
.
Arguments
B
(matrix): Stacked coefficient matrix excluding deterministic components (i.e., the matrix does not include the constant or trend coefficientsC
). Size is(k, k*p)
wherek
is the number of variables andp
is the lag order.
Returns
BCellArray
(cell array): A 1-by-p
cell array where each cell contains the(k x k)
lag coefficient matrix for one lag.
Notes
- Assumes that
B
has already been stripped of coefficients on deterministic components.