Repository navigation
Scale dev_gamma() by shape so deviance residuals have unit scaling (#170) - #171
Merged
Merged
Conversation
dev_gamma() omitted shape from the unit deviance, leaving res_gamma(type = "dev") residuals smaller than dev_norm()/dev_student()'s by ~sqrt(shape) and unusable for a standard +/-2 screening threshold. Multiplying by shape recovers the full 2 * (log_lik_sat - log_lik_fit), consistent with the rest of the dev_*() family. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
joethorley
approved these changes
Oct 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
dev_gamma()computed the classic Gamma unit deviance,2 * [(x - mu)/mu - log(x/mu)], which omitsshapeby construction — it matchesresiduals.glm(type = "deviance"), but leavesres_gamma(type = "dev")residuals smaller thandev_norm()/dev_student()'s by a factor ofsqrt(shape), making a standard ±2 screening threshold meaningless for Gamma models.shape, recovering the full2 * (log_lik_saturated - log_lik_fitted)— consistent with how every otherdev_*()function in the package is computed, and verified independently against base R'sglm()/rstandard()machinery.test-dev.R/test-res.Raccordingly, including removing a# hack to divide multiply by 1 / shapeworkaround in a test that had already noticed this mismatch.Closes #170.
Test plan
devtools::test()— full suite passes (3455/3455)shape * 2 * (log_lik_gamma(x, shape, shape/x) - log_lik_gamma(x, shape, rate))to floating-point precisionsd(res_gamma(x, shape, rate, type = "dev")) ≈ 1, matchingdev_norm()/dev_student()'s behavior🤖 Generated with Claude Code