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
Thanks for finding this, Josef. That's probably my doing. I agree with your other comment about our test case suite, although huge, has some pretty gaping holes. GLM binomial is a little different because it has its own bespoke "weight"-like thing, ntrials.
While I tried to make it as generic as possible, I also got confused because there is overlap with with ntrials, var_weights, and freq_weights. It might make sense to assume/require that the user is either allowed to use ntrials or freq_weigths/var_weights, but not both.
I'm not sure what to do with Binomial counts. There are too many special case handling for it in the current code, and it has been neglected as a standard model for unit testing (including by myself).
The user doesn't use n_trials directly, but is allowed to specify endog as (successes, failures), except that I added n_trials now to kwargs for internal use.
Some idea:
just fix bugs and add more unit tests (immediate approach)
use var_weights internally instead of n_trials once var_weights has stabilized and a bit battle tested
split BinomialCount from Binomial as separate family and keep endog as counts (similar to Poisson), avoids confusing endog as count versus endog as proportion.
drop (successes, failures) as permitted endog, but allow proportion with n_trials or var_weights similar to R. (this is what I use now for replicating a model)
related: we also have exposure as possible equivalent of n_trials if we generalize exposure, which is again almost or essentially equivalent to what we can do with var_weights.
It looks like there is also a bug in the hessian with observed=True
from a failing log-binomial test case with n_trials=10:
there are convergence problem with bfgs, but if we start close to irls params, then we get to the same params as irls (at convergence tolerance)
however, hessian is not invertible, and the difference between OIM and EIM is very large especially for the second parameter which has the wrong sign on the diagonal of OIM.
log-binomial can be a difficult case to optimize, but the fittedvalues at IRLS params are between 0.3 and 0.6 and shouldn't run into problems with domain violations.
And another bug in hessian with observed=True
It looks like I'm using eimfactor twice in the tmp part,
tmp already includes eim_factor and then we multiply again with it. oim_factor = eim_factor * (1 + tmp)
I don't remember the derivation for the expressions here (of course not), but unit test pass if I replace this line with oim_factor = eim_factor * (1) + tmp
edit this change should be correct
based on collecting terms in the SPSS algorithm documentation, which I also did initially for hessian factor
this reminds me:
There was a problem comparing hessian between GLM Binomial with probit link and discrete.Probit where agreement was not very high compared to other cases.
AFAIR, that was the only non-canonical link that I had checked when I wrote hessian_factor.
I don't remember for which unit test that was.
discrete/tests/test_sandwich_cov.py has a disabled test T_estGLMProbit(CheckDiscreteGLM): but based on the comment because of the link and not because of hessian.
discrete/tests/test_constrained.py compares discrete and GLM but only Poisson and Logit.
I think your OIM looks like SPSS manual.
The problem with the computation that I used is that I collected terms, i.e. some part of the messy last term is the same as the score factor the other part is eim taking out some duplicates.
But the bug is that I used the eim part twice.
bugfix now in PR #4620
Activity
thequackdaddy commentedon May 9, 2018
Thanks for finding this, Josef. That's probably my doing. I agree with your other comment about our test case suite, although huge, has some pretty gaping holes. GLM binomial is a little different because it has its own bespoke "weight"-like thing,
ntrials.While I tried to make it as generic as possible, I also got confused because there is overlap with with
ntrials,var_weights, andfreq_weights. It might make sense to assume/require that the user is either allowed to usentrialsorfreq_weigths/var_weights, but not both.josef-pkt commentedon May 9, 2018
I'm not sure what to do with Binomial counts. There are too many special case handling for it in the current code, and it has been neglected as a standard model for unit testing (including by myself).
The user doesn't use n_trials directly, but is allowed to specify endog as (successes, failures), except that I added n_trials now to kwargs for internal use.
Some idea:
josef-pkt commentedon May 10, 2018
It looks like there is also a bug in the hessian with observed=True
from a failing log-binomial test case with n_trials=10:
there are convergence problem with bfgs, but if we start close to irls params, then we get to the same params as irls (at convergence tolerance)
however, hessian is not invertible, and the difference between OIM and EIM is very large especially for the second parameter which has the wrong sign on the diagonal of OIM.
log-binomial can be a difficult case to optimize, but the fittedvalues at IRLS params are between 0.3 and 0.6 and shouldn't run into problems with domain violations.
josef-pkt commentedon May 10, 2018
And another bug in hessian with observed=True
It looks like I'm using eimfactor twice in the tmp part,
tmp already includes eim_factor and then we multiply again with it.
oim_factor = eim_factor * (1 + tmp)I don't remember the derivation for the expressions here (of course not), but unit test pass if I replace this line with
oim_factor = eim_factor * (1) + tmpedit this change should be correct
based on collecting terms in the SPSS algorithm documentation, which I also did initially for hessian factor
josef-pkt commentedon May 10, 2018
there is still a test failure with fit_constrained but that's just that tolerance is to tight
josef-pkt commentedon May 10, 2018
this reminds me:
There was a problem comparing hessian between GLM Binomial with probit link and discrete.Probit where agreement was not very high compared to other cases.
AFAIR, that was the only non-canonical link that I had checked when I wrote hessian_factor.
I don't remember for which unit test that was.
discrete/tests/test_sandwich_cov.py has a disabled test
T_estGLMProbit(CheckDiscreteGLM):but based on the comment because of the link and not because of hessian.discrete/tests/test_constrained.py compares discrete and GLM but only Poisson and Logit.
josef-pkt commentedon May 10, 2018
https://github.com/statsmodels/statsmodels/pull/1781/files
added a CheckComparisonMixin in test_glm.py but it is used only for Logit and Poisson which are the only two cases in test_glm that overlap with discrete.
discrete test_discrete.py doesn't have any GLM comparison tests.
thequackdaddy commentedon May 11, 2018
Whoops I meant to paste this here... ignore same comment in other thread.
Also, using that PPT, I got a different calculation of the OIM from the source code.
I got something like like this...
I was able to come up with this for the OIM...
I think that math agrees with your guess that the line...
oim_factor = eim_factor * (1 + tmp)should really beoim_factor = eim_factor + tmp.Simplifying more...
josef-pkt commentedon May 11, 2018
I think your OIM looks like SPSS manual.
The problem with the computation that I used is that I collected terms, i.e. some part of the messy last term is the same as the score factor the other part is eim taking out some duplicates.
But the bug is that I used the eim part twice.
bugfix now in PR #4620