DPredict · Guide test 203
Engle–Granger cointegration test
Tests whether residuals from a long run levels relationship are stationary, with cointegration specific critical values.
Do it in CodeSplash
In the app, set it up in Analyze with this method:
- Cointegration tests — Do several wandering (unit-root) series move together in the long run, so that some combination of them is stationary?
In Cointegration tests, choose Test = Engle–Granger (ADF on residuals).
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 · Engle–Granger cointegration test
1: the gap is a random walk too (no cointegration).
Extra lags of Δy that soak up short-run dynamics.
Your data
Simulated with known truthCointegrated series wander together: the gap from their long-run line keeps returning to zero.
If H₀ were true
- The reference: how τ varies across samples when H₀ is true, Engle–Granger τ, two series (MacKinnon) (MacKinnon (1994) response surface (asymptotic)).
- Your statistic, from the data above.
- The p-value: the area at least as extreme as yours (p = .003).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- residuals of the cointegrating regression
- on Engle–Granger (MacKinnon, two series) critical values, further left than Dickey–Fuller's
The verdict
τ = −4.26, p = .003
p ≤ α = .050: reject H₀
The residuals were fitted to be small, so the ordinary DF table over-rejects. Swapping y and x can change the verdict in small samples.
- Statistic
- −4.258
- p-value
- 0.0030
Engle–Granger cointegration test on two series of length 80: τ = −4.26, p = .003. The p-value is below α = .050, so the data are hard to reconcile with H₀.
Question and hypotheses
H0: I(1) variables are not cointegrated; H1: a stationary linear combination exists.
Assumptions
Variables are individually integrated of compatible order; correct deterministic terms and adequate dynamics; stable long-run relation.
Formula
Parameters and notation
First estimate the long-run regression; test its generated residuals for a unit root.
Structure of the method
Estimate a long-run levels regression, extract its generated residuals, and test those residuals for a unit root using a cointegration-specific reference distribution. The first-stage fit changes the second-stage null law. Cointegration requires a stationary linear combination, not necessarily white-noise residuals or an absence of short-run dynamics.
Estimated and nuisance parameters
Cointegrating coefficients, deterministic terms, and residual ADF short-run coefficients are fitted. The normalization chooses one variable as the response; its finite-sample consequences matter even when the underlying economic relation is symmetric.
Settings and design choices
Specify integration-order assumptions, normalization, deterministic terms, lag rule, common sample, and critical-value implementation. The supplied aTSA function returns several residual-regression variants, whereas the Python example requests one specific configuration; compare corresponding variants explicitly rather than treating every returned row as the same test.
Fitting and adaptation
Reestimate the long-run relation and residual dynamics whenever data or deterministic terms change. A bootstrap must reproduce both stages and their selection rules. Do not run an ordinary ADF function on fitted residuals and interpret its default p-value as an Engle–Granger p-value. Model changes following testing should be independently validated.
Sensitivity and robustness
Near-collinear series, breaks, mixed integration orders, weak error correction, and short samples complicate inference. Differencing both series before testing changes the scientific question. Nonrejection does not show no long-run relation, while rejection does not identify a causal mechanism. Examine stability and a suitable error-correction model after establishing the maintained assumptions.
How to use and calibrate
Use Engle–Granger/MacKinnon residual-cointegration critical values depending on regressors and deterministic terms.
Example application
Test whether two trending economic series have a stable long-run equilibrium.
Interpretation and pitfalls
Watch out
Ordinary ADF residual critical values are wrong. Results can depend on which variable is normalized as the response.
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
Engle–Granger residual-based cointegration test; aTSA reports multiple deterministic specifications. Its nlag convention and tabulated p-values can differ from statsmodels; use the same deterministic terms and effective residual lags before comparing.
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)
x=np.cumsum(rng.normal(size=160));y=1.5*x+rng.normal(size=160);Z=np.column_stack([y,x])
from statsmodels.tsa.stattools import coint
print(coint(y,x,trend="c",maxlag=4,autolag=None))
Output
CointResult(coint_t=-5.40518054596291, pvalue=2.7701798326788846e-05, critical_values=array([-3.96664605, -3.37482819, -3.0712318 ]))
Validated — Executed successfully in the validation environment · needs aTSA
set.seed(2026)
x<-cumsum(rnorm(160));y<-1.5*x+rnorm(160)
print(aTSA::coint.test(y,x,d=0,nlag=4,output=FALSE))
Output
lag EG p.value type 1 4 -6.8459519 0.01 type 2 4 -0.5501747 0.10 type 3 4 1.2852483 0.10
Sources
- statsmodels — statsmodels · tsa.stattools.cointstatsmodels.org
- statsmodels.tsa.stattools.cointstatsmodels.org
- coint.testsearch.r-project.org
- 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 203, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT203.