我对多变量时间序列非常陌生,我正在尝试制作一个具有108个预测变量和1个目标变量的VAR模型。在执行Johansen协整测试时,出现错误
LinAlgError: Matrix is not positive definite
我的代码是:
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)
cointegration_test(g)
其中[g是我的时间序列数据框,形状为((48行×109列))。行是日期时间索引,列是预测变量/变量。
几列中的数据,范围从0-1(例如:消费物价指数),而其他数列则在数百万的范围内(例如:人口,GDP)。
数据框中也包含负数的列(例如:就业变化)>
很少几列中也包含零
但是当我使用]使所有列stationary
g = g.diff().dropna().diff().dropna()
然后将差异数据帧传递给
cointegration_test
,其给定错误为:LinAlgError: Matrix is not positive definite
[据我所知,
Matrix is not positive definite
表示与之相关的特征值是非正值的。特征值仅适用于方阵,但鉴于我要提供的数据是非平方的。 。我该如何解决这个问题?我下一步应该去哪里?希望得到帮助。
谢谢
我对多变量时间序列非常陌生,我正在尝试制作一个具有108个预测变量和1个目标变量的VAR模型。在执行Johansen协整测试时,出现错误...
您已经提到,矩阵必须是nxn维。因此,您基本上需要的是: