Pandas Granger Causality
Asked Answered
J

2

7

I would like to perform a Granger Causality test on time series data using Python Pandas and I have two questions.

(1) I have tried using the pandas.stats.var package, but that seems to be deprecated. Are there any other recommended options?

(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:

   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?

Jaqitsch answered 1/3, 2016 at 16:29 Comment(3)
Generally with pandas you'd want to check statsmodels and scipy (and sometimes numpy for simpler stats). Looks like statsmodels has something: statsmodels.sourceforge.net/0.6.0/generated/…Phraseologist
Updated link from @JohnE's answer: linkDerbent
You can look into this link for interpretation through P-value: machinelearningplus.com/time-series/time-series-analysis-pythonBarbusse
B
1
  • (Null hypothesis) H0: Xt does not granger causes Yt.
  • (Alternate hypothesis) H1: Xt granger causes Yt.

If P-value is less than 5% (or 0.05), then we can reject the Null hypothesis (H0), and can conclude that Xt granger causes Yt.

So where ever your P-value is less than 0.05, you can consider those features.

Barbusse answered 17/8, 2020 at 10:43 Comment(0)
D
0

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

in order to see if the R2 from the second regression is higher. See also: http://www.statisticshowto.com/granger-causality/

Dorena answered 22/6, 2017 at 15:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.