%% Test Cointegrating Vectors
% Tests on B answer questions about the space of cointegrating relations. The column vectors in B, estimated by jcitest, do not uniquely define the cointegrating relations. Rather, they estimate a space of cointegrating relations, given by the span of the vectors. Tests on B allow you to determine if other potentially interesting relations lie in that space. When constructing constraints, interpret the rows and columns of the n-by- r matrix B as follows:
% Row i of B contains the coefficients of variable y_{it} in each of the r cointegrating relations.
% Column j of B contains the coefficients of each of the n variables in cointegrating relation j.
% One application of jcontest is to pretest variables for their order of integration. At the start of any cointegration analysis, trending variables are typically tested for the presence of a unit root. These pretests can be carried out with combinations of standard unit root and stationarity tests such as adftest, pptest, kpsstest, or lmctest. Alternatively, jcontest lets you carry out stationarity testing within the Johansen framework. To do so, specify a cointegrating vector that is 1 at the variable of interest and 0 elsewhere, and then test to see if that vector is in the space of cointegrating relations. The following tests all of the variables in Y a single call:

load Data_Canada
Y = Data(:,3:end); % Interest rate data
[h0,pValue0] = jcontest(Y,1,'BVec',{[1 0 0]',[0 1 0]',[0 0 1]'})

% The second input argument specifies a cointegration rank of 1, and the third and fourth input arguments are a parameter/value pair specifying tests of specific vectors in the space of cointegrating relations. The results strongly reject the null of stationarity for each of the variables, returning very small p-values.
%
% Another common test of the space of cointegrating vectors is to see if certain combinations of variables suggested by economic theory are stationary. For example, it may be of interest to see if interest rates are cointegrated with various measures of inflation (and, via the Fisher equation, if real interest rates are stationary). In addition to the interest rates already examined, Data_Canada.mat contains two measures of inflation, based on the CPI and the GDP deflator, respectively. To demonstrate the test procedure (without any presumption of having identified an adequate model), we first run jcitest to determine the rank of B, then test the stationarity of a simple spread between the CPI inflation rate and the short-term interest rate:

y1 = Data(:,1); % CPI-based inflation rate
YI = [y1,Y];
 
% Test if inflation is cointegrated with interest rates:
[h,pValue] = jcitest(YI);
% Test if y1 - y2 is stationary:
[hB,pValueB] = jcontest(YI,1,'BCon',[1 -1 0 0]')

% The first test provides evidence of cointegration, and fails to reject a cointegration rank r = 1. The second test, assuming r = 1, rejects the hypothesized cointegrating relation. Of course, reliable economic inferences would need to include proper model selection, with corresponding settings for the 'model' and other default parameters.
% Copyright 2015 The MathWorks, Inc.