# var2vec

Convert VAR model to VEC model

## Description

If any of the time series in a vector autoregression (VAR) model are cointegrated, then the VAR model is nonstationary. You can determine the error-correction coefficient by converting the VAR model to a vector error-correction (VEC) model. The error-correction coefficient matrix determines, on average, how the time series react to deviations from their long-run averages. The rank of the error-correction coefficient determines how many cointegrating relations there exist in the model.

Because estimate is suitable for estimating VAR models in reduced form, you can convert an estimated VAR model to its VEC model equivalent using var2vec.

example

[VEC,C] = var2vec(VAR) returns the coefficient matrices (VEC) and the error-correction coefficient matrix (C) of the vector error-correction model equivalent to the vector autoregressive model with coefficient matrices (VAR). If the number of lags in the input vector autoregressive model is p, then the number of lags in the output vector error-correction model is q = p – 1.

## Examples

collapse all

Consider converting the following VAR(3) model to a VEC(2) model.

${y}_{t}=\left[\begin{array}{c}0.5\\ 1\\ -2\end{array}\right]+\left[\begin{array}{ccc}0.54& 0.86& -0.43\\ 1.83& 0.32& 0.34\\ -2.26& -1.31& 3.58\end{array}\right]{y}_{t-1}+\left[\begin{array}{ccc}0.14& -0.12& 0.05\\ 0.14& 0.07& 0.10\\ 0.07& 0.16& 0.07\end{array}\right]{y}_{t-3}+{\epsilon }_{t}.$

Specify the coefficient matrices (${A}_{1}$, ${A}_{2}$, and ${A}_{3}$) of the VAR(3) model terms ${y}_{t-1}$, ${y}_{t-2}$, and ${y}_{t-3}$.

A1 = [0.54  0.86 -0.43;
1.83  0.32  0.34;
-2.26 -1.31  3.58];
A2 = zeros(3);
A3 = [0.14 -0.12 0.05;
0.14  0.07 0.10;
0.07  0.16 0.07];

Pack the matrices into separate cells of a 3 dimensional cell vector. Put A1 into the first cell, A2 into the second cell, and A3 into the third cell.

VAR = {A1 A2 A3};

Compute the coefficient matrices of $\Delta {y}_{t-1}$ and $\Delta {y}_{t-2}$, and error-correction coefficient matrix of the equivalent VEC(2) model.

[VEC,C] = var2vec(VAR);
size(VEC)
ans = 1×2

1     2

The specification of a cell array of matrices for the input argument indicates that the VAR(3) model is a reduced-form model expressed as a difference equation. VAR{1} is the coefficient of ${y}_{t-1}$, and subsequent elements correspond to subsequent lags.

VEC is a 1-by-2 cell vector of 3-by-3 coefficient matrices for the VEC(2) equivalent of the VAR(3) model. Because the VAR(3) model is in reduced form, the equivalent VEC model is also. That is, VEC{1} is the coefficient of $\Delta {y}_{t-1}$, and subsequent elements correspond to subsequent lags. The orientation of VEC corresponds to the orientation of VAR.

Display the VEC(2) model coefficients.

B1 = VEC{1}
B1 = 3×3

-0.1400    0.1200   -0.0500
-0.1400   -0.0700   -0.1000
-0.0700   -0.1600   -0.0700

B2 = VEC{2}
B2 = 3×3

-0.1400    0.1200   -0.0500
-0.1400   -0.0700   -0.1000
-0.0700   -0.1600   -0.0700

C
C = 3×3

-0.3200    0.7400   -0.3800
1.9700   -0.6100    0.4400
-2.1900   -1.1500    2.6500

Since the constant offsets between the models are equivalent, the resulting VEC(2) model is

