3.9.2.2.4.1.12. statsmodels.regression.linear_model.OLSResults.compare_lr_test

OLSResults.compare_lr_test(restricted, large_sample=False)

Likelihood ratio test to test whether restricted model is correct

Parameters:

restricted : Result instance

The restricted model is assumed to be nested in the current model. The result instance of the restricted model is required to have two attributes, residual sum of squares, ssr, residual degrees of freedom, df_resid.

large_sample : bool

Flag indicating whether to use a heteroskedasticity robust version of the LR test, which is a modified LM test.

Returns:

lr_stat : float

likelihood ratio, chisquare distributed with df_diff degrees of freedom

p_value : float

p-value of the test statistic

df_diff : int

degrees of freedom of the restriction, i.e. difference in df between models

Notes

The exact likelihood ratio is valid for homoskedastic data, and is defined as

\[D=-2\log\left(\frac{\mathcal{L}_{null}} {\mathcal{L}_{alternative}}\right)\]

where \(\mathcal{L}\) is the likelihood of the model. With \(D\) distributed as chisquare with df equal to difference in number of parameters or equivalently difference in residual degrees of freedom.

The large sample version of the likelihood ratio is defined as

\[D=n s^{\prime}S^{-1}s\]

where \(s=n^{-1}\sum_{i=1}^{n} s_{i}\)

\[s_{i} = x_{i,alternative} \epsilon_{i,null}\]

is the average score of the model evaluated using the residuals from null model and the regressors from the alternative model and \(S\) is the covariance of the scores, \(s_{i}\). The covariance of the scores is estimated using the same estimator as in the alternative model.

This test compares the loglikelihood of the two models. This may not be a valid test, if there is unspecified heteroscedasticity or correlation. This method will issue a warning if this is detected but still return the results without taking unspecified heteroscedasticity or correlation into account.

This test compares the loglikelihood of the two models. This may not be a valid test, if there is unspecified heteroscedasticity or correlation. This method will issue a warning if this is detected but still return the results without taking unspecified heteroscedasticity or correlation into account.

is the average score of the model evaluated using the residuals from null model and the regressors from the alternative model and \(S\) is the covariance of the scores, \(s_{i}\). The covariance of the scores is estimated using the same estimator as in the alternative model.

TODO: put into separate function, needs tests