Skip to content

Warn for non-Bernoulli binomial models in r2_tjur(), r2_somers(), r2_efron() and r2_mckelvey() - #957

Open
jmgirard wants to merge 1 commit into
mainfrom
hotfix-aggregated-binomial-r2
Open

jmgirard wants to merge 1 commit into
mainfrom
hotfix-aggregated-binomial-r2

Conversation

@jmgirard

Copy link
Copy Markdown
Contributor

r2(), r2_nagelkerke(), r2_coxsnell() and r2_mcfadden() already warn and return NULL for 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 a cbind() response:

Function Bernoulli Proportion + weights cbind()
r2_tjur() 0.273 0.299 0.299
r2_efron() 0.273 1 NA (base R warning)
r2_mckelvey() 0.312 0.035 0.035
r2_somers() 0.571 NA error: "The names you entered for x and y are not available"

(Same mtcars model, am ~ factor(cyl), fit three ways.)

This PR adds the same guard and warning text to these four functions. For r2_efron() and r2_mckelvey(), the guard applies only to binomial models, so other families are not affected.

  • New tests in tests/testthat/test-r2_binomial_aggregated.R: each function warns and returns NULL for both aggregated forms, stays silent with the expected value for the Bernoulli model, and r2_efron() stays silent for a Poisson model. The tests fail without the fix.
  • NEWS entry and version bump to 0.18.2.5.

A correct R2 for aggregated binomial models (the lchoose() log-likelihood idea in the issue) is not part of this PR.

Fixes #165

…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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 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.R and R/r2_mckelvey.R should 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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Warnings for binomial stats using frequency format

2 participants