Skip to content

fix(means_ratio): use -Inf lower bound in .limit_ci() on log scale - #723

Closed
soodoku wants to merge 1 commit into
easystats:mainfrom
finite-sample:fix/means-ratio-onesided-ci
Closed

soodoku wants to merge 1 commit into
easystats:mainfrom
finite-sample:fix/means-ratio-onesided-ci

Conversation

@soodoku

@soodoku soodoku commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Description

In means_ratio() (R/means_ratio.R:175), .limit_ci() is called while out is still on the log scale (before if (!log) exponentiates the estimate and CI bounds on lines 180–186), but it passes 0 as the lower limit:

out <- .limit_ci(out, alternative, 0, Inf)

For alternative = "less", this fixes CI_low to 0 on the log scale:

  • When log = TRUE, CI_low is 0 instead of -Inf (and produces an inverted interval when the log means ratio is negative).
  • When log = FALSE, exp(0) = 1 sets CI_low to 1 instead of 0 (and produces an inverted interval whenever the means ratio is < 1).

Proposed Changes

  • R/means_ratio.R: change .limit_ci(out, alternative, 0, Inf) to .limit_ci(out, alternative, -Inf, Inf) so CI_low is -Inf on the log scale and exp(-Inf) = 0 on the ratio scale.
  • tests/testthat/test-rom.R: add a regression test covering alternative = "less" and alternative = "greater" for both log = FALSE and log = TRUE, including a ratio < 1.

Minimal Reproducible Example

means_ratio(iris$Sepal.Width, iris$Sepal.Length, alternative = "less")
means_ratio(iris$Sepal.Width, iris$Sepal.Length, alternative = "less", log = TRUE)
  • Before (main):
    • log = FALSE: 0.52 | [1.00, 0.54] (inverted; CI_low = 1 > CI_high)
    • log = TRUE: -0.65 | [0.00, -0.62] (inverted; CI_low = 0 > CI_high)
  • After (this PR):
    • log = FALSE: 0.52 | [0.00, 0.54] (CI_low = 0)
    • log = TRUE: -0.65 | [-Inf, -0.62] (CI_low = -Inf)

Verification

  • testthat::test_file("tests/testthat/test-rom.R"): 40/40 passed.
  • Revert check (reverting only R/means_ratio.R): 4 failures in test-rom.R; restoring R/means_ratio.R returns to 40/40 passed.
  • Formatted with air format and checked with lintr (0 lints).

This PR was assisted by Gemini 4 Neon via Antigravity CLI; I have reviewed and verified the change.

@mattansb

Copy link
Copy Markdown
Member

Please submit this PR with #722

@mattansb mattansb closed this Nov 25, 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.

2 participants