Skip to content

means_ratio(): use log-scale lower bound for one-sided CIs - #727

Merged
mattansb merged 2 commits into
easystats:mainfrom
chenyangsu:fix/means-ratio-onesided-ci
Nov 29, 2026
Merged

mattansb merged 2 commits into
easystats:mainfrom
chenyangsu:fix/means-ratio-onesided-ci

Conversation

@chenyangsu

Copy link
Copy Markdown
Contributor

Description

means_ratio(c(1, 2, 3), c(4, 5, 6), alternative = "less") returns Means_ratio_adjusted = 0.41 with 95% CI [1.00, 0.70], and with log = TRUE returns -0.88 with 95% CI [0.00, -0.36]. .limit_ci(out, alternative, 0, Inf) runs while out is on the log scale, setting CI_low = 0 (exp(0) = 1 on the ratio scale), whereas the log response ratio has support (-Inf, Inf) (matching oddsratio()'s [0, Inf) ratio-scale / (-Inf, Inf) log-scale convention).

Proposed Changes

Pass -Inf as the lower bound to .limit_ci() on the log scale in R/means_ratio.R so CI_low is -Inf for log = TRUE and exp(-Inf) = 0 for log = FALSE, and add regression tests in tests/testthat/test-rom-ci.R. Happy to fold the test into test-rom.R instead if you prefer.

Testing: testthat::test_local(".", filter = "rom") passes (47 passed, 0 failed; test-rom-ci.R has 6 failures on main).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

There are no active review issues for the one-sided confidence-interval correction in means_ratio().

No open issues 🎉

What changed in this PR

Fixes one-sided confidence intervals in means_ratio() by applying the lower bound on the log scale, consistent with the package’s ratio-scale conventions.

Changes:

  • Uses -Inf as the log-scale lower bound, producing 0 on the ratio scale for alternative = "less".
  • Adds regression tests for one-sided bounds on both scales and scale consistency for ratios above one.
File Description
tests/​testthat/​test-rom-ci.R Adds regression coverage for one-sided bounds and log/ratio-scale consistency.
R/​means_ratio.R Corrects the lower bound passed to .limit_ci() from 0 to -Inf.

Review effort: Balanced

@mattansb
mattansb merged commit bc983aa into easystats:main Nov 29, 2026
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.

3 participants