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")

Which returns:

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)
Share