$\begin{array}{rcl}\Delta {y}_{t}& =& \left[\begin{array}{c}0.5\\ 1\\ -2\end{array}\right]+\left[\begin{array}{ccc}-0.14& 0.12& -0.05\\ -0.14& -0.07& -0.10\\ -0.07& -0.16& -0.07\end{array}\right]\Delta {y}_{t-1}+\left[\begin{array}{ccc}-0.14& 0.12& -0.05\\ -0.14& -0.07& -0.10\\ -0.07& -0.16& -0.07\end{array}\right]\Delta {y}_{t-2}\\ & +& \left[\begin{array}{ccc}-0.32& 0.74& -0.38\\ 1.97& -0.61& 0.44\\ -2.19& -1.15& 2.65\end{array}\right]{y}_{t-1}+{\epsilon }_{t}\end{array}.$

Consider converting the following structural VAR(2) model to a structural VEC(1) model.

$\left[\begin{array}{cc}0.54& -2.26\\ 1.83& 0.86\end{array}\right]{y}_{t}=\left[\begin{array}{cc}0.32& -0.43\\ -1.31& 0.34\end{array}\right]{y}_{t-1}+\left[\begin{array}{cc}0.07& 0.07\\ -0.01& -0.02\end{array}\right]{y}_{t-2}+{\epsilon }_{t}.$

Specify the autoregressive coefficient matrices ${A}_{0}$, ${A}_{1}$, and ${A}_{2}$.

A0 = [0.54 -2.26;
1.83  0.86];
A1 = [0.32 -0.43
-1.31  0.34];
A2 = [0.07  0.07
-0.01 -0.02];

Pack the matrices into separate cells of a 3 dimensional cell vector. Put A0 into the first cell, A1 into the second cell, and A2 into the third cell. Negate the coefficients corresponding to all nonzero lag terms.

VARCoeff = {A0; -A1; -A2};

Create a lag operator polynomial that encompasses the autoregressive terms in the VAR(2) model.

VAR = LagOp(VARCoeff)
VAR =
2-D Lag Operator Polynomial:
-----------------------------
Coefficients: [Lag-Indexed Cell Array with 3 Non-Zero Coefficients]
Lags: [0 1 2]
Degree: 2
Dimension: 2

VAR is a LagOp lag operator polynomial. VAR specifies the VAR(2) model in lag operator notation, as in this equation

$\left({A}_{0}-{A}_{1}L-{A}_{2}{L}^{2}\right){y}_{t}={\epsilon }_{t}.$

$L$ is the lag operator. If you expand the quantity and solve for ${y}_{t}$, then the result is the VAR(2) model in difference-equation notation.

Compute the coefficient matrices of $\Delta {y}_{t}$ and $\Delta {y}_{t}$, and the error-correction coefficient matrix of the equivalent VEC(1) model.

[VEC,C] = var2vec(VAR)
VEC =
2-D Lag Operator Polynomial:
-----------------------------
Coefficients: [Lag-Indexed Cell Array with 2 Non-Zero Coefficients]
Lags: [0 1]
Degree: 1
Dimension: 2
C = 2×2

-0.1500    1.9000
-3.1500   -0.5400

VAR.Coefficients{0} is ${A}_{0}$, the coefficient matrix of ${y}_{t}$. Subsequent elements in VAR.Coefficients correspond to subsequent lags in VAR.Lags.

VEC is the VEC(1) equivalent of the VAR(2) model. Because the VAR(2) model is structural, the equivalent VEC(1) model is as well. That is, VEC.Coefficients{0} is the coefficient of $\Delta {y}_{t}$, and subsequent elements correspond to subsequent lags in VEC.Lags.

Display the VEC model coefficients in difference-equation notation.

B0 = VEC.Coefficients{0}
B0 = 2×2

0.5400   -2.2600
1.8300    0.8600

B1 = -VEC.Coefficients{1}
B1 = 2×2

-0.0700   -0.0700
0.0100    0.0200

C
C = 2×2

-0.1500    1.9000
-3.1500   -0.5400

The resulting VEC(1) model is

$\left[\begin{array}{cc}0.54& -2.26\\ 1.83& 0.86\end{array}\right]\Delta {y}_{t}=\left[\begin{array}{cc}-0.07& -0.07\\ 0.01& 0.02\end{array}\right]\Delta {y}_{t-1}+\left[\begin{array}{cc}-0.15& 1.9\\ -3.15& -0.54\end{array}\right]{y}_{t-1}+{\epsilon }_{t}.$

