Skip to content

DPredict · Guide test 191

Goldfeld–Quandt test

Compares residual variances in two ordered portions of the data.

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 · Goldfeld–Quandt 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

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

The formula

GQ=RSShigh/(n2−2)RSSlow/(n1−2)GQ = \dfrac{\mathrm{RSS}_{\text{high}}/(n_2-2)}{\mathrm{RSS}_{\text{low}}/(n_1-2)}

With your numbers

GQ=4.59,ν1=18, ν2=18GQ = 4.59,\quad \nu_1 = 18,\ \nu_2 = 18
RSSlow, RSShigh\mathrm{RSS}_{\text{low}},\ \mathrm{RSS}_{\text{high}}
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 H0.

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

F=RSS2/(n2−p)RSS1/(n1−p)F=\frac{RSS_2/(n_2-p)}{RSS_1/(n_1-p)}

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.

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_goldfeldquandt
print(het_goldfeldquandt(y,X,idx=1,drop=.2))
Output
(np.float64(0.9425069984934233), np.float64(0.5806343925670858), 'increasing')
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::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

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.