【问题标题】:Vector Autoregression with Python Statsmodels使用 Python Statsmodels 进行向量自回归
【发布时间】:2014-12-22 12:41:55
【问题描述】:

我正在尝试在 python 中实现多维格兰杰因果关系。就此而言,我正在使用来自 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)

【问题讨论】:

    标签: python statistics time-series statsmodels causality


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2016-09-07
      • 2016-08-28
      • 1970-01-01
      • 2016-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-31
      • 2017-08-17
      相关资源
      最近更新 更多