pandas 熊猫格兰杰因果关系
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35728204/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Pandas Granger Causality
提问by agg212
I would like to perform a Granger Causality test on time series data using Python Pandas and I have two questions.
我想使用 Python Pandas 对时间序列数据执行格兰杰因果关系测试,我有两个问题。
(1) I have tried using the pandas.stats.var
package, but that seems to be deprecated. Are there any other recommended options?
(1) 我曾尝试使用该pandas.stats.var
软件包,但似乎已弃用。有没有其他推荐的选择?
(2) I'm having difficulty interpreting the output of the VAR.granger_causality()
function in the pandas.stats.var
package. The only reference I could find is a comment in the source code that says:
(2) 我很难解释包中VAR.granger_causality()
函数的输出pandas.stats.var
。我能找到的唯一参考是源代码中的一条评论:
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.
For example, the output of a trial run is shown below:
例如,试运行的输出如下所示:
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
I understand that each cell in the p-value table corresponds to a cell in the f-stat table, but I do not understand what the cells in the f-stat table refer to. For example, what does the value 0.52 in column C, row A mean?
我知道p值表中的每个单元格对应f-stat表中的一个单元格,但我不明白f-stat表中的单元格指的是什么。例如,C 列 A 行中的值 0.52 是什么意思?
回答by Niccola Tartaglia
Remember that Granger causality in its simplest form consists of an F-Test for the R2 of the two regressions: y=const+y[-1]+e vs. y=const+y[-1]+x[-1]+e
请记住,最简单形式的格兰杰因果关系由两个回归的 R2 的 F 检验组成:y=const+y[-1]+e 与 y=const+y[-1]+x[-1] +e
in order to see if the R2 from the second regression is higher. See also: http://www.statisticshowto.com/granger-causality/
为了查看第二次回归的 R2 是否更高。另见:http: //www.statisticshowto.com/granger-causality/