Alternatively, reflect the lag operator polynomial VEC around lag 0 to obtain the difference-equation notation coefficients.

DiffEqnCoeffs = reflect(VEC);
B = toCellArray(DiffEqnCoeffs);
B{1} == B0
ans = 2x2 logical array

1   1
1   1

B{2} == B1
ans = 2x2 logical array

1   1
1   1

Both methods produce the same coefficients.

Approximate the coefficients of the VEC model that represents this stationary and invertible VARMA(8,4) model that is in lag operator form

$\begin{array}{l}\left\{\left[\begin{array}{ccc}1& 0.2& -0.1\\ 0.03& 1& -0.15\\ 0.9& -0.25& 1\end{array}\right]+\left[\begin{array}{ccc}0.5& -0.2& -0.1\\ -0.3& -0.1& 0.1\\ 0.4& -0.2& -0.05\end{array}\right]{L}^{4}+\left[\begin{array}{ccc}0.05& -0.02& -0.01\\ -0.1& -0.01& -0.001\\ 0.04& -0.02& -0.005\end{array}\right]{L}^{8}\right\}{y}_{t}=\\ \left\{\left[\begin{array}{ccc}1& 0& 0\\ 0& 1& 0\\ 0& 0& 1\end{array}\right]+\left[\begin{array}{ccc}-0.02& 0.03& 0.3\\ 0.003& 0.001& 0.01\\ 0.3& 0.01& 0.01\end{array}\right]{L}^{4}\right\}{\epsilon }_{t}\end{array}$

where ${y}_{t}={\left[{y}_{1t}\phantom{\rule{0.2777777777777778em}{0ex}}\phantom{\rule{0.2777777777777778em}{0ex}}\phantom{\rule{0.2777777777777778em}{0ex}}{y}_{2t}\phantom{\rule{0.2777777777777778em}{0ex}}\phantom{\rule{0.2777777777777778em}{0ex}}\phantom{\rule{0.2777777777777778em}{0ex}}{y}_{3t}\right]}^{\prime }$ and ${\epsilon }_{t}={\left[{\epsilon }_{1t}\phantom{\rule{0.2777777777777778em}{0ex}}\phantom{\rule{0.2777777777777778em}{0ex}}\phantom{\rule{0.2777777777777778em}{0ex}}{\epsilon }_{2t}\phantom{\rule{0.2777777777777778em}{0ex}}\phantom{\rule{0.2777777777777778em}{0ex}}\phantom{\rule{0.2777777777777778em}{0ex}}{\epsilon }_{3t}\right]}^{\prime }$.

Create a cell vector containing the VAR coefficient matrices. Start with the coefficient of ${y}_{t}$, and then enter the rest in order by lag. Construct a vector that indicates the degree of the lag term for the corresponding coefficients.

VAR0 = {[1 0.2 -0.1; 0.03 1 -0.15; 0.9 -0.25 1],...
[0.5 -0.2 -0.1; -0.3 -0.1 0.1; 0.4 -0.2 -0.05],...
[0.05 -0.02 -0.01; -0.1 -0.01 -0.001; 0.04 -0.02 -0.005]};
var0Lags = [0 4 8];

Create a cell vector containing the VMA coefficient matrices. Start with the coefficient of ${\epsilon }_{t}$, and then enter the rest in order by lag. Construct a vector that indicates the degree of the lag term for the corresponding coefficients.

VMA0 = {eye(3),...
[-0.02 0.03 0.3; 0.003 0.001 0.01; 0.3 0.01 0.01]};
vma0Lags = [0 4];

arma2ma requires LagOp lag operator polynomials for input arguments that comprise structural VAR or VMA models. Construct separate LagOp polynomials that describe the VAR(8) and VMA(4) components of the VARMA(8,4) model.

VARLag = LagOp(VAR0,'Lags',var0Lags);
VMALag = LagOp(VMA0,'Lags',vma0Lags);

VARLag and VMALag are LagOp lag operator polynomials that describe the VAR and VMA components of the VARMA model.

Convert the VARMA(8,4) model to a VAR(p) model by obtaining the coefficients of the truncated approximation of the infinite-lag polynomial. Set numLags to return at most 12 lagged terms.

