DPredict · Guide test 190
White heteroskedasticity test
Tests whether residual variance relates to regressors, their squares, and cross products.
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 · White heteroskedasticity 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 = .003).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- squares (and, with several predictors, cross-products)
The verdict
LM(2) = 11.41, p = .003
p ≤ α = .050: reject H₀
Very general, so also low powered and sensitive to misspecified means as well as variances.
- Statistic
- 11.406
- p-value
- 0.0033
White heteroskedasticity test on 40 (x, y) pairs: LM(2) = 11.41, p = .003. The p-value is below α = .050, so the data are hard to reconcile with H₀.
Question and hypotheses
H0: homoskedasticity against a quadratic variance specification.
Assumptions
Correct conditional mean, independent observations, sufficient moments and adequate sample size relative to auxiliary regressors.
Formula
Parameters and notation
Remove redundant square/cross-product columns; df is auxiliary rank minus one.
Structure of the method
Fit the mean model, expand variance predictors to include original terms, squares, and cross-products, and regress squared residuals on the expanded design. The LM statistic uses the auxiliary R-squared; its degrees of freedom reflect independent nonconstant columns. A reported auxiliary F statistic is a related approximation, not literally the original LM statistic.
Estimated and nuisance parameters
Mean-model coefficients, residuals, auxiliary coefficients, and design rank are estimated. No neural feature extractor is trained: the quadratic feature map is a prespecified diagnostic construction. Binary/factor columns can create duplicated squares or interactions that must be removed through rank handling.
Settings and design choices
Specify included predictors, interaction policy, covariance assumptions, and any reduced White variant. The expansion grows quadratically with predictor count, so full quadratic testing may be impractical with limited n. Do not select interactions by maximizing the test statistic without accounting for that selection.
Fitting and adaptation
Refit the mean model before testing its residuals. If collinearity causes rank deficiency, use a documented full-rank auxiliary design and matching degrees of freedom. Robust standard errors, a revised mean function, and an explicit variance model answer different follow-up questions; validate any revised model separately.
Sensitivity and robustness
Omitted mean nonlinearity can look like heteroskedasticity because residual squares vary systematically with predictors. Outliers, leverage, dependence, and near-saturated auxiliary regressions weaken calibration. Report both the effective auxiliary rank and sample size, and pair the diagnostic with residual plots and scientifically meaningful variance alternatives.
How to use and calibrate
Use χ²df or the documented auxiliary F approximation.
Example application
Detect heteroskedasticity without naming one variance-driving predictor.
Interpretation and pitfalls
Watch out
Mean misspecification can also cause rejection. Many predictors cause a very large auxiliary model and poor small sample behavior.
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
White auxiliary regression includes squares and interactions; counts independent nonconstant columns for degrees of freedom.
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_white
print(het_white(fit.resid,fit.model.exog))
Output
(np.float64(4.862030897279734), np.float64(0.4329492919668939), np.float64(0.960774985328602), np.float64(0.44597551685951786))
Validated — Executed successfully in the validation environment · needs Base/standard library
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)
e2<-residuals(fit)^2;aux<-lm(e2~x+z+I(x^2)+I(z^2)+I(x*z));T<-n*summary(aux)$r.squared;df<-qr(model.matrix(aux))$rank-1;print(c(LM=T,df=df,p=pchisq(T,df,lower.tail=FALSE)))
Output
LM df p 2.8619289 5.0000000 0.7212621
Sources
- statsmodels White variance teststatsmodels.org
- statsmodels.stats.diagnostic.het_whitestatsmodels.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 190, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT190.