Skip to content

DPredict · Guide test 179

Cox nonnested model test

Compares nonnested model specifications through an adjusted likelihood based statistic.

Runs in CodeSplashPython example validatedR example validated

Do it in CodeSplash

In the app, set it up in Analyze with this method:

In Compare non-nested models (J, Cox, encompassing, PE, Vuong), choose Comparison = Two rival models of the outcome.

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 · Cox nonnested model test

60
0.40
0.50
0.30

0 makes M1 (y on x) the true model.

0.050

Your data

Simulated with known truth
—— M1: y ~ x—— M2: y ~ z

Two rival single-regressor models for the same y. Neither is nested in the other, so an F test cannot compare them directly.

If H₀ were true

z = −2.41
  1. The reference: how z 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 = .016).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

c01=n2ln⁡σ^M22σ^M2∣M12,z=c01/Var⁡^(c01)c_{01} = \tfrac{n}{2}\ln\dfrac{\hat\sigma^2_{M_2}}{\hat\sigma^2_{M_2|M_1}},\qquad z = c_{01}/\sqrt{\widehat{\operatorname{Var}}(c_{01})}

With your numbers

z=(−3.45)1.43=(−2.41)z = \dfrac{(-3.45)}{1.43} = (-2.41)
M1:y∼xM_1: y \sim x
the model under test
M2:y∼zM_2: y \sim z
the rival model
σ^M2∣M12\hat\sigma^2_{M_2|M_1}
M2's residual variance implied by M1's fit

The verdict

z = −2.41, p = .016

p ≤ α = .050: reject H₀

A centered likelihood-ratio comparison; like the J test, run both directions.

Statistic
−2.406
p-value
0.0161
Cox nonnested model test on 60 observations of y with rival regressors x and z: z = −2.41, p = .016. The p-value is below α = .050, so the data are hard to reconcile with H0.

Cox nonnested model test on 60 observations of y with rival regressors x and z: z = −2.41, p = .016. The p-value is below α = .050, so the data are hard to reconcile with H₀.

Question and hypotheses

H0: a specified nonnested model A is correctly specified relative to model B.

Assumptions

Same observations/response; regular normal linear regression models for the displayed implementation; identifiable nonnested projections.

Formula

CA,B=n2log⁡(sB2/sBA2)Z=CA,B/VA,BVA,B=nsA2(sBA2)2mean⁡(r2)\begin{gathered}C_{A,B}=\frac n2\log(s_B^2/s_{BA}^2)\\[5pt] Z=C_{A,B}/\sqrt{V_{A,B}}\\[5pt] V_{A,B}=n\frac{s_A^2}{(s_{BA}^2)^2}\operatorname{mean}(r^2)\end{gathered}

Parameters and notation

sA²,sB² are residual mean squares with denominator n; q=MB ŷA, where MB=I−PB is the residual-maker for rival model B; sBA²=sA²+mean(q²); r=MAq, with MA=I−PA for model A.

Structure of the method

Fit two nonnested normal regressions, compute their residual variance estimates, and project one model's fitted values through the rival and back through the focal residual space. Those projection residuals center and scale a nonnested likelihood contrast. The reverse-direction statistic requires a separate calculation.

Estimated and nuisance parameters

Candidate coefficient vectors, residual variances using the stated divisor, and auxiliary projection quantities are estimated. The variance of the adjusted contrast is a fitted asymptotic quantity. The procedure is unrelated to the Cox proportional-hazards survival model despite the shared surname.

Settings and design choices

Specify both mean-model designs, comparison direction, shared response scale, exact sample, and normal-error formulation. Transformations that change the dependent variable require an appropriate nonnested framework; a raw residual-sum comparison across scales is not sufficient.

Fitting and adaptation

Estimate both models on identical complete cases and compute the documented auxiliary regressions. If recalibrating by simulation, generate under the focal null and refit every component. Revising one model following rejection changes the comparison; use an independent assessment or disclose the exploratory sequence rather than reporting only the final favorable test.

Sensitivity and robustness

Near-overlapping model spaces can make normalization unstable, while poor error-distribution assumptions undermine classical inference. Sample size and high leverage affect the asymptotic approximation. Ordinary likelihood-ratio chi-square degrees of freedom do not apply to arbitrary nonnested models. Both hypotheses can fail simultaneously; a result is directional evidence about a specified null, not a guaranteed winner.

How to use and calibrate

Use asymptotic normal inference; compute the reverse-direction test separately. This is a centered nonnested likelihood comparison.

Example application

Compare rival normal regression specifications that are not nested.

Interpretation and pitfalls

Watch out

Do not apply ordinary likelihood-ratio χ² df differences. The Cox nonnested test is unrelated to Cox proportional hazards.

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

Read the directional model comparison carefully: nonnested procedures can reject neither, one, or both models. A specification rejection does not identify the correct replacement model.

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()
from statsmodels.stats.diagnostic import compare_cox
print(compare_cox(sm.OLS(y,sm.add_constant(x)).fit(),sm.OLS(y,sm.add_constant(z)).fit()))
Output
(np.float64(-3.1261572233258974), np.float64(0.001771068377378107))
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::coxtest(y~x,y~z,data=d))
Output
Cox test

Model 1: y ~ x
Model 2: y ~ z
                Estimate Std. Error z value  Pr(>|z|)    
fitted(M1) ~ M2  -4.3779    0.23943 -18.285 < 2.2e-16 ***
fitted(M2) ~ M1 -11.6505    0.16398 -71.050 < 2.2e-16 ***
---
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 179, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT179.