DPredict · Guide test 195
Breusch–Godfrey test
Tests regression error serial correlation through a specified lag order.
Do it in CodeSplash
In the app, set it up in Analyze with this method:
- Linear regression (OLS) — How does a numeric outcome depend on one or more predictors?
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
Adds curve × (x − 5)².
Error SD grows like exp(h · (x − 5)/5).
Errors in collection order carry φ × the previous error.
Your data
Simulated with a known ρIf H₀ were true
- The reference: how LM varies across samples when H₀ is true.
- Your statistic, from the data above.
- The p-value: the area at least as extreme as yours (p = .008).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- 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 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
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.
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)
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
- lmtest — lmtest · bgtestAuthor documentation/source reviewed: lmtest 0.9-40.search.r-project.org
- bgtestsearch.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 195, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT195.