Skip to content

DPredict · Guide test 237

CUSUM parameter stability test

Tests regression stability using cumulative sums of residuals or estimating functions.

Runs in CodeSplashPython (calls R) example not runR example validated

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

40
0.30
0.000

Adds curve × (x − 5)².

0.00

Error SD grows like exp(h · (x − 5)/5).

0.00

Errors in collection order carry φ × the previous error.

0.25
0.050

Your data

Simulated with a known ρ

If H₀ were true

S = 1.25
  1. 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).
  2. Your statistic, from the data above.
  3. The p-value: the area at least as extreme as yours (p = .004).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

Wr=1σ^n−p∑t=p+1rwt,S=max⁡r∣Wr∣1+2 r−pn−pW_r=\frac{1}{\hat\sigma\sqrt{n-p}}\sum_{t=p+1}^{r}w_t,\qquad S=\max_r\frac{|W_r|}{1+2\,\frac{r-p}{n-p}}

With your numbers

S=1.25,n=40S = 1.25,\quad n = 40
wtw_t
recursive residuals: standardized one-step-ahead prediction errors
1+2t1+2t
the linear boundary of Brown, Durbin and Evans
SS
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 H0.

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

W(r)=1σ^n−p∑t=p+1p+⌊r(n−p)⌋wtW(r)=\frac{1}{\widehat\sigma\sqrt{n-p}}\sum_{t=p+1}^{p+\lfloor r(n-p)\rfloor}w_t

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.

Python · invokes R

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()
R

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

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.