DPredict · Guide test 176
Harvey–Collier test
Tests linear model specification using the behavior of recursive residuals.
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 · Harvey–Collier 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 t 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 = .061).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- recursive (one-step-ahead standardized) residuals
- their mean and SD
The verdict
t(37) = 1.94, p = .061
p > α = .050: compatible with H₀
If the relation is linear, out-of-sample prediction errors average zero; a curve makes them drift.
- Statistic
- 1.936
- p-value
- 0.0605
Harvey–Collier test on 40 (x, y) pairs: t(37) = 1.94, p = .061. The p-value is above α = .050, so the data are compatible with H₀.
Question and hypotheses
H0: the specified regression functional form is adequate, giving zero-mean recursive residuals.
Assumptions
Correct ordered linear model with independent normal homoskedastic errors for classical inference; initial observations must give full rank.
Formula
Parameters and notation
Fit each observation using only previous observations; m=n−p recursive residuals. Ordering can be by a prespecified predictor.
Structure of the method
Order the observations, estimate regression coefficients recursively using preceding rows, and standardize each next-observation prediction error by its leverage adjustment. The Harvey–Collier statistic tests whether the recursive residuals have a nonzero mean. Reusing ordinary full-sample residuals would remove the defining recursive construction.
Estimated and nuisance parameters
A sequence of expanding-window coefficient estimates is fitted, followed by the recursive-residual mean and variance. Initial model rank determines when residuals can be formed; the test degrees of freedom depend on the usable residual count rather than an arbitrary network complexity parameter.
Settings and design choices
Choose ordering, initial full-rank segment, included regressors, and one/two-sided interpretation before testing. Ordering by a scientifically meaningful predictor may reveal curvature; optimizing ordering after inspecting the response requires additional calibration.
Fitting and adaptation
Refit the model recursively using exactly the declared ordering and feature design. If applying a null simulation, reproduce the recursive initialization and leverage scaling in every replicate. Following rejection, investigate specific functional-form alternatives and validate revised regressions independently; changing the sequence until the test passes is not legitimate adaptation.
Sensitivity and robustness
Singular early design matrices, high leverage, heteroskedasticity, and serial dependence affect the classical t reference. The test is especially directed at systematic mean shifts in recursive errors and can miss other misspecifications. Check how software handles the starting observations and verify that changing row order is scientifically justified rather than accidental file sorting.
How to use and calibrate
Apply the documented t test of recursive residual mean zero; reference df=m−1.
Example application
Check curvature by ordering a regression sample along a predictor.
Interpretation and pitfalls
Watch out
Ordering affects power. A test of mean recursive residuals is not a comprehensive diagnostic for all misspecification.
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
Read the directional model comparison carefully: nonnested procedures can reject neither, one, or both models. A specification rejection does not identify the correct replacement model.
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 linear_harvey_collier
print(linear_harvey_collier(fit))
Output
TtestResult(statistic=np.float64(0.5183048473676405), pvalue=np.float64(0.6054381504566951), df=np.int64(96))
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::harvtest(fit))
Output
Harvey-Collier test data: fit HC = 0.34418, df = 96, p-value = 0.7315
Sources
- lmtest — lmtest · harvtestAuthor documentation/source reviewed: lmtest 0.9-40.search.r-project.org
- harvtestsearch.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 176, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT176.