Skip to content

BUG: predict in ZeroInflated fails if exog_infl not specified #4757

Closed

Description

@josef-pkt

https://stackoverflow.com/questions/50999793/zeroinflatedpoisson-model-in-python/51003782#51003782

As far as I can see:

If there are no explanatory variables, exog_infl, specified for the inflation model, then a array of ones is used to model a constant inflation probability. However, if exog_infl in predict is None, then it uses the model.exog_infl which is an array of ones with the length equal to the training sample.

As work around specifying a 1-D array of ones of correct length in predict should work.

clf.predict(test_x, exog_infl=np.ones(len(test_x))

I guess the same problem will occur if exposure was used in the model, but is not explicitly specified in predict.

Activity

  1. added this to the 0.10 milestone on Jun 23, 2018
  2. modified the milestones: 0.10, 0.12 on Jul 31, 2020
  3. modified the milestones: 0.12, 0.13 on Aug 11, 2020
  4. josef-pkt commented on Jul 14, 2021

    @josef-pkt
    MemberAuthor

    same problem shows up in Beta regression and will apply to all multi-part models #7543 (comment)

  5. josef-pkt commented on Jul 14, 2021

    @josef-pkt
    MemberAuthor

    #4952 mentions that exog_infl has to be 2-d

    beta regression also defaults to 2-d constant exog_precision = np.ones((len(endog), 1), dtype='f')

    We might want to automatically add the 2-d axis if user specifies a 1-d exog_xxx

  6. josef-pkt commented on Aug 24, 2021

    @josef-pkt
    MemberAuthor

    while trying to fix this, I get test failures with offset exposure. (not directly related to exog_infl)

    Looks like there is something wrong, but I don't yet see why test fails
    https://github.com/statsmodels/statsmodels/blob/main/statsmodels/discrete/tests/test_count_model.py#L147
    compares self.res1 predict (using offset) with itself, instead of res3 which is supposed to be the equivalent exposure version.

    but self.res1 predict() is not the same as res3.predict()

  7. josef-pkt commented on Aug 24, 2021

    @josef-pkt
    MemberAuthor

    offset and exposure are not treated the same by default in predict if they are None.
    https://github.com/statsmodels/statsmodels/blob/main/statsmodels/discrete/count_model.py#L396
    if None: offset = 0, exposure = self.exposure

    discrete_model.CountModel uses a copied version of GLM.predict (minus link check)
    GenericZeroInflated.predict uses it's own predict method, but does not follow the same pattern of checks.

    Note
    exog is None means we have default predict with self.exog. exog is required if not default
    In ZI, we have to additionally treat exog_infl, and similarly in Beta regression.

    another messy part for ZI:
    we have submodel `model_main that also has offset or exposure attached.
    Offset should be fine, but we have to watch out that exposure is not transformed twice. (still side effect that exposure is internally log-ed.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions