Closed
Labels
Description
https://github.com/statsmodels/statsmodels/blob/master/statsmodels/genmod/families/family.py#L372
Should the deviance function of the poisson distribution have the term - (endog - mu) added inside the sum, cf. function resid_dev? If the model does not contain an intercept term np.sum(endog - mu) might not be zero.
return 2 * np.sum(freq_weights * (endog * np.log(endog_mu) - (endog - mu))) / scale
Activity
josef-pkt commentedon Jan 4, 2017
Yes, looks like a bug to me for the no-intercept case. (I'm adding corner-case label to signal that this bug only affects "uncommon" use cases.)
We don't use deviance in any optimization, so redundant calculation doesn't make much difference in performance.
thequackdaddy commentedon Jan 5, 2017
I think I was the culprit who introduced this when I added
freq_weights.For my education, can one of you 2 explain this problem further? I was always under the impression that when you fit a poisson model
np.sum(endog - mu)approaches zero. I'm aware this behavior is specific to Poisson (or maybe more specifically to the related variance function).Additionally, what is the exact drawback of having
np.sum(endog - mu) != 0? Does this bias some statistical test (only Chi2 comes to mind as something that relies on deviance)?Thanks!
josef-pkt commentedon Jan 5, 2017
@thequackdaddy
It is or can be nonzero if no constant and no implicit constant is included.
It is a property of all GLM/LEF models, including OLS that the sum of residuals is zero if a constant is included.
edit Most likely it's true only for canonical links. I didn't check the math for non-canonical links but I guess it would be a weighted average instead of sum.
However, we don't rule out the case that a user specifies a model without a constant. In the OLS case this would correspond to a regression through the zero point.
The match between sum(endog) and sum(fittedvalues) also occurs for subgroups with categorical dummy variables, e.g. in contingency tables.
josef-pkt commentedon Jan 5, 2017
related when I looked at this recently for Logit
https://mail.python.org/pipermail/scikit-learn/2016-December/001010.html
When the constant is penalized, then it cannot force
sum(endog) = sum(fittedvalues).josef-pkt commentedon Feb 4, 2017
This is an old behavior, the term is missing also in 0.6, and not related to freq_weights addition
BUG: missing term in family Poisson deviance closes statsmodels#3355
BUG: missing term in family Poisson deviance closes statsmodels#3355