Skip to content

DPredict · Guide test 001

Likelihood ratio test

Compares maximized likelihoods under a restricted null and a larger model; calibration depends on regularity conditions.

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 · Likelihood ratio 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

LR = 14.81
  1. The reference: how LR 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

LR=2 (ℓ1−ℓ0)=nln⁡RSS0RSS1∼χ12LR = 2\,(\ell_1-\ell_0) = n\ln\dfrac{\mathrm{RSS}_0}{\mathrm{RSS}_1} \sim \chi^2_1

With your numbers

LR=40 ln⁡64.1244.28=14.81LR = 40\,\ln\dfrac{64.12}{44.28} = 14.81
ℓ0, ℓ1\ell_0,\ \ell_1
log-likelihoods without and with the slope
RSS0, RSS1\mathrm{RSS}_0,\ \mathrm{RSS}_1
residual sums of squares of the two fits
χ12\chi^2_1
one restriction tested

The verdict

LR(1) = 14.81, p < .001

p ≤ α = .050: reject H₀

Compare how well the two models explain the data on the likelihood scale. Wald, LR and score tests agree in large samples; in small ones they differ in a fixed order (W ≥ LR ≥ LM).

Statistic
14.809
p-value
0.0001
Likelihood ratio test on 40 (x, y) pairs: LR(1) = 14.81, p < .001. The p-value is below α = .050, so the data are hard to reconcile with H0.

Likelihood ratio test on 40 (x, y) pairs: LR(1) = 14.81, p < .001. The p-value is below α = .050, so the data are hard to reconcile with H₀.

Question and hypotheses

H0: θ belongs to a restricted parameter set Θ0; H1: θ is in the larger model but outside Θ0.

Assumptions

The likelihood must represent the sampling process. The models are nested. The usual chi square approximation requires identifiable, interior parameters, smooth likelihood, nonsingular information, and a sufficiently large sample.

Formula

Λ=2{ℓ(θ^)−ℓ(θ^0)} ≈H0 χq2\Lambda=2\{\ell(\widehat\theta)-\ell(\widehat\theta_0)\}\ \overset{H_0}{\approx}\ \chi^2_q

Parameters and notation

ℓ is log likelihood; θ̂ and θ̂0 maximize it in the full and null models; q is the difference in free parameter dimensions.

Structure of the method

A likelihood engine fits the restricted and unrestricted parameter spaces to identical observations, then compares twice the optimized log-likelihood difference. Numerical optimization is part of the computation: check convergence, shared likelihood constants, and whether the restricted optimum is genuinely nested. Regular cases use a chi-square reference with the number of independent restrictions.

Estimated and nuisance parameters

Both models estimate their own nuisance parameters, including residual scale or dispersion when the likelihood requires it. The target restriction and its dimension are not estimated by the test. Record model ranks rather than counting nominal coefficients when the design is aliased.

Settings and design choices

Choose the null restrictions, sampling distribution, significance level, and asymptotic versus null-bootstrap calibration before inspecting significance. Solver tolerances and restart counts are numerical controls. A bootstrap replication budget governs Monte Carlo precision, not model complexity or a learned parameter.

Fitting and adaptation

Adaptation means refitting both models under the same likelihood and observation mask. A null parametric bootstrap simulates from the restricted fit and refits both models in every replicate; keeping alternative-model parameters fixed fails to reproduce the statistic's sampling distribution.

Sensitivity and robustness

Boundary parameters, weak identification, separation, and mixture-component testing can invalidate Wilks' ordinary chi-square law. ML and REML likelihoods cannot be interchanged casually when fixed effects differ. Inspect optimization failures in bootstrap replicates and report Monte Carlo uncertainty for small tail probabilities.

How to use and calibrate

Fit both models to exactly the same observations, compute Λ, and use the upper chi square tail. For boundary or small sample problems use an appropriate mixture law, exact calculation, or null parametric bootstrap.

Example application

To test whether three added predictors improve a logistic model, fit the restricted and expanded models and compare twice their log likelihood difference with χ²3.

Interpretation and pitfalls

Watch out

A variance component equal to zero is a boundary problem. Nonidentifiable mixture components and nonnested models invalidate ordinary Wilks calibration. A large statistic indicates disagreement with restrictions, not a large practical effect.

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

Nested Gaussian regression example; chi-square calibration is asymptotic. Use the same observations in both fits.

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()
print(fit.compare_lr_test(reduced))
Output
CompareLRTestResult(statistic=np.float64(5.360927752495741), pvalue=np.float64(0.020592815666549854), df_diff=np.float64(1.0))
R

Validated — Executed successfully in the validation environment · needs lmtest

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(lmtest::lrtest(reduced,fit))
Output
Likelihood ratio test

Model 1: y ~ x
Model 2: y ~ x + z
  #Df  LogLik Df  Chisq Pr(>Chisq)    
1   3 -135.58                         
2   4 -128.74  1 13.678   0.000217 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

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 001, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT001.