statsmodels.tsa.stattools.grangercausalitytests

statsmodels.tsa.stattools.grangercausalitytests(x, maxlag, addconst=True, verbose=None)[source]

Four tests for granger non causality of 2 time series.

All four tests give similar results. params_ftest and ssr_ftest are equivalent based on F test which is identical to lmtest:grangertest in R.

Parameters:
xarray_like

The data for testing whether the time series in the second column Granger causes the time series in the first column. Missing values are not supported.

maxlag{int, Iterable[int]}

If an integer, computes the test for all lags up to maxlag. If an iterable, computes the tests only for the lags in maxlag.

addconstbool

Include a constant in the model.

verbosebool

Print results. Deprecated

Returns:
dict

All test results, dictionary keys are the number of lags. For each lag the values are a tuple, with the first element a dictionary with test statistic, pvalues, degrees of freedom, the second element are the OLS estimation results for the restricted model, the unrestricted model and the restriction (contrast) matrix for the parameter f_test.

Notes

TODO: convert to class and attach results properly

The Null hypothesis for grangercausalitytests is that the time series in the second column, x2, does NOT Granger cause the time series in the first column, x1. Grange causality means that past values of x2 have a statistically significant effect on the current value of x1, taking past values of x1 into account as regressors. We reject the null hypothesis that x2 does not Granger cause x1 if the pvalues are below a desired size of the test.

The null hypothesis for all four test is that the coefficients corresponding to past values of the second time series are zero.

params_ftest, ssr_ftest are based on F distribution

ssr_chi2test, lrtest are based on chi-square distribution

References

[2]

Greene: Econometric Analysis

Examples

>>> import statsmodels.api as sm
>>> from statsmodels.tsa.stattools import grangercausalitytests
>>> import numpy as np
>>> data = sm.datasets.macrodata.load_pandas()
>>> data = data.data[["realgdp", "realcons"]].pct_change().dropna()

All lags up to 4

>>> gc_res = grangercausalitytests(data, 4)

Only lag 4

>>> gc_res = grangercausalitytests(data, [4])

Last update: Dec 16, 2024