首页 > 解决方案 > 执行 Johansen 整合检验时遇到错误

问题描述

我正在尝试对以下数据框执行协整测试:

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)

但是,我收到以下错误:

LinAlgError: Singular matrix

有人可以帮助我为什么会收到这样的错误吗?

标签: pythonstatistical-test

解决方案


我认为 coint_johansen 采用 NxN 矩阵。所以 col 9 和 on 将不起作用。我绝不是专家,所以我可能是错的


推荐阅读