Skip to content

DPredict · Guide test 188

Breusch–Pagan heteroskedasticity test

Tests whether error variance depends on specified explanatory variables.

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–Pagan heteroskedasticity test

40
0.30
0.000

Adds curve × (x − 5)².

0.90

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

0.00

Errors in collection order carry φ × the previous error.

0.00
0.050

Your data

Simulated with a known ρ

If H₀ were true

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

The formula

BP=12 ESS of ei2σ^2∼x ∼ χ12BP = \tfrac{1}{2}\,\mathrm{ESS}\ \text{of } \dfrac{e_i^2}{\hat\sigma^2}\sim x \ \sim\ \chi^2_1

With your numbers

BP=8.67BP = 8.67
eie_i
residuals
σ^2=RSS/n\hat\sigma^2 = \mathrm{RSS}/n
maximum likelihood error variance
ESS\mathrm{ESS}
explained sum of squares

The verdict

BP(1) = 8.67, p = .003

p ≤ α = .050: reject H₀

The original version assumes normal errors; with heavy tails it over-rejects — use Koenker's studentized form.

Statistic
8.670
p-value
0.0032
Breusch–Pagan heteroskedasticity test on 40 (x, y) pairs: BP(1) = 8.67, p = .003. The p-value is below α = .050, so the data are hard to reconcile with H0.

Breusch–Pagan heteroskedasticity test on 40 (x, y) pairs: BP(1) = 8.67, p = .003. The p-value is below α = .050, so the data are hard to reconcile with H₀.

Question and hypotheses

H0: regression error variance is constant against specified variance predictors Z.

Assumptions

Correct mean model; independent normal errors for the original Breusch–Pagan LM derivation; adequate sample size.

Formula

fi=ei2/σ^2−1LM=12∑if^i2\begin{gathered}f_i=e_i^2/\widehat\sigma^2-1\\[5pt] LM=\tfrac12\sum_i\widehat f_i^2\end{gathered}

Parameters and notation

σ̂²=Σei²/n; regress f on an intercept and q variance predictors; f̂ are auxiliary fitted values.

Structure of the method

Fit the conditional mean by OLS, scale squared residuals using the null error variance, and project the resulting variance score onto specified variance predictors. The original Breusch–Pagan LM statistic uses the normal-error score scaling. The studentized Koenker calculation is a related but distinct version.

Estimated and nuisance parameters

Mean-model coefficients and the null residual variance are fitted nuisance quantities. Auxiliary variance-regression coefficients indicate directions of possible variance change; they are not automatically a fully specified positive conditional-variance model suitable for prediction.

Settings and design choices

Specify variance predictors separately from mean predictors where scientifically justified, include the required constant, and select original versus studentized calibration explicitly. The examples correctly request robust=False or studentize=FALSE for the original form. Covariance dependence assumptions and weights also matter.

Fitting and adaptation

Fit the mean model on the intended analysis sample and compute residuals consistently. If the mean specification changes, rerun the diagnostic because omitted mean structure can create systematic squared residuals. A fitted variance model, weighted least squares, or heteroskedasticity-consistent inference is a subsequent analysis decision, not a way to erase the original test.

Sensitivity and robustness

Nonnormal heavy-tailed errors undermine the original normality-dependent score scaling. Leverage, outliers, dependence, and too many variance predictors can distort size or power. Rejection does not identify the exact variance function, and nonrejection does not certify equal variance. Report the variant, auxiliary design rank, and a residual-versus-fit or scale-location plot.

How to use and calibrate

Use χ²q asymptotically. Specify variance predictors; they need not equal the mean-model predictors.

Example application

Detect error spread that increases with a predictor.

Interpretation and pitfalls

Watch out

The default in some software is the Koenker studentized version, not this original normality-dependent statistic.

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 het_breuschpagan
print(het_breuschpagan(fit.resid,fit.model.exog,robust=False))
Output
(np.float64(0.6645249615516491), np.float64(0.7172990209391937), np.float64(0.31906150917801623), np.float64(0.7275907086566948))
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::bptest(fit,studentize=FALSE))
Output
	Breusch-Pagan test

data:  fit
BP = 0.21026, df = 2, p-value = 0.9002

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