Python Statsmodels的向量自回归

Python Statsmodels的向量自回归,python,statistics,time-series,statsmodels,causality,Python,Statistics,Time Series,Statsmodels,Causality,我试图在python中实现多维Granger因果关系。就这点而言,我使用的是Statsmodels的向量自回归,但当我试图从中得到系数时,它会返回一个空矩阵。有人能告诉我到底出了什么问题吗 import numpy as np from statsmodels.tsa.vector_ar import var_model def multi_dim_granger(X_ts,Y_ts,order=5,test='F-test'): """Multivariate Granger cusa

我试图在python中实现多维Granger因果关系。就这点而言,我使用的是Statsmodels的向量自回归,但当我试图从中得到系数时,它会返回一个空矩阵。有人能告诉我到底出了什么问题吗

import numpy as np
from statsmodels.tsa.vector_ar import var_model
def multi_dim_granger(X_ts,Y_ts,order=5,test='F-test'):
    """Multivariate Granger cusality.
    input:
        X_ts: the first vector time series. 
              TxK matrix with T being the time instance and K is the dimension  
        Y_ts: the second vector time series. 
              TxK matrix with T being the time instance and K is the dimension  

        order: the maximum number of lags for fitting a VAR process
        test: the statistical test to check for the residual covariance matrix
    """
    ts=np.hstack((X,Y))
    print ts.shape
    VAR_model=var_model.VAR(ts)
    ts=VAR_model.fit(ic='aic',maxlags=order)
    return ts.coefs
X=np.random.randn(1000,2)
Y=(np.arange(4000)*np.random.randn(4000)).reshape((1000,4))
multi_dim_granger(X,Y)

您可以使用VARResults实例的
test\u因果关系
方法来测试格兰杰因果关系。请参阅文档和示例