Skip to content

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.

Runs in CodeSplashPython example validatedR example validated

Do it in CodeSplash

In the app, set it up in Analyze with one of these methods:

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

40
0.25
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.00
0.050

Your data

Simulated with a known ρ

If H₀ were true

LM = 12.38
  1. The reference: how LM varies across samples when H₀ is true.
  2. Your statistic, from the data above.
  3. The p-value: the area at least as extreme as yours (p = < .001).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

LM=nRe0∼x2=n(RSS0−RSS1)RSS0∼χ12LM = nR^2_{e_0\sim x} = \dfrac{n(\mathrm{RSS}_0-\mathrm{RSS}_1)}{\mathrm{RSS}_0} \sim \chi^2_1

With your numbers

LM=40 (64.12−44.28)64.12=12.38LM = \dfrac{40\,(64.12-44.28)}{64.12} = 12.38
e0e_0
residuals of the model without x
R2R^2
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 H0.

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

S=UψTIψψ⋅λ−1Uψ,Iψψ⋅λ=Iψψ−IψλIλλ−1IλψS=U_\psi^T I_{\psi\psi\cdot\lambda}^{-1}U_\psi,\qquad I_{\psi\psi\cdot\lambda}=I_{\psi\psi}-I_{\psi\lambda}I_{\lambda\lambda}^{-1}I_{\lambda\psi}

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.

Python · native

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

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

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.