numLags = 12;
VAR = arma2ar(VARLag,VMALag,numLags)
VAR =
3-D Lag Operator Polynomial:
-----------------------------
Coefficients: [Lag-Indexed Cell Array with 4 Non-Zero Coefficients]
Lags: [0 4 8 12]
Degree: 12
Dimension: 3

VAR is a LagOP lag operator polynomial. All coefficients except those corresponding to lags 0, 4, 8, and 12 are 3-by-3 matrices of zeros. The coefficients in VAR.Coefficients comprise a structural VAR(12) model approximation of the original VARMA(8,4) model.

Compute the coefficients of the VEC(11) model equivalent to the resulting VAR(12) model.

[VEC,C] = var2vec(VAR)
VEC =
3-D Lag Operator Polynomial:
-----------------------------
Coefficients: [Lag-Indexed Cell Array with 12 Non-Zero Coefficients]
Lags: [0 1 2 3 4 5 6 7 8 9 10 11]
Degree: 11
Dimension: 3
C = 3×3

-1.2998   -0.1019    0.5440
0.3831   -0.8937    0.0603
-0.9484    0.5068   -1.0876

VEC is a LagOp lag operator polynomial containing the coefficient matrices of the resulting VEC(11) model in VEC.Coefficients. VEC.Coefficients{0} is the coefficient of $\Delta {y}_{t}$, Vec{1} is the coefficient of $\Delta {y}_{t-1}$, and so on.

Display the nonzero coefficients of the resulting VEC model.

lag2Idx = VEC.Lags + 1; % Lags start at 0.  Add 1 to convert to indices.
VecCoeff = toCellArray(VEC);

for j = 1:numel(lag2Idx)
fprintf('___________Lag %d__________\n',lag2Idx(j) - 1)
fprintf('%8.3f %8.3f %8.3f \n',VecCoeff{lag2Idx(j)})
fprintf    ('__________________________\n')
end
___________Lag 0__________
1.000    0.030    0.900
0.200    1.000   -0.250
-0.100   -0.150    1.000
__________________________
___________Lag 1__________
-0.300    0.413   -0.048
0.098    0.106    0.257
0.444   -0.090   -0.088
__________________________
___________Lag 2__________
-0.300    0.413   -0.048
0.098    0.106    0.257
0.444   -0.090   -0.088
__________________________
___________Lag 3__________
-0.300    0.413   -0.048
0.098    0.106    0.257
0.444   -0.090   -0.088
__________________________
___________Lag 4__________
-0.051    0.101    0.042
-0.053    0.007   -0.011
0.046    0.001   -0.116
__________________________
___________Lag 5__________
-0.051    0.101    0.042
-0.053    0.007   -0.011
0.046    0.001   -0.116
__________________________
___________Lag 6__________
-0.051    0.101    0.042
-0.053    0.007   -0.011
0.046    0.001   -0.116
__________________________
___________Lag 7__________
-0.051    0.101    0.042
-0.053    0.007   -0.011
0.046    0.001   -0.116
__________________________
___________Lag 8__________
-0.014   -0.000    0.010
0.007    0.000    0.018
0.034    0.001   -0.002
__________________________
___________Lag 9__________
-0.014   -0.000    0.010
0.007    0.000    0.018
0.034    0.001   -0.002
__________________________
___________Lag 10__________
-0.014   -0.000    0.010
0.007    0.000    0.018
0.034    0.001   -0.002
__________________________
___________Lag 11__________
-0.014   -0.000    0.010
0.007    0.000    0.018
0.034    0.001   -0.002
__________________________

## Input Arguments

collapse all

VAR(p) model coefficients, specified as a numeric vector, a cell vector of n-by-n numeric matrices, or a LagOp lag operator polynomial object.

• For a numeric vector specification:

• The VAR(p) is a univariate time series.

• VAR must be a length p numeric vector.

• VAR(j) contains the scalar Aj, the coefficient of the lagged response ytj.

• The coefficient of yt (A0) is 1.

• For a cell vector specification:

