Skip to content

BUG/ENH: fit_constrained with GLM-Binomial #4600

Closed

Description

@josef-pkt

consequence of #4599 Binomial with counts stores transformed endog.

fit_constrained with GLM-Binomial counts is most likely incorrect.

current unit tests

  • genmod/tests/test_constrained Gaussian only (added to fix scale handling for cov_params)
  • discrete/tests/test_constrained Poisson and Logit for both discrete models and GLM
    (uses GLM-Binomial with binary endog.)

Activity

  1. added
    type-bug-wrong
    on May 7, 2018
  2. added this to the 0.10 milestone on May 7, 2018
  3. josef-pkt commented on May 7, 2018

    @josef-pkt
    MemberAuthor

    same for GLM fit_regularized which has unit tests only for binary Binomial case, and Poisson

  4. josef-pkt commented on May 7, 2018

    @josef-pkt
    MemberAuthor

    It looks like fit_constrained works correctly after #4601
    (I'm working in penalized branch with 4601 added)

    Trying an example with dropping some exog and compare to fit_constrained

    based on test case with star98 dataset

    keep_idx = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 20])
    drop_idx = np.array([15, 16, 17, 18, 19])
    ​
    exog_dropped = data.exog[:, keep_idx]
    res_dropped = GLM(data.endog, exog_dropped, \
               family=families.Binomial(),
               offset=offset).fit()
    
    constraints = np.eye(k)[drop_idx]
    res_constrained = res1.model.fit_constrained(constraints)
    
    res_constrained.params[keep_idx] - res_dropped.params
    array([ -2.74086309e-16,   8.15320034e-17,   3.46944695e-17,
             9.88792381e-17,   5.20417043e-16,  -4.75314232e-15,
            -1.28716482e-15,   2.99760217e-15,   6.99093561e-16,
            -7.80625564e-18,   1.99493200e-17,   6.41847686e-17,
             6.46184495e-17,  -1.45283091e-17,   1.16443313e-16,
             5.26245714e-14])
    
    for attr in ['llf', 'null_deviance', 'aic', 'bic', 'df_resid', 'df_model', 'pearson_chi2', 'scale']:
        print(attr, getattr(res_constrained, attr) - getattr(res_dropped, attr) )
    llf 9.09494701773e-13
    null_deviance 0.0
    aic -1.81898940355e-12
    bic -9.09494701773e-12
    df_resid 0
    df_model 0
    pearson_chi2 -1.45519152284e-11
    scale 0.0
    
  5. josef-pkt commented on Jan 1, 2019

    @josef-pkt
    MemberAuthor

    check and close as fixed (which it looks like it is based on the previous comment above)

  6. bashtage commented on May 3, 2019

    @bashtage
    Member

    @josef-pkt Do you think this issue has been fixed?

  7. bashtage commented on Jul 30, 2026

    @bashtage
    Member

    Fixed by PR #4601 (merged same day), which added n_trials to _init_keys/_get_init_kwds (statsmodels/genmod/generalized_linear_model.py) so fit_constrained on GLM-Binomial with count data correctly accounts for n_trials. A dedicated regression test (TestGLMBinomialCountConstrained, star98 dataset) confirms this today. Closing as fixed.

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-genmodtype-bugtype-bug-wrongtype-enh

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions