Skip to content

DPredict · Guide test 180

Encompassing test

Tests whether one regression model contains the explanatory information of a competing nonnested model.

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 · Encompassing 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

F = 2.78
  1. The reference: how F 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

F=(RSSM1−RSSE)/1RSSE/(n−3),E:y∼x+zF = \dfrac{(\mathrm{RSS}_{M_1} - \mathrm{RSS}_{E})/1}{\mathrm{RSS}_{E}/(n-3)},\qquad E: y \sim x + z

With your numbers

F=2.78 on (1,57) dfF = 2.78\ \text{on}\ (1, 57)\ df
M1:y∼xM_1: y \sim x
the model under test
M2:y∼zM_2: y \sim z
the rival model
EE
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 H0.

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

F=(RSSA−RSSE)/qRSSE/(n−pE)F=\frac{(RSS_A-RSS_E)/q}{RSS_E/(n-p_E)}

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.

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_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
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::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 ‘ ’ 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 180, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT180.