Encompassing Test
The Encompassing Test, following the encompassing principle of Mizon and Richard (1986), asks whether the tested model encompasses the rival: whether it explains everything the rival does. It adds the rival’s own regressors that the tested model lacks and tests them jointly with an F-test, against an artificial model that nests both.
The formula for the Encompassing Test regresses the dependent series on the regressors of model A and those of model B that model A does not have, by OLS:
\[y = X_{A} \cdot a + Z_{B} \cdot b + u\]The statistic is the F-statistic of the added regressors, comparing the residual sum of squares of model A alone with that of the combined model:
\[F = \frac{\frac{\text{SSR}_{A} - \text{SSR}}{q}}{\frac{\text{SSR}}{n - k}}\]Where y is the dependent series, \(X_{A}\) the regressors of model A with a constant, \(Z_{B}\) the regressors of model B that model A does not have, a and b their coefficients, u the error, \(\text{SSR}_{A}\) and SSR the residual sums of squares of model A and of the combined model, q the number of columns of \(Z_{B}\), n the number of observations and k the number of parameters of the combined model. F is F(q, n - k) distributed under the null that model A encompasses model B: model A is rejected when the p-value is below the significance level (0.05 for the 5% level). With many added regressors it loses power compared with the J Test, which adds only one.
Two explanations of the same returns, such as a sector ETF against the market, or one factor set against another, cannot be compared with an F-test when neither model is a special case of the other: the models are non-nested. A non-nested test takes one model as the null hypothesis and asks whether the other model explains something it misses, the alternative. Each test is run both ways, model A against model B and model B against model A. Rejecting one and not the other favours the one not rejected; rejecting both says each misses something the other has, and rejecting neither says the data cannot tell them apart. Unlike an information criterion, the tests can reject both models.
Also known as: encompassing F-test, artificial nesting test.
In the Finance Toolkit this is get_non_nested_test with method="encompassing", the same function as Non-Nested Test.
Example · XOM, XLE · 2025
Install the Finance Toolkit with pip install financetoolkit -U, then call get_non_nested_test:
from financetoolkit import Toolkit
toolkit = Toolkit(
["XOM", "XLE"],
api_key="FINANCIAL_MODELING_PREP_KEY",
start_date="2025-01-01",
end_date="2025-12-31",
)
# XOM explained by XLE (model A) or by the benchmark SPY (model B)
toolkit.econometrics.get_non_nested_test(method="encompassing")
| Parameter | Type | Description | Example |
|---|---|---|---|
dependent_ticker | str | None | The dependent (predicted) asset. Defaults to None, meaning the Toolkit instance’s first ticker. | "AAPL" |
independent_tickers | str | list[str] | None | The regressors of model A. Defaults to None, meaning every other ticker in the Toolkit instance besides dependent_ticker and the other independent tickers. | ["MSFT", "Benchmark"] |
other_independent_tickers | str | list[str] | None | The regressors of model B. Defaults to None, meaning “Benchmark”. | "GOOGL" |
include_benchmark | bool | Whether to include “Benchmark” in the default independent ticker(s) of model A. Defaults to False. | True |
period | str | The data frequency (daily, weekly, monthly, quarterly, or yearly). Defaults to “daily”. | "weekly" |
column | str | The historical data column to regress on. Defaults to “Return”. | "Return" |
method | str | The test. Options are: “j_test” (J Test), “encompassing” (Encompassing Test), “cox” (Cox Test). Defaults to “j_test”. | "j_test" |
rounding | int | None | The number of decimals to round the results to. Defaults to None. | 2 |
show_columns | str | list[str] | None | The columns to keep, a name or a list of names, matched on every column level, or the rows when no column has those names (such as the line items of a financial statement). Names that do not exist are logged, and when none exist the result is returned in full. Defaults to None, which keeps every column. | None, which keeps every column |
Which returns:
| Item | Encompassing F-Statistic | P-Value | Reject Tested Model (5%) |
|---|---|---|---|
| Model A against Model B | 53.3753 | 0 | 1 |
| Model B against Model A | 1,103.2400 | 0 | 1 |
2 rows
Using Your Own Data
get_non_nested_test runs on any data, not only prices: ratios, economic indicators, yield curves or your own dataset. Pass a DataFrame, a Series or a dictionary of them to Econometrics as data, with the dates in the rows or the columns, and set changes to how its changes are calculated: "percentage", "log", "difference" for rates and ratios, or None when the data are changes already. For example, for the monthly unemployment rates of the United States and Germany:
from financetoolkit import Economics, Econometrics
economics = Economics(start_date="2000-01-01")
unemployment = economics.get_unemployment_rate(
countries=["United States", "Germany"], period="monthly"
)
econometrics = Econometrics(data=unemployment, changes="difference")
econometrics.get_non_nested_test()
References
- Paper Mizon, G.E. and Richard, J.-F. (1986). “The Encompassing Principle and its Application to Testing Non-Nested Hypotheses.” Econometrica, 54(3), 657-678.
- Library Referenced against statsmodels’ compare_encompassing (Encompassing Test)