DPredict · Guide test 191
Goldfeld–Quandt test
Compares residual variances in two ordered portions of the data.
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 · Goldfeld–Quandt 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 GQ 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 = .001).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- residual sums of squares of separate fits to the lower and upper halves by x
The verdict
F(18, 18) = 4.59, p = .001
p ≤ α = .050: reject H₀
Exact under normality for a variance that grows with x; dropping the middle third raises its power.
- Statistic
- 4.585
- p-value
- 0.0011
Goldfeld–Quandt test on 40 (x, y) pairs: F(18, 18) = 4.59, p = .001. The p-value is below α = .050, so the data are hard to reconcile with H₀.
Question and hypotheses
H0: error variances in two ordered subsets are equal.
Assumptions
Independent normal errors and correctly specified regressions; split/order and omitted middle fraction chosen in advance.
Formula
Parameters and notation
Order by a suspected variance driver; fit the same p-coefficient mean model separately in low and high subsets.
Structure of the method
Sort observations by a specified variance driver, omit an optional central block, and fit the same regression separately to the low and high subsets. Compare residual mean squares using an F ratio with subset-specific residual degrees of freedom. The subsets need separate coefficient fits even when the scientific mean specification is common.
Estimated and nuisance parameters
Two regression coefficient vectors and two residual variance estimates are fitted. The ordering, split, and deleted middle region determine which observations contribute but are design choices, not estimated error-variance parameters.
Settings and design choices
Prespecify ordering variable, split position, central omission, tail direction, and required minimum subset rank. Software differs in whether a drop fraction is removed around a midpoint or after an explicit split; inspect actual selected indices before expecting Python/R results to coincide.
Fitting and adaptation
Fit each subset with the same declared predictor columns and verify adequate degrees of freedom. If the variance pattern is unknown, searching orderings and breakpoints needs adjusted or simulation-based calibration. A subsequent variance model or weighted regression should be justified from scientific structure and separately validated.
Sensitivity and robustness
Gaussian independent errors support the classical exact ratio reference; heavy tails and dependence can distort it. Structural changes in the conditional mean, influential observations, and unbalanced subset sizes may resemble heteroskedasticity. Omitting more central data can increase separation while reducing precision. State actual subset sizes and direction, and distinguish the variance diagnostic from a general structural-break test.
How to use and calibrate
Use Fn2−p,n1−p, usually one sided for increasing variance; state a two sided convention when used.
Example application
Check whether measurement noise rises with predicted scale.
Interpretation and pitfalls
Watch out
A structural mean change can mimic variance heterogeneity. Searching splits requires adjusted calibration.
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 het_goldfeldquandt
print(het_goldfeldquandt(y,X,idx=1,drop=.2))
Output
(np.float64(0.9425069984934233), np.float64(0.5806343925670858), 'increasing')
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::gqtest(fit,order.by=~x,data=d,fraction=.2))
Output
Goldfeld-Quandt test data: fit GQ = 0.92416, df1 = 37, df2 = 37, p-value = 0.5942 alternative hypothesis: variance increases from segment 1 to 2
Sources
- lmtest — lmtest · gqtestAuthor documentation/source reviewed: lmtest 0.9-40.search.r-project.org
- gqtestsearch.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 191, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT191.