statsmodels: AttributeError: module 'scipy.stats' has no attribute 'chisqprob'
Error: c:\program files (x86)\python35-64\lib\site-packages\statsmodels\discrete\discrete_model.py in summary(self, yname, xname, title, alpha, yname_list) 2756 yname_list=None): 2757 smry = super(BinaryResults, self).summary(yname, xname, title, alpha, -> 2758 yname_list) 2759 fittedvalues = self.model.cdf(self.fittedvalues) 2760 absprederror = np.abs(self.model.endog - fittedvalues)
c:\program files (x86)\python35-64\lib\site-packages\statsmodels\discrete\discrete_model.py in summary(self, yname, xname, title, alpha, yname_list) 2548 (‘Log-Likelihood:’, None), 2549 (‘LL-Null:’, [“%#8.5g” % self.llnull]), -> 2550 (‘LLR p-value:’, [“%#6.4g” % self.llr_pvalue]) 2551 ] 2552
c:\program files (x86)\python35-64\lib\site-packages\statsmodels\tools\decorators.py in get(self, obj, type) 95 if _cachedval is None: 96 # Call the “fget” function —> 97 _cachedval = self.fget(obj) 98 # Set the attribute in obj 99 # print(“Setting %s in cache to %s” % (name, _cachedval))
c:\program files (x86)\python35-64\lib\site-packages\statsmodels\discrete\discrete_model.py in llr_pvalue(self) 2403 @cache_readonly 2404 def llr_pvalue(self): -> 2405 return stats.chisqprob(self.llr, self.df_model) 2406 2407 @cache_readonly
AttributeError: module ‘scipy.stats’ has no attribute ‘chisqprob’
To reproduce the error: Dataset information - http://www.statsmodels.org/dev/datasets/generated/ccard.html
Code:
df = sm.datasets.ccard.load_pandas().data
df['intercept'] = 1
df = df[['intercept', 'AGE', 'INCOME','OWNRENT']]
model = sm.Logit(df.OWNRENT, df[['intercept', 'AGE', 'INCOME']])
result = model.fit()
result.summary()
Issue: File - statsmodels\discrete\discrete_model.py Function - llr_pvalue(self)
This returns - stats.chisqprob(self.llr, self.df_model) But the function stats.chisqprob is depricated as of statsmodel 1.7 (https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.chisqprob.html) and should be replaced with stats.distributions.chi2.sf
Ouput of sm.show_versions()
INSTALLED VERSIONS
------------------
Python: 3.5.3.final.0
Statsmodels
===========
Installed: 0.8.0 (c:\program files (x86)\python35-64\lib\site-packages\statsmodels)
Required Dependencies
=====================
cython: Not installed
numpy: 1.13.1 (c:\program files (x86)\python35-64\lib\site-packages\numpy)
scipy: 1.0.0b1 (c:\program files (x86)\python35-64\lib\site-packages\scipy)
pandas: 0.20.3 (c:\program files (x86)\python35-64\lib\site-packages\pandas)
dateutil: 2.6.1 (c:\program files (x86)\python35-64\lib\site-packages\dateutil)
patsy: 0.4.1 (c:\program files (x86)\python35-64\lib\site-packages\patsy
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 16 (3 by maintainers)
Links to this issue
Commits related to this issue
- BUG: Remove deprecated scipy function Remove deprecated chisqprob in favor of stats.distributions.chi2.sf closes #3931 — committed to bashtage/statsmodels by bashtage 7 years ago
- BUG: Remove deprecated scipy function Remove deprecated chisqprob in favor of stats.distributions.chi2.sf closes #3931 — committed to tupui/statsmodels by bashtage 7 years ago
Running into this issue myself now. In case it wasn’t immediately obvious to anyone else, the workaround for this specific issue with missing function
chisqprobis@NaderNazemi This will not be fixed (reverted) in scipy (given also the existence of a simple workaround). It is our fault that we missed this and that we are slow with a new release.
However, there is a simple workaround by assigning the missing function back into the scipy.stats namespace as shown above, i.e.
results.summary2() will work
instead of downgrading scipy, it’s better to upgrade statsmodels. statsmodels 0.9 has the compatibility fixes
Thanks for checking and reporting. I didn’t know we still use those functions. Based on a file search it is the only use of
chisqprob, but there are a few more removed distribution function.Note this is in DiscreteResults so it will cause errors in all discrete models, i.e all
summarywill be “dead”.@srivathsadv Did you run the statsmodels test suite with scipy 1.0 candidate? Are there other errors?
workaround is to assign the missing function to scipy.stats