Repository navigation
BUG: fix GLM resid_working - #3164
Conversation
|
there is another test for tweedie that can be activated to test resid_working |
24c6c5a to
75b45d6
Compare
|
amended commit to include the tweedie resid tests |
|
@josef-pkt This looks great, Josef. Very clever just to "fix" the incorrect values from stata tests instead of re-calculating and saving them. The idea of re-doing all of the stata results is what stopped me from this. Thanks a bunch. |
| # Isn't self.resid_response is already adjusted by _n_trials? | ||
| val = (self.resid_response / self.family.link.deriv(self.mu)) | ||
| val = (self.resid_response * self.family.link.deriv(self.mu)) | ||
| val *= self._n_trials |
There was a problem hiding this comment.
Wait, I was thinking we didn't need _n_trials. I think resid_response is already adusted.
There was a problem hiding this comment.
I assume this is only for Binomial. I didn't look into it.
GLMBinomial has a unit test, that passes
The main problem I had in getting the test to run was with offset or exposure because I had made a mistake in rewriting the tests, but that also seems to work fine. There are some problems hiding in the test suite compared to Stata because some of the individual required test precisions are quite low. But that's independent of correcting the working residuals.
There was a problem hiding this comment.
self.mu in binomial is in terms of fraction or probability.
resid_response is in counts (taking n_trials into account)
So, I guess the multiplication by _n_trials is to adjust the self.family.link.deriv(self.mu))
BUG: fix GLM resid_working
|
Is the same fix supposed to apply to |
The definitions of `resid_working` in [GEE](https://github.com/statsmodels/statsmodels/blob/master/statsmodels/genmod/generalized_estimating_equations.py#L1472) and [GLM](https://github.com/statsmodels/statsmodels/blob/master/statsmodels/genmod/generalized_linear_model.py#L1318) are _almost_ identical. statsmodels#3164 changed the version in GLM from division to multiplication. This PR just applies the exact same change to the GEE version. Note that at the moment, the GEE version is not getting hit in tests.
closes #2891
GLM resid_working is calculated incorrectly
I didn't try to run the test examples in Stata. (that's a lot of work without ready made
dofiles)I corrected the reference numbers, and activated the tests that has correct Stata numbers in test_glm_weights.
(One-character bug fix with several hours of figuring out the unit tests.)