DPredict · Guide test 180
Encompassing test
Tests whether one regression model contains the explanatory information of a competing nonnested model.
Do it in CodeSplash
In the app, set it up in Analyze with this method:
- Compare non-nested models (J, Cox, encompassing, PE, Vuong) — Which of two rival regression models explains the outcome better, when neither contains the other?
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 · Encompassing test
0 makes M1 (y on x) the true model.
Your data
Simulated with known truthTwo 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
- The reference: how F 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 = .101).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- the model under test
- the rival model
- the encompassing model with both regressors
The verdict
F(1, 57) = 2.78, p = .101
p > α = .050: compatible with H₀
A partial F test in disguise: M1 encompasses M2 if z adds nothing once x is in.
- Statistic
- 2.783
- p-value
- 0.1008
Encompassing test on 60 observations of y with rival regressors x and z: F(1, 57) = 2.78, p = .101. The p-value is above α = .050, so the data are compatible with H₀.
Question and hypotheses
H0: model A’s restrictions hold within a model containing the regressors of both A and B.
Assumptions
Same response and sample; full rank encompassing design; usual linear model assumptions or justified robust covariance.
Formula
Parameters and notation
E is the union model, q its additional independent regressors beyond A; pE its parameter count.
Structure of the method
Form a union design containing the independent columns from both candidate regressions, fit that encompassing model, and test restrictions that recover each smaller model. Classical partial F inference compares residual sums of squares; robust joint Wald inference instead uses an appropriate coefficient covariance estimate.
Estimated and nuisance parameters
Coefficients and residual variability in the two candidates and their union are fitted. The restriction rank is the number of genuinely additional independent regressors, not the raw column count before duplicates, factor coding, or aliased terms are resolved.
Settings and design choices
Choose candidate designs, common response scale, shared complete-case sample, covariance estimator, and directional comparisons. Factor contrasts and interaction coding must preserve the intended nesting. Searching large candidate unions raises both multiplicity and overfitting concerns.
Fitting and adaptation
Refit all models on exactly the same observations and inspect design rank. Robust covariance can be supplied only with a testing formulation that supports it; a robust standard error attached to an ordinary RSS ratio does not automatically robustify that ratio. Validate any selected final regression on independent data.
Sensitivity and robustness
A large union can consume residual degrees of freedom or be nearly singular, reducing power and numerical stability. Both smaller models can be rejected even if neither is predictively useful; both may survive because data are weak. Dependence and heteroskedasticity require appropriate inference. Encompassing evidence concerns the specified regressors and hypothesis, not unrestricted functional-form adequacy or causal identification.
How to use and calibrate
Test A against E, then B against E if required; use partial F or robust joint Wald inference.
Example application
Compare two nonnested predictor sets via a common larger regression.
Interpretation and pitfalls
Watch out
The union can be collinear or overfitted. Passing the encompassing test does not demonstrate predictive superiority.
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.
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_encompassing
print(compare_encompassing(sm.OLS(y,sm.add_constant(x)).fit(),sm.OLS(y,sm.add_constant(z)).fit()))
Output
stat pvalue df_num df_denom x 5.342011 2.293417e-02 1 97 z 32.748028 1.167555e-07 1 97
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::encomptest(y~x,y~z,data=d))
Output
Encompassing test
Model 1: y ~ x
Model 2: y ~ z
Model E: y ~ x + z
Res.Df Df F Pr(>F)
M1 vs. ME 97 -1 14.218 0.0002799 ***
M2 vs. ME 97 -1 31.575 1.837e-07 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1Sources
- lmtest — lmtest · encomptestAuthor documentation/source reviewed: lmtest 0.9-40.search.r-project.org
- encomptestsearch.r-project.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 180, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT180.