• VAR must have length p, and each cell contains an n-by-n numeric matrix (n > 1).

• VAR{j} must contain Aj, the coefficient matrix of the lag term ytj.

• var2vec assumes that the coefficient of yt (A0) is the n-by-n identity.

• For a LagOp lag operator polynomial specification:

• VAR.Degree must be p.

• VAR.Coefficients{0} is A0, the coefficient of yt. All other elements correspond to the coefficients of the subsequent lag terms. For example, VAR.Coefficients{j} is the coefficient matrix of ytj. VAR.Lags stores all nonzero lags.

• To construct a model in reduced form, set VAR.Coefficients{0} to eye(VAR.Dimension).

For example, consider converting

$\left[\begin{array}{cc}1& 0\\ 0& 1\end{array}\right]{y}_{t}=\left[\begin{array}{cc}0.1& 0.2\\ 1& 0.1\end{array}\right]{y}_{t-1}+\left[\begin{array}{cc}-0.1& 0.01\\ 0.2& -0.3\end{array}\right]{y}_{t-2}+{\epsilon }_{t}$

to a VEC(1) model. The model is in difference-equation notation. You can convert the model by entering

VEC = var2vec({[0.1 0.2; 1 0.1], [-0.1 0.01; 0.2 -0.3]});
The VAR(2) model in lag operator notation is

$\left(\left[\begin{array}{cc}1& 0\\ 0& 1\end{array}\right]-\left[\begin{array}{cc}0.1& 0.2\\ 1& 0.1\end{array}\right]-\left[\begin{array}{cc}-0.1& 0.01\\ 0.2& -0.3\end{array}\right]L\right){y}_{t}={\epsilon }_{t}.$

The coefficient matrices of the lagged responses appear negated compared to the corresponding coefficients in difference-equation notation. To obtain the same result using LagOp lag operator polynomials, enter

VAR = LagOp({eye(2), -[0.1 0.2; 1 0.1], -[-0.1 0.01; 0.2 -0.3]});
VEC = var2vec(VAR);

## Output Arguments

collapse all

VEC(q) model coefficients of differenced responses, returned as a numeric vector, a cell vector of n-by-n numeric matrices, or a LagOp lag operator polynomial object. n is the number of time series in the VAR(p) model.

VAR and VEC share the same data type and orientation.

var2vec converts VAR(p) models to VEC(p – 1) models. That is:

• If VAR is a cell or numeric vector, then numel(VEC) is numel(VAR) - 1.

• If VAR is a LagOp lag operator polynomial, then VEC.Degree is VAR.Degree - 1.

Error-correction coefficient, returned as an n-by-n numeric matrix. n is the number of time series in the VAR model.

collapse all

### Difference-Equation Notation

A VAR(p) or VEC(q) model written in difference-equation notation isolates the present value of the response vector and its structural coefficient matrix on the left side of the equation. The right side of the equation contains the sum of the lagged responses, their coefficient matrices, the present innovation vector, and, for VEC models, the error-correction term.

That is, a VAR(p) model written in difference-equation notation is

${A}_{0}{y}_{t}=a+{A}_{1}{y}_{t-1}+{A}_{2}{y}_{t-2}+...+{A}_{p}{y}_{t-p}+{\epsilon }_{t}.$

A VEC(q) model written in difference equation notation is

${B}_{0}\Delta {y}_{t}=b+{B}_{1}\Delta {y}_{t-1}+{B}_{2}\Delta {y}_{t-2}+...+{B}_{q}\Delta {y}_{t-q}+C{y}_{t-1}+{\epsilon }_{t}.$

For the variable and parameter definitions, see VAR(p) Model and VEC(q) Model.

### Lag Operator Notation

A VAR(p) or VEC(q) model written in lag-operator notation positions all response terms to the left side of the equation. The right side of the equation contains the model constant offset vector, the present innovation, and, for VEC models, the error-correction term.

That is, a VAR(p) model written in lag-operator notation is

$A\left(L\right){y}_{t}=a+{\epsilon }_{t}$

where $A\left(L\right)={A}_{0}-{A}_{1}L-{A}_{2}{L}^{2}-...-{A}_{p}{L}^{p}$ and ${L}^{j}{y}_{t}={y}_{t-j}$.

A VEC(q) model written in difference equation notation is

$B\left(L\right)\Delta {y}_{t}=b+C{y}_{t-1}+{\epsilon }_{t}$

where $B\left(L\right)={B}_{0}-{B}_{1}L-{B}_{2}{L}^{2}-...-{B}_{q}{L}^{q}$.

For the variable and parameter definitions, see VAR(p) Model and VEC(q) Model.

When comparing lag operator notation to difference-equation notation, the signs of the lag terms are opposites. For more details, see Lag Operator Notation.

### VAR(p) Model

A VAR(p) model is a multivariate, autoregressive time series model that has this general form:

${A}_{0}{y}_{t}=a+{A}_{1}{y}_{t-1}+{A}_{2}{y}_{t-2}+...+{A}_{p}{y}_{t-p}+{\epsilon }_{t}.$

• yt is an n-dimensional time series.

• A0 is the n-by-n invertible structural coefficient matrix. For models in reduced form, A0 = In, which is the n-dimensional identity matrix.

• a is an n-dimensional vector of constant offsets.

• Aj is the n-by-n coefficient matrix of yt–j, j = 1,...,p.

• εt is an n-dimensional innovations series. The innovations are serially uncorrelated, and have a multivariate normal distribution with mean 0 and n-by-n covariance matrix Σ.

### VEC(q) Model

A VEC(q) model is a multivariate, autoregressive time series model that has this general form:

${B}_{0}\Delta {y}_{t}=b+{B}_{1}\Delta {y}_{t-1}+{B}_{2}\Delta {y}_{t-2}+...+{B}_{q}\Delta {y}_{t-q}+C{y}_{t-1}+{\epsilon }_{t}.$

• yt is an n-dimensional time series.

• Δ is the first difference operator, that is, Δyt = ytyt–1.

• B0 is the n-by-n invertible structural coefficient matrix. For models in reduced form, B0 = In, which is the n-dimensional identity matrix.

• b is an n-dimensional vector of constant offsets.

• Bj is the n-by-n coefficient matrix of Δyt–j, j = 1,...,q.

• εt is an n-dimensional innovations series. The innovations are serially uncorrelated, and have a multivariate normal distribution with mean 0 and n-by-n covariance matrix Σ.

• C is the n-by-n error-correction or impact coefficient matrix.

## Tips

• To accommodate structural VAR models, specify the input argument VAR as a LagOp lag operator polynomial.

• To access the cell vector of the lag operator polynomial coefficients of the output argument VEC, enter toCellArray(VEC).

• To convert the model coefficients of the output argument from lag operator notation to the model coefficients in difference-equation notation, enter

VECDEN = toCellArray(reflect(VEC));
VECDEN is a cell vector containing p coefficients corresponding to the differenced response terms in VEC.Lags in difference-equation notation. The first element is the coefficient of Δyt, the second element is the coefficient of Δyt–1, and so on.

• Consider converting a VAR(p) model to a VEC(q) model. If the error-correction coefficient matrix (C) has:

• Rank zero, then the converted VEC model is a stable VAR(p – 1) model in terms of Δyt.

• Full rank, then the VAR(p) model is stable (i.e., has no unit roots) [2].

• Rank r, such that 0 < r < n, then the stable VEC model has r cointegrating relations.

• The constant offset of the converted VEC model is the same as the constant offset of the VAR model.

## Algorithms

• var2vec does not impose stability requirements on the coefficients. To check for stability, use isStable.

isStable requires a LagOp lag operator polynomial as an input argument. For example, to check whether VAR, the cell array of n-by-n numeric matrices, composes a stable time series, enter

varLagOp = LagOp([eye(n) VAR]);
isStable(varLagOp)

A 0 indicates that the polynomial is not stable.

## References

[1] Hamilton, J. D. Time Series Analysis. Princeton, NJ: Princeton University Press, 1994.

[2] Lutkepohl, H. "New Introduction to Multiple Time Series Analysis." Springer-Verlag, 2007.

## Version History

Introduced in R2015b