0

I am trying perform cointegration test on the following dataframe:

col1    col2    col3    col4    col5    col6    col7    col8    col9    col10   col11
1736559 79  0   0   0   0   480 0.17    0.21    0.034   1
1930007 105 0   26  0   0   454 0.17    0.21    0.034   1
1733824 112 0   7   0.269231    0   515 0.17    0.21    0.034   1
2100953 186 0   74  10.57143    0   483 0.17    0.21    0.034   1
1677567 1978    0   1792    24.21622    0   501 0.17    0.21    0.034   1
2138232 12133   17  10155   5.666853    0.261538    365 0.19    0.19    0.035   1
1001923 74404   200 62271   6.132053    0.217865    195 0.19    0.19    0.035   1
648836  241260  1273    166856  2.679514    0.874914    34  0.19    0.19    0.035   0
555510  512308  5688    271048  1.624443    0.970814    12  0.19    0.19    0.035   0
433700  760900  14577   248592  0.917151    0.913861    5   0.21    0.18    0.035   0
412856  928041  24454   167141  0.672351    0.571836    6   0.21    0.18    0.035   0

from statsmodels.tsa.vector_ar.vecm import coint_johansen

def cointegration_test(df, alpha=0.05): 
"""Perform Johanson's Cointegration Test and Report Summary"""
    out = coint_johansen(df,-1,5)
   d = {'0.90':0, '0.95':1, '0.99':2}
   traces = out.lr1
  cvts = out.cvt[:, d[str(1-alpha)]]
  def adjust(val, length= 6): return str(val).ljust(length)

# Summary
print('Name   ::  Test Stat > C(95%)    =>   Signif  \n', '--'*20)
for col, trace, cvt in zip(df.columns, traces, cvts):
    print(adjust(col), ':: ', adjust(round(trace,2), 9), ">", adjust(cvt, 8), ' =>  ' , trace > cvt)

However, I am getting the following error :

LinAlgError: Singular matrix

Can somebody please help why am I getting such error ?

user6016731
  • 382
  • 5
  • 18

2 Answers2

0

I think that the coint_johansen takes a NxN matrix. So col 9 and on would not work. By no means am I an expert so I could be wrong

EscapeThat
  • 33
  • 2
0

I had the same error while using coint_johansen, the culprit was that there are columns in my dataframe which are perfectly linearly correlated. So when calculating covariance matrix, it is singular.

panc
  • 817
  • 2
  • 14
  • 30