Skip to content

DPredict · Guide test 195

Breusch–Godfrey test

Tests regression error serial correlation through a specified lag order.

Runs in CodeSplashPython example validatedR example validated

Do it in CodeSplash

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

In Linear regression (OLS), choose Residual diagnostics = Full battery.

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 · Breusch–Godfrey test

40
0.30
0.000

Adds curve × (x − 5)².

0.00

Error SD grows like exp(h · (x − 5)/5).

0.50

Errors in collection order carry φ × the previous error.

0.00
0.050

Your data

Simulated with a known ρ

If H₀ were true

LM = 7.01
  1. The reference: how LM 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 = .008).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

LM=nR2 of et∼xt+et−1 ∼ χ12LM = nR^2\ \text{of } e_t\sim x_t+e_{t-1}\ \sim\ \chi^2_1

With your numbers

LM=7.01LM = 7.01
et−1e_{t-1}
previous residual, in collection order (0 for the first)

The verdict

LM(1) = 7.01, p = .008

p ≤ α = .050: reject H₀

Unlike Durbin–Watson it handles lagged dependent variables and higher orders. Serial correlation leaves estimates unbiased but standard errors wrong.

Statistic
7.014
p-value
0.0081
Breusch–Godfrey test on 40 (x, y) pairs: LM(1) = 7.01, p = .008. The p-value is below α = .050, so the data are hard to reconcile with H0.

Breusch–Godfrey test on 40 (x, y) pairs: LM(1) = 7.01, p = .008. The p-value is below α = .050, so the data are hard to reconcile with H₀.

Question and hypotheses

H0: no residual serial correlation through lag q.

Assumptions

Correct mean specification, suitable exogeneity/predetermined-regressor conditions and large sample regularity; can include lagged dependent variables.

Formula

et=Xtγ+∑j=1qρjet−j+vtLM=neffR2\begin{gathered}e_t=X_t\gamma+\sum_{j=1}^{q}\rho_je_{t-j}+v_t\\[5pt] LM=n_{eff}R^2\end{gathered}

Parameters and notation

Auxiliary regressors include the original X and q residual lags; treatment of initial lags affects neff.

Structure of the method

Regress fitted residuals on the original design and their first q lags, then test all lagged-residual coefficients jointly. Keeping the original regressors in the auxiliary model distinguishes the regression-based LM construction from simply applying a correlation test to residuals. The procedure can accommodate models containing lagged outcomes under appropriate conditions.

Estimated and nuisance parameters

Original regression coefficients, lagged residuals, auxiliary coefficients, and covariance or residual variance are estimated. Initial-lag treatment changes the effective sample and should be recorded; zero filling and dropping unavailable lags are different documented conventions.

Settings and design choices

Choose q, ordering, initial fill policy, chi-square versus finite-sample F version, and covariance assumptions. If repeated seasonal lags or many candidate orders are examined, define how multiple diagnostics will be interpreted rather than selecting the largest p-value.

Fitting and adaptation

Fit a justified mean model and reconstruct the entire auxiliary regression after changes. For heteroskedastic or clustered errors, use a specifically supported robust formulation or valid bootstrap; an ordinary LM reference is not automatically robust. Recalibration should repeat any fitted nuisance dynamics and preserve the dependence structure under the null.

Sensitivity and robustness

Too few lags miss residual dependence; too many consume power and make auxiliary regressors collinear. Mean misspecification, structural breaks, outliers, and incorrect chronology can generate rejection. A passing test only addresses the chosen lag span and assumptions, not independence or forecast adequacy. Report lag count, sample handling, and both statistic and effect-oriented residual plots.

How to use and calibrate

Use χ²q or a documented finite sample F approximation; select q transparently.

Example application

Check whether an autoregressive regression has remaining serial dependence.

Interpretation and pitfalls

Watch out

Heteroskedasticity can affect the conventional test. State the lag order and covariance variant.

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

The variance design/order and lag count are prespecified. LM and F versions may both be printed; identify which reference was used.

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)
import statsmodels.api as sm
n=100
x=rng.normal(size=n); z=rng.normal(size=n); y=1+.5*x+.3*z+rng.normal(size=n)
X=sm.add_constant(np.column_stack([x,z])); fit=sm.OLS(y,X).fit(); reduced=sm.OLS(y,X[:,:2]).fit()
from statsmodels.stats.diagnostic import acorr_breusch_godfrey
print(acorr_breusch_godfrey(fit,nlags=2))
Output
(np.float64(5.612346351331543), np.float64(0.06043582772372711), 2.8243784158523577, 0.06433858963057795)
R

Validated — Executed successfully in the validation environment · needs lmtest

set.seed(2026)
n <- 100; x <- rnorm(n); z <- rnorm(n); y <- 1+.5*x+.3*z+rnorm(n)
d <- data.frame(y,x,z); fit <- lm(y~x+z,data=d); reduced <- lm(y~x,data=d)
print(lmtest::bgtest(fit,order=2))
Output
	Breusch-Godfrey test for serial correlation of order up to 2

data:  fit
LM test = 2.9873, df = 2, p-value = 0.2246

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 195, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT195.