DPredict · Guide test 003
Rao score test or Lagrange multiplier test
Tests restrictions using the likelihood slope evaluated under the null, often avoiding fitting the alternative model.
Do it in CodeSplash
In the app, set it up in Analyze with one of these methods:
- One proportion (exact binomial / score test) — Does the share of an outcome differ from a reference proportion?
- Two independent proportions (z, Fisher, Boschloo, Barnard, non-inferiority) — Does the share of an outcome differ between two independent groups?
- Compare nested models (LR, Wald, score, partial F) — Do the added predictors improve the model significantly?
- Cox proportional hazards regression — Which factors are associated with the hazard of the event?
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 · Rao score (Lagrange multiplier) 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 LM 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 = < .001).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- residuals of the model without x
- share of those residuals x explains
The verdict
LM(1) = 12.38, p < .001
p ≤ α = .050: reject H₀
The score test only needs the restricted fit, which makes it the natural test for adding terms. It is the smallest of the three statistics.
- Statistic
- 12.377
- p-value
- 0.0004
Rao score (Lagrange multiplier) test on 40 (x, y) pairs: LM(1) = 12.38, p < .001. The p-value is below α = .050, so the data are hard to reconcile with H₀.
Question and hypotheses
H0: a subset of parameters ψ equals ψ0; H1: ψ differs.
Assumptions
The likelihood is differentiable and correctly specified, nuisance estimates under H0 are consistent, and efficient information is nonsingular. Standard chi square calibration assumes interior restrictions and adequate sample size.
Formula
Parameters and notation
Uψ is the likelihood derivative for the tested parameters, evaluated at ψ0 and the null nuisance estimate λ̂0; I is expected or suitably consistent observed information; q=dim(ψ).
Structure of the method
Fit the model under the null, evaluate score derivatives for the omitted directions, and remove their nuisance-parameter information through a Schur complement. In the displayed Gaussian-regression example, the auxiliary regression of null residuals on the expanded design yields the asymptotic n-times-R-squared score statistic.
Estimated and nuisance parameters
Estimate nuisance coefficients and scale under the null only. The tested coefficients remain fixed at their hypothesized values during this fit. Efficient information accounts for correlation between nuisance and tested directions; using a raw tested-parameter information block can overstate the available information.
Settings and design choices
Specify which variables or restrictions are tested, expected versus observed information where justified, covariance robustness, and chi-square or resampling calibration. Numerical differentiation steps and optimizer tolerance need stability checks. The number of auxiliary regressors is not automatically the number of tested restrictions.
Fitting and adaptation
For new data or a changed null, refit the restricted model and recompute its derivatives and information. A parametric bootstrap regenerates data under the restricted fit and repeats the null-fitting stage. Neural fine-tuning is irrelevant; the adaptation is likelihood refitting and null recalibration.
Sensitivity and robustness
A zero score caused by aliasing or separation does not establish the null. Sparse outcomes, boundary restrictions, misspecified variance, or a singular nuisance information matrix require a specialized reference. The nR-squared shortcut is model-specific, not a general recipe for every score test.
How to use and calibrate
Fit only the restricted model, calculate the efficient score, and compare S with χ²q. In many regression diagnostics the same calculation appears as nR² from an auxiliary regression.
Example application
Test an additional predictor in a generalized linear model from the fitted null model’s residuals and design matrix.
Interpretation and pitfalls
Watch out
The nuisance adjustment matters; using the ψ block alone can be wrong. “LM test” labels many different hypotheses. Robust versions require their own covariance construction.
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
Gaussian omitted-variable score/LM example: regress null-model residuals on the full design; nR² has an asymptotic chi-square reference.
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()
aux=sm.OLS(reduced.resid,X).fit()
LM=n*aux.rsquared
print({"LM":LM,"p":stats.chi2.sf(LM,1)})
Output
{'LM': np.float64(5.219763815178203), 'p': np.float64(0.022331583899805482)}Validated — Executed successfully in the validation environment · needs Base/standard library
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)
e <- residuals(reduced); aux <- lm(e~x+z); LM <- n*summary(aux)$r.squared
print(c(LM=LM,p=pchisq(LM,1,lower.tail=FALSE)))
Output
LM p 1.278362e+01 3.496671e-04
Sources
- gmm — gmm · specTestAuthor documentation/source reviewed: gmm 1.9-1.search.r-project.org
- statsmodels statistical testsstatsmodels.org
- specTestsearch.r-project.org
- statsstatsmodels.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 003, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT003.