2016-03-01 77 views
2

我想对使用Python Pandas的时间序列数据进行Granger因果关系检验,我有两个问题。 (1)我试过使用pandas.stats.var软件包,但似乎不推荐使用。还有其他推荐选项吗? (2)我很难解释pandas.stats.var包中的VAR.granger_causality()函数的输出。我能找到的唯一的参考是在源代码中,说评论:Pandas Granger因果关系

Returns the f-stats and p-values from the Granger Causality Test. 
    If the data consists of columns x1, x2, x3, then we perform the 
    following regressions: 
    x1 ~ L(x2, x3) 
    x1 ~ L(x1, x3) 
    x1 ~ L(x1, x2) 
    The f-stats of these results are placed in the 'x1' column of the 
    returned DataFrame. We then repeat for x2, x3. 
    Returns 
    ------- 
    Dict, where 'f-stat' returns the DataFrame containing the f-stats, 
    and 'p-value' returns the DataFrame containing the corresponding 
    p-values of the f-stats. 

例如,如下所示试运行的输出:

p-value: 
      C   B   A 
A 0.472122 0.798261 0.412984 
B 0.327602 0.783978 0.494436 
C 0.071369 0.385844 0.688292 

f-stat: 
      C   B   A 
A 0.524075 0.065955 0.680298 
B 0.975334 0.075878 0.473030 
C 3.378231 0.763898 0.162619 

据我所知,在每个单元p值表对应于f-stat表中的单元格,但我不明白f-stat表中的单元格是指什么。例如,C列A行中的值0.52是什么意思?

+0

一般来说,熊猫你想检查statsmodels和scipy(有时为简单的统计数字numpy)。看起来像statsmodels有一些东西:http://statsmodels.sourceforge.net/0.6.0/generated/statsmodels.tsa.stattools.grangercausalitytests.html – JohnE

回答

0

请记住,在其最简单的形式Granger因果由F-检验的两个回归的R 2: Y = const的+ Y [-1] + E 与 Y = const的+ Y [-1 ] + x [-1] + e

为了查看来自第二次回归的R2是否更高。另见: http://www.statisticshowto.com/granger-causality/