You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ENH: option to disable GLM Perfect Separation exception #2680
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
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.
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.
"""
Activity
josef-pkt commentedon Apr 18, 2017
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 exceptionbump and adding bug label
josef-pkt commentedon Jan 28, 2018
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.
josef-pkt commentedon Jan 24, 2020
bump
https://stackoverflow.com/questions/59902037/perfect-separation-on-linear-model
josef-pkt commentedon Dec 2, 2022
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.summaryIn 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.