Repository navigation
Closed
Description
Similarly to #3533, I have a non-convergence on the null-model. The Poisson converges, while the NB2 no. Isn't it strange? (naive question)
features = ['pp']
df = pd.read_csv('bug.csv').head(10)
X = (df[features])# - df[features].mean())/df[features].std()
y = df['num'].values
X_sm = sm.add_constant(X[features].copy())
model = sm.Poisson(y, X_sm, ) #
res = model.fit(maxiter=1000, method='minimize', min_method='dogleg', disp=0)
print(res.summary())
Results to
Poisson Regression Results
==============================================================================
Dep. Variable: y No. Observations: 10
Model: Poisson Df Residuals: 8
Method: MLE Df Model: 1
Date: Fri, 24 Mar 2017 Pseudo R-squ.: 0.2763
Time: 16:17:50 Log-Likelihood: -4818.7
converged: True LL-Null: -6658.0
LLR p-value: 0.000
==============================================================================
coef std err z P>|z| [0.025 0.975]
------------------------------------------------------------------------------
const 6.9949 0.012 563.378 0.000 6.971 7.019
pp 1.34e-05 2.06e-07 65.023 0.000 1.3e-05 1.38e-05
==============================================================================
Warning:
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/statsmodels-0.8.0-py3.4-macosx-10.6-intel.egg/statsmodels/discrete/discrete_model.py:956: RuntimeWarning: overflow encountered in exp
return np.sum(-np.exp(XB) + endog*XB - gammaln(endog+1))
With NB2
model = sm.NegativeBinomial(y, X_sm, )
start = res.params.append(pd.Series(0.5, index=['alpha']))
res = model.fit(maxiter=2000, start_params=start, method='nm')
print(res.summary())
Result
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/statsmodels-0.8.0-py3.4-macosx-10.6-intel.egg/statsmodels/discrete/discrete_model.py:901: RuntimeWarning: overflow encountered in exp
return stats.poisson.cdf(y, np.exp(X))
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/statsmodels-0.8.0-py3.4-macosx-10.6-intel.egg/statsmodels/discrete/discrete_model.py:1172: RuntimeWarning: overflow encountered in exp
L = np.exp(np.dot(X,params) + exposure + offset)
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/statsmodels-0.8.0-py3.4-macosx-10.6-intel.egg/statsmodels/discrete/discrete_model.py:1112: RuntimeWarning: overflow encountered in exp
L = np.exp(np.dot(X,params) + offset + exposure)
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/scipy/stats/_discrete_distns.py:451: RuntimeWarning: invalid value encountered in greater_equal
return mu >= 0
Optimization terminated successfully.
Current function value: 8.303326
Iterations: 85
Function evaluations: 151
NegativeBinomial Regression Results
==============================================================================
Dep. Variable: y No. Observations: 10
Model: NegativeBinomial Df Residuals: 8
Method: MLE Df Model: 1
Date: Fri, 24 Mar 2017 Pseudo R-squ.: nan
Time: 16:17:51 Log-Likelihood: -83.033
converged: True LL-Null: nan
LLR p-value: nan
==============================================================================
coef std err z P>|z| [0.025 0.975]
------------------------------------------------------------------------------
const 6.6414 0.458 14.496 0.000 5.743 7.539
pp 2.209e-05 1.13e-05 1.960 0.050 -4.46e-09 4.42e-05
alpha 0.4835 0.202 2.399 0.016 0.088 0.878
==============================================================================
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/statsmodels-0.8.0-py3.4-macosx-10.6-intel.egg/statsmodels/base/model.py:481: HessianInversionWarning: Inverting hessian failed, no bse or cov_params available
'available', HessianInversionWarning)
Data here:
bug.csv.zip
thx
Metadata
Metadata
Assignees
Labels
No labels
Activity
josef-pkt commentedon Sep 22, 2017
this was supposed to be closed by #3921 but I had a typo in commit message