Skip to content

BUG/ENH: poisson deviance #3355

Closed
Closed

Description

@lorentzenchr

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

  1. added
    type-bug-wrong
    on Jan 4, 2017
  2. josef-pkt commented on Jan 4, 2017

    @josef-pkt
    Member

    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.

  3. thequackdaddy commented on Jan 5, 2017

    @thequackdaddy
    Member

    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!

  4. josef-pkt commented on Jan 5, 2017

    @josef-pkt
    Member

    @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.

  5. josef-pkt commented on Jan 5, 2017

    @josef-pkt
    Member

    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).

  6. josef-pkt commented on Feb 4, 2017

    @josef-pkt
    Member

    This is an old behavior, the term is missing also in 0.6, and not related to freq_weights addition

  7. added a commit that references this issue on Feb 4, 2017
    9ca6fed
  8. added a commit that references this issue on Feb 11, 2017
    dca7e3a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    comp-genmodcorner-casetype-bug-wrong

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions