# Original link:http://tecdat.cn/?p=22215

One of the preconditions of vector autoregressive model estimation is that the analyzed time series is stationary. However, economic theory holds that there is an equilibrium relationship between economic variables, which can make these variables differential and stable. This is the so-called cointegration relationship. Knowing that this relationship can improve the analysis results, we hope to have an econometric model to capture this relationship. The so-called vector error correction models (vecms) belong to this kind of models. The following introduces the basic concept of vecms and estimates this model in R.

## Models and data

The vector error correction model is very similar to the VAR model and can have the following forms.

Among them, Δ X is the first difference of each variable in vector x, PI is the coefficient matrix of cointegration relationship, Γ Is the coefficient matrix of the lag of the difference variable of X, D is the vector of the deterministic term, C is its corresponding coefficient matrix, and P is the lag order of the model in the form of var, ϵ Is the error term with zero mean, variance covariance matrix Σ。

From the above formula, the only difference from the VAR model is the error correction term Π Xt-1, which reflects how the variable growth rate in X will change if one of the variables deviates from its equilibrium value. coefficient matrix Π It can be written as matrix product Π=αβ′， So the error correction term becomes αβ′ xt-1。 Cointegration matrix β It contains the equilibrium relationship information between variables at all levels. β′ The vector described by xt-1 can be interpreted as the distance between the variable and the equilibrium value, α Is the so-called load matrix, which describes the rate at which the dependent variable converges to the equilibrium value.

To illustrate the r-vector error correction model estimation, we use data set E6 (2007), which contains seasonally adjusted time series of long-term interest rates and inflation rates from quarter 1972q2 to 1998 Q4.

`plot(data) # Drawing data`

## estimate

There are many ways to estimate the VEC model. The first method is the ordinary least square method, which can get accurate results, but can not estimate the cointegration relationship between variables. Estimation generalized least squares (egls) is an alternative method. However, the most popular vecms estimation method is Johansen’s (1995) maximum likelihood estimation.

However, before estimating the VEC model, the lag order P, the level R of the cointegration matrix and the deterministic term must be specified. An effective strategy to select the lag order is to estimate var horizontally and select the lag method to minimize the information criterion. Because the time series shows a strong seasonal law, we control it by specifying the seasonal parameter = 4, where 4 is the frequency of the data.

```
# estimate VAR
VAR(data,ic = "AIC", season = 4 ,....)
# AIC recommended lag order
var$p
```

```
## AIC(n)
## 4
```

According to AIC, a lag order of 4 can be used, which is the same as the value used in L ü tkepohl (2007). This means that the VaR corresponding to VEC model has three lag periods at the level. Since the ca.jo function requires the lag order of the VAR model, we set K = 4.

Adding deterministic terms to VECM is a clever problem. A common strategy is to add a linear trend to the error correction term and a constant to the non cointegration part of the equation. In this example, we follow the method of L ü tkepohl (2007) and add a constant term and seasonal pseudo variable to the non cointegration part of the equation.

Cajo function not only estimates VECM, but also calculates the test statistics of the equation. It also calculates the test statistics of different specificity of R. users can choose between two methods, namely trace test and eigenvalue test. In this example, the trace test is used, that is, type = “trace”.

```
# estimate
cajo(e6, ecdet = "none", type = "trace",...)
```

Trace test shows that r = 1, cointegration relationship β And load matrix α The first column of estimates is consistent with the results of ML estimates in L ü tkepohl (2007, Chapter 7).

```
# Beta
round([email protected], 2)
```

```
## R.l1 Dp.l1
## R.l1 1.00 1.0
## Dp.l1 -3.96 1.7
```

```
# Alpha
round([email protected], 2)
```

```
## R.l1 Dp.l1
## R.d -0.10 -0.04
## Dp.d 0.16 -0.02
```

However, the estimated coefficients of the non cointegration part of the model are consistent with the results of egls estimation.

`round(GAMMA, 2)`

```
## constant sd1 sd2 sd3 R.dl1 Dp.dl1 R.dl2 Dp.dl2 R.dl3 Dp.dl3
## R.d 0.01 0.01 0.00 0.00 0.29 -0.16 0.01 -0.19 0.25 -0.09
## Dp.d -0.01 0.02 0.02 0.03 0.08 -0.31 0.01 -0.37 0.04 -0.34
```

Due to the use of different reference dates, the results are different from those of L ü tkepohl (2007).

### Impulse response analysis

The impulse response function of VECM is usually obtained in its var form.

```
# Convert VEC to VaR, r = 1.
vec2var(vec, r = 1)
```

Then the impulse response function is calculated in the usual way.

```
# Get IRF
irf(impulse = "R", response = "Dp",...)
```

Note that an important difference between smooth VaR models is that the impulse response of cointegration VaR models does not have to be close to zero because the variables are unstable.

### reference

Lütkepohl, H. (2007). _New introduction to multiple time series analysis_ (2nd ed.). Berlin: Springer.

Most popular insights

1.Using LSTM and python for time series prediction in Python

2.Using long-term and short-term memory model LSTM to predict and analyze time series in Python

3.Time series (ARIMA, exponential smoothing) analysis using R language

4.R language multivariate copula GARCH model time series prediction

5.R language copulas and financial time series cases

6.Using R language random fluctuation model SV to deal with random fluctuations in time series

7.Tar threshold autoregressive model of R language time series

8.R language K-shape time series clustering method for stock price time series clustering