Skip to content

ENH: option to disable GLM Perfect Separation exception #2680

Closed

Description

@josef-pkt

I want to estimate a saturated model for loglinear analysis, but I get an PerfectSeparation error for Poisson.

It looks like GLM doesn't have an option to disable Perfect Separation exception an to turn it into a warning.

Activity

  1. added this to the 0.8 milestone on Oct 29, 2015
  2. modified the milestones: 0.8, 0.9 on Aug 10, 2016
  3. josef-pkt commented on Apr 18, 2017

    @josef-pkt
    MemberAuthor

    I ran into this again for a one-way poisson example with unique exog and exposure,
    However, exception is only raised in irls, using method='bfgs' avoids the exception

    bump and adding bug label

  4. josef-pkt commented on Jan 28, 2018

    @josef-pkt
    MemberAuthor

    related: discrete has an attribute option to disable the exception, but there is no option to warn instead of the exception, i.e. we need also a PerfectSeparationWarning

    also instead of an attribute we should have a keyword option to choose what to do in the case of perfect separation.

    aside: there should be another related issue about using the perfect separation callback in non-binary models like the count models.

  5. modified the milestones: 0.9, 0.10 on Jan 28, 2018
  6. modified the milestones: 0.10, 0.12 on Jan 24, 2020
  7. modified the milestones: 0.12, 0.13 on Aug 11, 2020
  8. modified the milestones: 0.13, 0.14 on Dec 2, 2022
  9. josef-pkt commented on Dec 2, 2022

    @josef-pkt
    MemberAuthor

    I will just convert this to a Warning.
    The user can set Warning to "error", but I will default to just warn

    problems with test in discrete if I switch to warning instead of error:

    example has convergence failure with default optimizer (newton)
    When I switch to "bfgs", then it converges, but the PerfectSeparationWarning is not issued.
    However, with have an extra text in the summary (I didn't remember adding this). The warning is added in BinaryResults.summary
    In this example all standard errors are huge, so it's clear that params are not (well) identified.
    Also, even the old code does not raise PerfectSeparationError when method="bfgs". So the check is not loose enough to catch this case.

    > ...\statsmodels\statsmodels\discrete\tests\test_discrete.py(1576)test_perfect_prediction()
    -> res = mod.fit(method="bfgs", disp=False, maxiter=50)  # should not raise but should warn
    (Pdb) p res.mle_retvals['converged']
    True
    (Pdb) res.resid.var()
    *** AttributeError: 'LogitResults' object has no attribute 'resid'
    (Pdb) res.resid_response.var()
    1.1297028686877065e-10
    (Pdb) res.resid_response.mean()
    1.1228335390697837e-06
    (Pdb) res.summary()
    <class 'statsmodels.iolib.summary.Summary'>
    """
                               Logit Regression Results
    ==============================================================================
    Dep. Variable:                      y   No. Observations:                  100
    Model:                          Logit   Df Residuals:                       95
    Method:                           MLE   Df Model:                            4
    Date:                Fri, 02 Dec 2022   Pseudo R-squ.:                   1.000
    Time:                        10:27:32   Log-Likelihood:            -0.00011486
    converged:                       True   LL-Null:                       -69.315
    Covariance Type:            nonrobust   LLR p-value:                 5.547e-29
    ==============================================================================
                     coef    std err          z      P>|z|      [0.025      0.975]
    ------------------------------------------------------------------------------
    const         -1.5110   5157.716     -0.000      1.000   -1.01e+04    1.01e+04
    x1            -2.4487   1725.063     -0.001      0.999   -3383.510    3378.612
    x2            -8.4204   2017.738     -0.004      0.997   -3963.114    3946.273
    x3            12.7030   1318.984      0.010      0.992   -2572.458    2597.864
    x4             5.5326   1986.007      0.003      0.998   -3886.971    3898.036
    ==============================================================================
    
    Possibly complete quasi-separation: A fraction 0.99 of observations can be
    perfectly predicted. This might indicate that there is complete
    quasi-separation. In this case some parameters will not be identified.
    """
    
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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions