Repository: statsmodels/statsmodels

Issue:
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


Discussion:
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 `summary` will 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

```
>>> from scipy import stats
>>> stats.junk = lambda chisq, df: stats.chi2.sf(chisq, df)
>>> stats.junk(10, 3)
>>> 0.018566135463043251
>>> stats.chisqprob(10,3)
>>> 0.018566135463043251
```
No, I did not run the statsmodels test suite. Just used the summary function of the discrete model.
Thanks for the workaround.

Resolving patch:
diff --git a/statsmodels/discrete/discrete_model.py b/statsmodels/discrete/discrete_model.py
--- a/statsmodels/discrete/discrete_model.py
+++ b/statsmodels/discrete/discrete_model.py
@@ -3270,7 +3270,6 @@ def __init__(self, model, mlefit, cov_type='nonrobust', cov_kwds=None,
                                            **cov_kwds)
 
 
-
     def __getstate__(self):
         # remove unpicklable methods
         mle_settings = getattr(self, 'mle_settings', None)
@@ -3291,7 +3290,7 @@ def llr(self):
 
     @cache_readonly
     def llr_pvalue(self):
-        return stats.chisqprob(self.llr, self.df_model)
+        return stats.distributions.chi2.sf(self.llr, self.df_model)
 
     def set_null_options(self, llnull=None, attach_results=True, **kwds):
         """set fit options for Null (constant-only) model


Test patch: