Cox Test
The Cox Test of Cox (1961, 1962), in the form of Pesaran (1974) for linear regressions, compares the log-likelihoods of the two models with the difference expected if the tested model were right. It is the original non-nested test, built on the likelihood ratio.
The formula for the Cox Test starts from the residual variances of the two models fitted by OLS and the projection \(M_{B}\) on the residual space of model B:
\[\hat{\sigma}_{A}^{2} = \frac{\text{SSR}_{A}}{n}\] \[\hat{\sigma}_{B}^{2} = \frac{\text{SSR}_{B}}{n}\] \[M_{B} = I - X_{B} \cdot (X'_{B} \cdot X_{B})^{-1} \cdot X'_{B}\]It then estimates the residual variance that model B would have if model A were right, and compares it with model B’s actual residual variance:
\[\hat{\sigma}_{\text{BA}}^{2} = \hat{\sigma}_{A}^{2} + \frac{\hat{\beta}_{A}' \cdot X'_{A} \cdot M_{B} \cdot X_{A} \cdot \hat{\beta}_{A}}{n}\] \[c = \left(\frac{n}{2}\right) \cdot \ln\left(\frac{\hat{\sigma}_{B}^{2}}{\hat{\sigma}_{\text{BA}}^{2}}\right)\]The statistic standardises that difference by its variance:
\[v = \left(\frac{\hat{\sigma}_{A}^{2}}{\hat{\sigma}_{\text{BA}}^{4}}\right) \cdot \hat{\beta}_{A}' \cdot X'_{A} \cdot M_{B} \cdot M_{A} \cdot M_{B} \cdot X_{A} \cdot \hat{\beta}_{A}\] \[q = \frac{c}{\sqrt{v}}\]Where \(\text{SSR}_{A}\) and \(\text{SSR}_{B}\) are the residual sums of squares of the two models, n the number of observations, \(X_{A}\) and \(X_{B}\) their regressors with a constant, hat(beta_A) the coefficients of model A, \(M_{A}\) the projection on the residual space of model A and I the identity matrix. q is asymptotically standard normal under the null that model A is right: model A is rejected when the two-sided p-value is below the significance level (0.05 for the 5% level). Like the J Test it rejects a correct model too often in small samples.
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: Cox-Pesaran test, Cox likelihood ratio test.
In the Finance Toolkit this is get_non_nested_test with method="cox", 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="cox")
| 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 | Cox Statistic | P-Value | Reject Tested Model (5%) |
|---|---|---|---|
| Model A against Model B | 5.3152 | 0 | 1 |
| Model B against Model A | -62.9064 | 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 Cox, D.R. (1961). “Tests of Separate Families of Hypotheses.” Proceedings of the Fourth Berkeley Symposium on Mathematical Statistics and Probability, 1, 105-123.
- Paper Cox, D.R. (1962). “Further Results on Tests of Separate Families of Hypotheses.” Journal of the Royal Statistical Society, Series B, 24(2), 406-424.
- Paper Pesaran, M.H. (1974). “On the General Problem of Model Selection.” Review of Economic Studies, 41(2), 153-171.
- Library Referenced against statsmodels’ compare_cox (Cox Test)