pythonstatisticscanopypysal

OLS Breusch Pagan test in Python


I used the statsmodels package to estimate my OLS regression. Now I want Breusch Pagan test. I used the pysal package for this test but this function returns an error:

import statsmodels.api as sm
import pysal

model = sm.OLS(Y,X,missing = 'drop')
rs = model.fit()
pysal.spreg.diagnostics.breusch_pagan(rs)

returned error:

AttributeError: 'OLSResults' object has no attribute 'u'

What should I do?


Solution

  • The problem is that the regression results instance of statsmodels is not compatible with the one in pysal.

    You can use breuschpagan from statsmodels, which takes OLS residuals and candidates for explanatory variables for the heteroscedasticity and so it does not rely on a specific model or implementation of a model.

    documentation: https://www.statsmodels.org/devel/generated/statsmodels.stats.diagnostic.het_breuschpagan.html

    with examples here https://www.statsmodels.org/devel/examples/notebooks/generated/regression_diagnostics.html

    I do not know if there are any essential differences in the implementation of the Breusch-Pagan test.

    It looks like the name is misspelled in statsmodels.

    edit The spelling of the name has been corrected in statsmodels version 0.9. The old incorrect spelling was breushpagan.