Skip to content

DPredict · Guide test 203

Engle–Granger cointegration test

Tests whether residuals from a long run levels relationship are stationary, with cointegration specific critical values.

Runs in CodeSplashPython example validatedR example validated

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

80
1.50
0.60

1: the gap is a random walk too (no cointegration).

1

Extra lags of Δy that soak up short-run dynamics.

0.050

Your data

Simulated with known truth
—— y– – x—— gap y − 0.79 − 1.53·x

Cointegrated series wander together: the gap from their long-run line keeps returning to zero.

If H₀ were true

τ = −4.26
  1. The reference: how τ varies across samples when H₀ is true, Engle–Granger τ, two series (MacKinnon) (MacKinnon (1994) response surface (asymptotic)).
  2. Your statistic, from the data above.
  3. The p-value: the area at least as extreme as yours (p = .003).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

yt=a+b xt+ut,Δu^t=γ u^t−1+∑j=1kδjΔu^t−j+ety_t = a + b\,x_t + u_t,\qquad \Delta\hat u_t = \gamma\,\hat u_{t-1} + \sum_{j=1}^{k}\delta_j\Delta\hat u_{t-j} + e_t

With your numbers

b^=1.53,τ=(−4.26),k=1\hat b = 1.53,\qquad \tau = (-4.26),\qquad k = 1
u^t\hat u_t
residuals of the cointegrating regression
τ\tau
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 H0.

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

yt=βTxt+dtTη+etΔe^t=γe^t−1+∑jϕjΔe^t−j+vt\begin{gathered}y_t=\beta^Tx_t+d_t^T\eta+e_t\\[5pt]\Delta\widehat e_t=\gamma\widehat e_{t-1}+\sum_j\phi_j\Delta\widehat e_{t-j}+v_t\end{gathered}

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.

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)
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 ]))
R

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

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.