-
Notifications
You must be signed in to change notification settings - Fork 115
add residuals method for GLM #499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
8625214
30a77ab
92660be
ca6342b
66325eb
ffd7c97
d8e0434
e90aad8
9480b0c
613f5fe
476fc6f
dd491b5
5be6314
b58c3bd
3cb863e
cfa33e0
ee87fc7
dfa5f15
781ecd1
8eb70a8
c8b69b6
ae0b680
88345d6
f55713a
64eda0b
6bd8980
3445319
fe6800b
282e321
904e158
1a1cbeb
d90bab5
e9865be
c3fbc4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -731,3 +731,37 @@ function checky(y, d::Binomial) | |
| end | ||
| return nothing | ||
| end | ||
|
|
||
| # need to add :pearson | ||
| const _RESIDUAL_TYPES = [:deviance, :response, :working] | ||
|
|
||
| """ | ||
| residuals(model::GeneralizedLinearModel; type=:deviance) | ||
|
|
||
| Return the residuals of a GLM. | ||
|
|
||
| Supported residual types are: | ||
| - `:response`: the difference between the observed and fitted values | ||
| - `:deviance`: the signed square root of the elementwise | ||
| contribution to the deviance | ||
| - `:working`: working residuals (used during the IRLS process) | ||
|
palday marked this conversation as resolved.
Outdated
palday marked this conversation as resolved.
|
||
| """ | ||
| function residuals(model::GeneralizedLinearModel; type=:deviance) | ||
| type in _RESIDUAL_TYPES || | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use the |
||
| throw(ArgumentError("Unsupported type `$(type)``; supported types are" * | ||
| "$(_RESIDUAL_TYPES)")) | ||
| # TODO: add in optimized method for normal with identity linnk | ||
|
palday marked this conversation as resolved.
Outdated
|
||
| res = if type == :response | ||
| response(model) - fitted(model) | ||
| elseif type == :deviance | ||
|
andreasnoack marked this conversation as resolved.
Outdated
|
||
| # XXX I think this might be the same as | ||
| # 2 * wrkresid, but I'm not 100% sure if that holds across families | ||
|
Comment on lines
+867
to
+868
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dmbates Does this relationship hold across families?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you use the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it seems that that function is lower level and used in the computation of the associated field rather returning said field. |
||
| sign.(response(model) .- fitted(model)) .* sqrt.(model.rr.devresid) | ||
| elseif type == :working | ||
| return model.rr.wrkresid | ||
| else | ||
| error("An error has occurred. Please file an issue on GitHub.") | ||
| end | ||
|
|
||
| return res | ||
|
palday marked this conversation as resolved.
Outdated
|
||
| end | ||
|
palday marked this conversation as resolved.
|
||
Uh oh!
There was an error while loading. Please reload this page.