DPredict · Guide test 237
CUSUM parameter stability test
Tests regression stability using cumulative sums of residuals or estimating functions.
Do it in CodeSplash
In the app, set it up in Analyze with this method:
- Structural change in a regression — Did the relationship between the outcome and its predictors change over time — at a known date, at an unknown date, or gradually?
In Structural change in a regression, choose Test = Recursive CUSUM (Brown–Durbin–Evans).
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 · Recursive CUSUM 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 S varies across samples when H₀ is true, Brown–Durbin–Evans crossing law of a Brownian motion (Brown–Durbin–Evans crossing probability for the boundary 1 + 2t).
- Your statistic, from the data above.
- The p-value: the area at least as extreme as yours (p = .004).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- recursive residuals: standardized one-step-ahead prediction errors
- the linear boundary of Brown, Durbin and Evans
- compared with the boundary-crossing law of a Brownian motion (the curve)
The verdict
S = 1.25, p = .004
p ≤ α = .050: reject H₀
Good at gradual or early drift in the intercept; it has little power against a change that leaves the mean of the errors near zero, such as a pure slope change at the mean of x.
- Statistic
- 1.253
- p-value
- 0.0035
Recursive CUSUM test on 40 (x, y) pairs: S = 1.25, p = .004. The p-value is below α = .050, so the data are hard to reconcile with H₀.
Question and hypotheses
H0: regression parameters are stable over the ordering.
Assumptions
Correct regression under H0, stable innovation variance for the classical recursive version, and an ordering meaningful to the question.
Formula
Parameters and notation
wt are recursive residuals as in entry 176; r∈[0,1]. OLS-CUSUM instead uses cumulative full-sample residuals and a Brownian-bridge limit.
Structure of the method
Fit a regression and form a standardized cumulative residual or score process over the declared ordering, then compare the entire path with simultaneous boundaries or a matching functional distribution. Recursive and full-sample OLS residuals induce different limiting processes and must remain distinct implementation choices.
Estimated and nuisance parameters
Estimate regression coefficients and residual scale; recursive versions repeatedly update coefficients from earlier observations. OLS versions use the complete fitted model, while score-based variants may include multiple parameter directions. The cumulative path is a diagnostic statistic, not a separately trained sequence model.
Settings and design choices
Choose residual type, ordering, initial estimation size, variance or long-run variance treatment, and monitoring versus retrospective testing. A larger initial fit stabilizes recursive estimates but leaves fewer monitored observations. Changing the ordering changes the question, particularly when observations are sorted by a covariate rather than time.
Fitting and adaptation
Refit the regression after changes to controls or sample, then regenerate its entire process and matching boundary. For dependence, use the documented long-run variance option or a valid bootstrap where available. Selecting the visually most dramatic residual process after inspection needs appropriate multiplicity/selection handling.
Sensitivity and robustness
Inspect variance instability, omitted nonlinear terms, influential points, and initial-design rank problems. A path crossing can indicate broad specification failure rather than one interpretable coefficient jump. Pointwise normal bands or a single large residual do not provide the same familywise inference as a whole-path CUSUM test.
How to use and calibrate
Compare the process to simultaneous CUSUM boundaries or use its supremum distribution; identify recursive versus OLS version.
Example application
Monitor a regression for gradual parameter instability.
Interpretation and pitfalls
Watch out
Pointwise normal intervals do not provide a valid whole-path test. Variance changes can also trigger rejection.
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
Chow fixes a breakpoint at observation 50; supF searches the trimmed range and uses search-adjusted calibration. CUSUM/MOSUM/score fluctuation tests assess parameter constancy in observation order; MOSUM h is window fraction.
Not run — Executed end to end through Rscript · needs Python standard library + Rscript; R packages: strucchange
# 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(strucchange::sctest(strucchange::efp(y~x,data=d,type="Rec-CUSUM")))
"""
# 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 strucchange
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(strucchange::sctest(strucchange::efp(y~x,data=d,type="Rec-CUSUM")))
Output
Recursive CUSUM test data: strucchange::efp(y ~ x, data = d, type = "Rec-CUSUM") S = 0.39122, p-value = 0.8602
Sources
- strucchange — strucchange · efpAuthor documentation/source reviewed: strucchange 1.6-0.search.r-project.org
- efpsearch.r-project.org
- sctestsearch.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 237, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT237.