Repository navigation
Conversation
…elvey() for non-Bernoulli binomial models These functions returned inaccurate values or failed with an unclear error for a proportion response with weights or a cbind() response. They now use the same warning as r2(), r2_nagelkerke(), r2_coxsnell() and r2_mcfadden(). Fixes #165
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
Exclude beta-binomial models from the Efron and McKelvey guards.
0 open findings
What changed in this PR
This PR adds warnings and NULL returns for non-Bernoulli binomial models across four R² measures.
Changes:
- Added guards to Tjur, Somers, Efron, and McKelvey R² functions.
- Added regression tests for aggregated and Bernoulli models.
- Updated NEWS and bumped the development version.
Review findings:
R/r2_efron.RandR/r2_mckelvey.Rshould exclude beta-binomial models from the new guards.
| File | Reviewed change |
|---|---|
tests/testthat/test-r2_binomial_aggregated.R |
Tests warnings, NULL results, and unaffected models. |
R/r2_tjur.R |
Guards non-Bernoulli binomial models. |
R/r2_somers.R |
Guards non-Bernoulli binomial models. |
R/r2_mckelvey.R |
Adds a binomial-specific guard. |
R/r2_efron.R |
Adds a binomial-specific guard. |
NEWS.md |
Documents the behavior change. |
DESCRIPTION |
Bumps the development version. |
🧠 Review effort: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This branch has not been deployed
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.
r2(),r2_nagelkerke(),r2_coxsnell()andr2_mcfadden()already warn and returnNULLfor binomial models that are not Bernoulli models (#275). Four other R2 functions did not, and gave wrong values or unclear errors for a proportion response with weights or acbind()response:cbind()r2_tjur()r2_efron()NA(base R warning)r2_mckelvey()r2_somers()NA(Same
mtcarsmodel,am ~ factor(cyl), fit three ways.)This PR adds the same guard and warning text to these four functions. For
r2_efron()andr2_mckelvey(), the guard applies only to binomial models, so other families are not affected.tests/testthat/test-r2_binomial_aggregated.R: each function warns and returnsNULLfor both aggregated forms, stays silent with the expected value for the Bernoulli model, andr2_efron()stays silent for a Poisson model. The tests fail without the fix.A correct R2 for aggregated binomial models (the
lchoose()log-likelihood idea in the issue) is not part of this PR.Fixes #165