Skip to content

BUG: fix GLM resid_working - #3164

Merged
josef-pkt merged 1 commit into
statsmodels:masterfrom
josef-pkt:bug_glm_residworking
Aug 17, 2016
Merged

josef-pkt merged 1 commit into
statsmodels:masterfrom
josef-pkt:bug_glm_residworking

Conversation

@josef-pkt

Copy link
Copy Markdown
Member

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 do files)
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.)

@josef-pkt josef-pkt added comp-genmod backport-0.8.0 type-bug-wrong serious bugs that silently return incorrect numbers labels Aug 16, 2016
@josef-pkt josef-pkt added this to the 0.8 milestone Aug 16, 2016
@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.0008%) to 89.245% when pulling 24c6c5a on josef-pkt:bug_glm_residworking into 3116b58 on statsmodels:master.

@josef-pkt

Copy link
Copy Markdown
Member Author

@josef-pkt
josef-pkt force-pushed the bug_glm_residworking branch from 24c6c5a to 75b45d6 Compare August 16, 2016 22:37
@josef-pkt

Copy link
Copy Markdown
Member Author

amended commit to include the tweedie resid tests

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.0007%) to 89.245% when pulling 75b45d6 on josef-pkt:bug_glm_residworking into 3116b58 on statsmodels:master.

@thequackdaddy

Copy link
Copy Markdown
Member

@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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, I was thinking we didn't need _n_trials. I think resid_response is already adusted.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@josef-pkt josef-pkt Aug 17, 2016 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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))

@josef-pkt
josef-pkt merged commit 1a09acf into statsmodels:master Aug 17, 2016
@josef-pkt josef-pkt mentioned this pull request Aug 17, 2016
4 of 28 tasks
@josef-pkt
josef-pkt deleted the bug_glm_residworking branch August 17, 2016 15:16
josef-pkt added a commit to josef-pkt/statsmodels that referenced this pull request Aug 19, 2016
@TomAugspurger TomAugspurger mentioned this pull request Feb 2, 2017
2 tasks done
@jbrockmendel

Copy link
Copy Markdown
Contributor

Is the same fix supposed to apply to resid_working in GEEResults?

jbrockmendel added a commit to jbrockmendel/statsmodels that referenced this pull request May 12, 2017
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-genmod type-bug-wrong serious bugs that silently return incorrect numbers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG?: GLM working residuals

4 participants