DPredict · Guide test 192
Harrison–McCabe test
Tests variance constancy using the share of residual sum of squares in a chosen sample portion.
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 · Harrison–McCabe 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 HMC varies across samples when H₀ is true, HMC for n = 40 under constant variance (Monte Carlo null: 1,999 samples simulated under H₀ (seed 20261107)).
- Your statistic, from the data above.
- The p-value: the area at least as extreme as yours (p = .030).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- residuals of y ~ x, ordered by x
- share of the residual sum of squares in the first half: ½ under H₀
The verdict
HMC = 0.30, p = .030
p ≤ α = .050: reject H₀
Small HMC rejects: the later half is noisier. The order matters; ordering by the wrong variable hides the pattern.
- Statistic
- 0.300
- p-value
- 0.0300
Harrison–McCabe test on 40 (x, y) pairs: HMC = 0.30, p = .030. The p-value is below α = .050, so the data are hard to reconcile with H₀.
Question and hypotheses
H0: constant regression error variance over the chosen ordering.
Assumptions
Correct regression and independent errors; normal-model simulation for the usual calibration; prespecified ordering and breakpoint.
Formula
Parameters and notation
m is the split position; ei are full-model residuals ordered as specified.
Structure of the method
Fit one regression to all observations, order its residuals, and compute the fraction of total squared residuals lying before a chosen breakpoint. A lower-tail null simulation assesses an unexpectedly small early fraction. The residuals are correlated through the fitted design, so an independent-sum-of-squares beta argument is not automatically applicable.
Estimated and nuisance parameters
Full-model coefficients and residuals are estimated; the overall scale cancels in the ratio. Leverage and the residual-maker matrix determine its design-dependent behavior. The breakpoint and ordering variable are analysis choices rather than estimated change-point parameters in this fixed-split test.
Settings and design choices
Specify ordering, split fraction/index, simulation count, seed, and exact implementation. The package can also plot the statistic across breakpoints, but that plot does not convert a fixed-point p-value into a valid searched-breakpoint p-value.
Fitting and adaptation
A conditional null simulation can generate normal errors for the fixed design, refit the regression, and recompute the ordered ratio in each replicate. Record whether the supplied software uses that design-refitted reference or a different approximation. Model revision requires rerunning residual construction; there is no neural fine-tuning stage.
Sensitivity and robustness
Leverage patterns, small early/late subsets, heavy tails, dependence, and misspecified means influence the ratio. A large value points in the opposite direction from the stated increasing-variance alternative. Repeated breakpoint searches and selective omission of observations require recalibration. Report the split and Monte Carlo uncertainty rather than only a rounded p-value.
How to use and calibrate
Small H supports larger variance after the split. Use the documented null simulation; a design-conditional simulation can generate normal errors, refit the same X, and recompute H.
Example application
Investigate a variance increase along an ordered predictor.
Interpretation and pitfalls
Watch out
Residuals have leverage-dependent covariance, so H is not simply an independent chi-square ratio. Report the simulation method.
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.
Not run — Executed end to end through Rscript · needs Python standard library + Rscript; R packages: lmtest
# Python launcher for the complete R implementation below.
# Requires Rscript on PATH and the listed R packages.
import shutil
import subprocess
rscript = shutil.which("Rscript")
if rscript is None:
raise RuntimeError("Install R and make Rscript available on PATH.")
r_code = r"""
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::hmctest(fit,order.by=~x,data=d,simulate.p=TRUE))
"""
# No shell interpolation. A failed R execution raises an error in Python.
result = subprocess.run([rscript, "--vanilla", "-"], input=r_code,
text=True, capture_output=True)
print(result.stdout)
if result.stderr:
print(result.stderr)
result.check_returncode()
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::hmctest(fit,order.by=~x,data=d,simulate.p=TRUE))
Output
Harrison-McCabe test data: fit HMC = 0.45585, p-value = 0.273
Sources
- lmtest — lmtest · hmctestAuthor documentation/source reviewed: lmtest 0.9-40.search.r-project.org
- hmctestsearch.r-project.org
- Statistics guide v4 (historical):
- Python: Executed end to end through Rscript · R: Executed successfully in the validation environment
- Reference's record:
- Edition 2 review: Python: skip · R: not executed (Rscript unavailable); why not run: Python: Python-to-R bridge; Rscript is unavailable. R code was not executed. Python: Not run in the reference's review: Python-to-R bridge; Rscript is unavailable. R code was not executed. R: Reviewed but not run: R wasn't available to the reference's authors.
From the CodeSplash statistics guide (v4), entry 192, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT192.