From 32b18900fd36e874b79917fc8d57851c365d7d50 Mon Sep 17 00:00:00 2001 From: ***** <721466+soodoku@users.noreply.github.com> Date: Wed, 25 Nov 2026 04:58:33 -0800 Subject: [PATCH] fix(means_ratio): use -Inf lower bound in .limit_ci() on log scale --- R/means_ratio.R | 2 +- tests/testthat/test-rom.R | 40 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/R/means_ratio.R b/R/means_ratio.R index a68239a9..1ecbf449 100644 --- a/R/means_ratio.R +++ b/R/means_ratio.R @@ -172,7 +172,7 @@ means_ratio <- function( out[["CI_low"]] <- interval[1] out[["CI_high"]] <- interval[2] - out <- .limit_ci(out, alternative, 0, Inf) + out <- .limit_ci(out, alternative, -Inf, Inf) } else { ci_method <- alternative <- NULL } diff --git a/tests/testthat/test-rom.R b/tests/testthat/test-rom.R index 741bc2b1..bd05e48e 100644 --- a/tests/testthat/test-rom.R +++ b/tests/testthat/test-rom.R @@ -127,3 +127,43 @@ test_that("means_ratio paired - not adjusted", { expect_equal(x$CI_low, .651, tolerance = 0.001) expect_equal(x$CI_high, 0.865, tolerance = 0.001) }) + +test_that("means_ratio - one-sided CI lower bound on ratio and log scales", { + r_less <- means_ratio( + iris$Sepal.Length, + iris$Sepal.Width, + alternative = "less" + ) + expect_identical(r_less$CI_low, 0) + + r_less_log <- means_ratio( + iris$Sepal.Length, + iris$Sepal.Width, + alternative = "less", + log = TRUE + ) + expect_identical(r_less_log$CI_low, -Inf) + + r_less_small <- means_ratio( + iris$Sepal.Width, + iris$Sepal.Length, + alternative = "less" + ) + expect_identical(r_less_small$CI_low, 0) + expect_lt(r_less_small$CI_low, r_less_small$CI_high) + + r_greater <- means_ratio( + iris$Sepal.Length, + iris$Sepal.Width, + alternative = "greater" + ) + expect_identical(r_greater$CI_high, Inf) + + r_greater_log <- means_ratio( + iris$Sepal.Length, + iris$Sepal.Width, + alternative = "greater", + log = TRUE + ) + expect_identical(r_greater_log$CI_high, Inf) +})