Skip to content

DPredict · Guide test 214

Granger causality test

Tests whether one series’ lags improve prediction of another conditional on included lags; it does not establish causal effects.

Runs in CodeSplashPython example validatedR example validated

Do it in CodeSplash

In the app, set it up in Analyze with this method:

In Granger causality (predictive) test, choose Test = Granger F test.

Do it in CodeSplash Run this test on your own data, in Python or R.

Bench

Change the design, drag the data, move α. The statistic, its reference distribution and the verdict follow.

Bench · Granger causality test

100
0.30
0.40
0.30
2
0.050

Your data

Simulated with known truth
—— y– – x

If H₀ were true

F = 5.63
  1. The reference: how F varies across samples when H₀ is true.
  2. Your statistic, from the data above.
  3. The p-value: the area at least as extreme as yours (p = .005).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

yt=a+∑j=1qbjyt−j+∑j=1qcjxt−j+et,H0:c1=⋯=cq=0y_t = a + \sum_{j=1}^{q}b_j y_{t-j} + \sum_{j=1}^{q}c_j x_{t-j} + e_t,\qquad H_0: c_1 = \dots = c_q = 0

With your numbers

F=5.63 on (2,93) df,q=2F = 5.63\ \text{on}\ (2, 93)\ df,\qquad q = 2
cjc_j
lagged effects of x
qq
lags of both series

The verdict

F(2, 93) = 5.63, p = .005

p ≤ α = .050: reject H₀

Predictive precedence, not causation: a common driver or a missing variable produces Granger causality too.

Statistic
5.630
p-value
0.0049
Granger causality test on two series of length 100: F(2, 93) = 5.63, p = .005. The p-value is below α = .050, so the data are hard to reconcile with H0.

Granger causality test on two series of length 100: F(2, 93) = 5.63, p = .005. The p-value is below α = .050, so the data are hard to reconcile with H₀.

Question and hypotheses

H0: past X adds no linear predictive information for Y given included past variables.

Assumptions

A stable correctly specified VAR/lag regression; stationarity or a justified cointegrated/augmented method; suitable innovation covariance.

Formula

yt=a+∑j=1pαjyt−j+∑j=1pβjxt−j+utH0:β1=⋯=βp=0\begin{gathered}y_t=a+\sum_{j=1}^{p}\alpha_jy_{t-j}+\sum_{j=1}^{p}\beta_jx_{t-j}+u_t\\[5pt] H_0:\beta_1=\cdots=\beta_p=0\end{gathered}

Parameters and notation

p lag order; additional controls can be included. Use a joint F/Wald restriction test.

Structure of the method

Build restricted and unrestricted lag-regression design matrices over identical timestamps, fit both, and jointly test coefficients on the proposed predictor’s lags. The computational object is a linear predictive model followed by a restriction test. A multivariate conditional question requires all intended conditioning variables in both specifications.

Estimated and nuisance parameters

Estimate autoregressive coefficients, cross-series lag coefficients, intercept/trend/control effects, and innovation covariance. The tested lag coefficients are model parameters, while residual variance or robust covariance is nuisance estimation. Regression fit and test degrees of freedom must reflect the actual common effective sample.

Settings and design choices

Choose lag order, deterministic terms, controls, directional hypothesis, covariance estimator, and any stationarity/cointegration framework before inspecting significance. Higher lag orders represent longer effects but reduce degrees of freedom and increase collinearity. Information-criterion lag selection is model selection and should be disclosed.

Fitting and adaptation

Fit or refit the complete time-series model when adapting to a new frequency or regime; do not call this neural fine-tuning. Use a valid covariance or bootstrap for the innovation process. The cited grangertest convenience function is bivariate; use an appropriate VAR restriction interface for a genuinely multivariate conditioning set.

Sensitivity and robustness

Inspect residual serial correlation, unit roots, breaks, temporal aggregation, and alignment of publication dates. An apparently leading series can exploit future revisions or common drivers. A nonsignificant test may reflect inadequate lags or low power, and significance establishes conditional predictive content rather than an intervention effect.

How to use and calibrate

Fit restricted and unrestricted models to the same effective sample; use a valid covariance/reference for the series.

Example application

Assess whether one series improves forecasts of another.

Interpretation and pitfalls

Watch out

Predictive precedence is not causal identification; omitted common causes and sampling frequency can change results.

What changed in edition 2

  • New sections: structure of the method, estimated and nuisance parameters, settings and design choices, fitting and adaptation, sensitivity and robustness.

Python and R

Tests whether lagged x improves prediction of y conditional on lagged y. It is predictive causality, not intervention causality; stationarity/model adequacy matter.

Python · native

Validated — Executed successfully in the validation environment · needs numpy, scipy, statsmodels

import numpy as np
from scipy import stats
rng = np.random.default_rng(2026)
from statsmodels.tsa.stattools import grangercausalitytests
x=np.zeros(150)
for t in range(1,150):x[t]=.4*x[t-1]+rng.normal()
y=.4*np.r_[0,x[:-1]]+rng.normal(size=150)
print(grangercausalitytests(np.column_stack([y,x]),maxlag=[2]))
Output
{np.int64(2): ({'ssr_ftest': (np.float64(15.219520274972776), np.float64(1.0174803208092624e-06), np.float64(143.0), np.int64(2)), 'ssr_chi2test': (np.float64(31.503342667076517), np.float64(1.4425672192098987e-07), np.int64(2)), 'lrtest': (np.float64(28.56127030154704), np.float64(6.280568489474834e-07), np.int64(2)), 'params_ftest': (np.float64(15.219520274972787), np.float64(1.0174803208092517e-06), np.float64(143.0), 2.0)}, [<statsmodels.regression.linear_model.RegressionResultsWrapper object at 0x7f9df27cc770>, <statsmodels.regression.linear_model.RegressionResultsWrapper object at 0x7f9df4db1df0>, array([[0., 0., 1., 0., 0.],
       [0., 0., 0., 1., 0.]])])}
R

Validated — Executed successfully in the validation environment · needs lmtest

set.seed(2026)
x<-as.numeric(arima.sim(list(ar=.4),n=150));y<-c(0,head(x,-1))*.4+rnorm(150);print(lmtest::grangertest(y~x,order=2))
Output
Granger causality test

Model 1: y ~ Lags(y, 1:2) + Lags(x, 1:2)
Model 2: y ~ Lags(y, 1:2)
  Res.Df Df      F    Pr(>F)    
1    143                        
2    145 -2 12.659 8.671e-06 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Sources

Statistics guide v4 (historical):
Python: Executed successfully in the validation environment · R: Executed successfully in the validation environment
Reference's record:
Edition 2 review: Python: skip · R: not executed (Rscript unavailable); why not run: Python: Unavailable local dependencies: statsmodels. Python: Not run in the reference's review: Unavailable local dependencies: statsmodels. No installation attempted. R: Reviewed but not run: R wasn't available to the reference's authors.

From the CodeSplash statistics guide (v4), entry 214, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT214.