DPredict · Guide test 239
Nyblom–Hansen stability test
Tests whether model parameters remain constant over the observation sequence.
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 = Nyblom–Hansen (gradual drift).
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 · Nyblom–Hansen stability 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 L varies across samples when H₀ is true, simulated with these x: 499 sets of N(0, 1) errors (Monte Carlo with the regressors held fixed (499 draws on the shared stream)).
- 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
- cumulative scores (residual × regressor)
- their variance, so every coefficient is judged on its own scale
The verdict
L = 1.34, p = .004
p ≤ α = .050: reject H₀
Aimed at parameters that drift like a random walk; it is a locally most powerful test against that, not a way to date a break.
- Statistic
- 1.340
- p-value
- 0.0040
Nyblom–Hansen stability test on 40 (x, y) pairs: L = 1.34, p = .004. The p-value is below α = .050, so the data are hard to reconcile with H₀.
Question and hypotheses
H0: model parameters are constant; H1: stochastic/gradual parameter variation.
Assumptions
Regular estimated model with score contributions and a valid information/long-run covariance estimate.
Formula
Parameters and notation
si are per-observation scores; remove the fitted-score total as required to obtain the centered bridge process. Ω is score long-run covariance.
Structure of the method
Fit a regular parametric or estimating-equation model, calculate observation-level scores, build their centered cumulative process, decorrelate by an information/long-run covariance estimate, and integrate its squared norm. The integrated functional accumulates instability across the ordering rather than testing one chosen breakpoint.
Estimated and nuisance parameters
Estimate model parameters and score covariance; determine which parameter coordinates, including any variance score, enter the process. The dimension governs its null distribution. Singular information from redundant parameters or sparse outcomes prevents ordinary inversion and needs an explicitly justified reduced parameterization.
Settings and design choices
Choose model, ordering, score extractor, covariance method, tested coordinates, and the integrated functional. The supplied meanL2BB route identifies a particular integrated Brownian-bridge statistic. Changing to a supremum or univariate-coordinate maximum changes the test, not merely its visual presentation.
Fitting and adaptation
Refit the model and regenerate scores whenever its specification changes. For dependence or model misspecification, use valid estimating-function covariance and matching calibration. If a bootstrap is employed, repeat estimation and any parameter selection under the null; there are no independently fine-tunable neural components inside the test.
Sensitivity and robustness
Inspect parameter identifiability, score outliers, ordering choice, covariance condition number, and whether instability is in the mean or variance. A rejection supports parameter instability under the fitted framework, while a nonsignificant integrated statistic may miss a localized change. Its null is not an ordinary chi-square solely because squared scores appear.
How to use and calibrate
Use Nyblom–Hansen-specific integrated Brownian-bridge critical values or a model-valid bootstrap.
Example application
Assess whether parameters drift rather than jump once.
Interpretation and pitfalls
Watch out
The null is not ordinary χ². Singular score covariance and data-dependent parameter selection need special treatment.
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::gefp(y~x,data=d,fit=lm),functional=strucchange::meanL2BB))
"""
# 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::gefp(y~x,data=d,fit=lm),functional=strucchange::meanL2BB))
Output
M-fluctuation test data: strucchange::gefp(y ~ x, data = d, fit = lm) f(efp) = 0.07855, p-value = 0.8645
Sources
- strucchange — strucchange · gefpAuthor documentation/source reviewed: strucchange 1.6-0.search.r-project.org
- gefpsearch.r-project.org
- meanL2BBsearch.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 239, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT239.