Skip to content

DPredict · Guide test 178

Davidson–MacKinnon J test

Tests one nonnested regression specification by augmenting it with fitted values from another.

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 · Davidson–MacKinnon J 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

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

The formula

y=xβ+γ y^M2+u,t=γ^/SE⁡(γ^)y = \mathbf x\beta + \gamma\,\hat y_{M_2} + u,\qquad t = \hat\gamma/\operatorname{SE}(\hat\gamma)

With your numbers

γ^=0.52,t=1.67 (reverse direction: t=3.60)\hat\gamma = 0.52,\qquad t = 1.67\ (\text{reverse direction: } t = 3.60)
M1:y∼xM_1: y \sim x
the model under test
M2:y∼zM_2: y \sim z
the rival model
y^M2\hat y_{M_2}
fitted values of the rival model

The verdict

t(57) = 1.67, p = .101

p > α = .050: compatible with H₀

Test both directions: both models can be rejected, or neither. Rejecting M1 says it misses something M2 has, not that M2 is right.

Statistic
1.668
p-value
0.1008
Davidson–MacKinnon J test on 60 observations of y with rival regressors x and z: t(57) = 1.67, p = .101. The p-value is above α = .050, so the data are compatible with H0.

Davidson–MacKinnon J test on 60 observations of y with rival regressors x and z: t(57) = 1.67, p = .101. The p-value is above α = .050, so the data are compatible with H₀.

Question and hypotheses

H0: model A encompasses the fitted predictions from nonnested model B.

Assumptions

Same response and observations; identifiable auxiliary regression and regular errors. Classical inference assumes homoskedasticity, while robust versions need valid covariance asymptotics.

Formula

y=XAβ+γy^B+uH0:γ=0\begin{gathered}y=X_A\beta+\gamma\widehat y_B+u\\[5pt] H_0:\gamma=0\end{gathered}

Parameters and notation

ŷB is the fitted response from rival model B; γ is the added coefficient.

Structure of the method

Fit both nonnested regressions on the same outcome and rows. Add the rival's fitted response as one generated regressor to the focal model and test its coefficient. Reverse the construction to test the other direction. This differs from adding all rival regressors in an encompassing model.

Estimated and nuisance parameters

Each model's regression coefficients and residual covariance are estimated, then an auxiliary coefficient measures information in the rival prediction beyond the focal design. Generated fitted values are dependent on the same sample; the test uses the established asymptotic construction rather than treating them as independent new data.

Settings and design choices

Define the rival specifications, tested direction, covariance estimator, observation set, and any transformation beforehand. Multiple rivals and bidirectional tests create a family of comparisons requiring a reporting or multiplicity plan.

Fitting and adaptation

Refit both candidate models whenever preprocessing or the shared sample changes, and use a supported robust covariance where the relevant asymptotics justify it. Do not replace in-sample rival fits by arbitrary machine-learning predictions while retaining the original calibration without justification. Subsequent model revision should be validated independently.

Sensitivity and robustness

Near-collinearity between rival predictions and focal regressors weakens identification of the auxiliary coefficient. Heteroskedasticity, dependence, and misspecification in both models complicate conclusions. Both directions may reject, or neither may reject; neither outcome automatically ranks predictive accuracy or establishes causality. Compare scientific interpretability and held-out performance separately.

How to use and calibrate

Test γ using the documented t/Wald procedure; repeat with A and B reversed if comparing both encompassing claims.

Example application

Compare two different sets of explanatory variables for the same response.

Interpretation and pitfalls

Watch out

Both models can be rejected or neither rejected. It is not a rule guaranteeing one model wins.

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_j
print(compare_j(sm.OLS(y,sm.add_constant(x)).fit(),sm.OLS(y,sm.add_constant(z)).fit()))
Output
(np.float64(5.722589247162545), np.float64(1.167555024637619e-07))
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::jtest(y~x,y~z,data=d))
Output
J test

Model 1: y ~ x
Model 2: y ~ z
                Estimate Std. Error t value  Pr(>|t|)    
M1 + fitted(M2)   1.0965    0.29079  3.7706 0.0002799 ***
M2 + fitted(M1)   1.0413    0.18530  5.6191 1.837e-07 ***
---
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 178, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT178.