dev first guess returns nan for Poisson family GLM
Bug #603306 reported by
amcmorl
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
statsmodels |
Fix Committed
|
Undecided
|
Unassigned |
Bug Description
Poisson famiy GLM fit to data with 0s in endog variable fails with error:
"ValueError: The first guess on the deviance function returned a nan. This could be a boundary problem and should be reported."
Problem can be reproduced with following code:
import numpy as np
import scikits.statsmodels as sm
size = 1e5
nbeta = 3
beta = np.random.
x = np.random.
y = np.random.
fam = sm.families.
glm = sm.GLM(y,x, family=fam)
res = glm.fit()
If family=fam is left out of GLM constructor, then glm.fit() works as expected.
Changed in statsmodels: | |
status: | New → Fix Committed |
To post a comment you must log in.
family. Poisson. deviance has (Y*np.log(Y/mu)) which is nan for Y=0 which is a valid value for Poisson
a solution:
set 0*np.log(0) = 0 using for example numpy.where
(I'm surprised this wasn't caught by any tests)