# Test for Cointegration Using the Johansen Test

This example shows how to assess whether a multivariate time series has multiple cointegrating relations using the Johansen test.

Load `Data_Canada` into the MATLAB® Workspace. The data set contains the term structure of Canadian interest rates [141]. Extract the short-term, medium-term, and long-term interest rate series.

```load Data_Canada Y = Data(:,3:end); % Interest rate data```

To illustrate the input and output structure of `jcitest` when conducting multiple tests, test for the cointegration rank using the default H1 model and two different lag structures.

`[h,pValue,stat,cValue] = jcitest(Y,'Model','H1','Lags',1:2);`
```************************ Results Summary (Test 1) Data: Y Effective sample size: 39 Model: H1 Lags: 1 Statistic: trace Significance level: 0.05 r h stat cValue pValue eigVal ---------------------------------------- 0 1 35.3442 29.7976 0.0104 0.3979 1 1 15.5568 15.4948 0.0490 0.2757 2 0 2.9796 3.8415 0.0843 0.0736 ************************ Results Summary (Test 2) Data: Y Effective sample size: 38 Model: H1 Lags: 2 Statistic: trace Significance level: 0.05 r h stat cValue pValue eigVal ---------------------------------------- 0 0 25.8188 29.7976 0.1346 0.2839 1 0 13.1267 15.4948 0.1109 0.2377 2 0 2.8108 3.8415 0.0937 0.0713 ```

The default "trace" test assesses null hypotheses $H\left(r\right)$ of cointegration rank less than or equal to r against the alternative $H\left(n\right)$, where n is the dimension of the data. The summaries show that the first test rejects a cointegration rank of 0 (no cointegration) and just barely rejects a cointegration rank of 1, but fails to reject a cointegration rank of 2. The inference is that the data exhibit 1 or 2 cointegrating relationships. With an additional lag in the model, the second test fails to reject any of the cointegration ranks, providing little by way of inference. It is important to determine a reasonable lag length for the VEC model (as well as the general form of the model) before testing for cointegration.

Because the Johansen method, by its nature, tests multiple rank specifications for each specification of the remaining model parameters, `jcitest` returns the results in the form of tabular arrays, and indexes by null rank and test number.

Display the test results, `h`.

`h`
```h=2×3 table r0 r1 r2 _____ _____ _____ t1 true true false t2 false false false ```

Column headers indicate tests `r0`, `r1`, and `r2`, respectively, of $H\left(0\right)$, $H\left(1\right)$, and $H\left(2\right)$ against $H\left(3\right)$. Row headers `t1` and `t2` indicate the two separate tests (two separate lag structures) specified by the input parameters.

Access the result for the second test at null rank $r=0$ using tabular array indexing.

`h20 = h.r0(2)`
```h20 = logical 0 ```