Skip to content

Pass conf.level = ci to stats::binom.test() in binned_residuals() - #1018

Open
soodoku wants to merge 1 commit into
easystats:mainfrom
finite-sample:fix/binned-residuals-exact-ci
Open

soodoku wants to merge 1 commit into
easystats:mainfrom
finite-sample:fix/binned-residuals-exact-ci

Conversation

@soodoku

@soodoku soodoku commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Summary

When ci_type = "exact" (the default for Bernoulli models), binned_residuals() called stats::binom.test(sum(y0[items]), n)$conf.int without passing conf.level = ci, so the ci argument was silently ignored and exact intervals were always computed at the 95% level.

Minimal reproducible example

library(performance)

model <- glm(vs ~ wt + mpg, data = mtcars, family = "binomial")
res_95 <- binned_residuals(model, ci = 0.95, ci_type = "exact")
res_50 <- binned_residuals(model, ci = 0.50, ci_type = "exact")

identical(res_95$CI_low, res_50$CI_low)
  • Observed (before fix): TRUE — ci = 0.50 returns identical CI_low and CI_high values as ci = 0.95 (e.g., bin 1 width 0.5218 instead of 0.2400).
  • Expected: FALSE — ci = 0.50 returns narrower intervals matching stats::binom.test(..., conf.level = 0.50)$conf.int (bin 1 width 0.2400).

Fix

Pass conf.level = ci to stats::binom.test(sum(y0[items]), n, conf.level = ci) in R/binned_residuals.R.

Verification

  • Added regression test "binned_residuals, exact CI respects ci argument" in tests/testthat/test-binned_residuals.R.
  • testthat::test_file("tests/testthat/test-binned_residuals.R"): PASS 27 | FAIL 0 | WARN 0 | SKIP 2.
  • Revert-check (reverting only R/binned_residuals.R): FAIL 2 | PASS 25; restoring R/binned_residuals.R: PASS 27 | FAIL 0 | WARN 0.

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.

1 participant