Repository navigation
means_ratio(): use log-scale lower bound for one-sided CIs - #727
Merged
Merged
Conversation
There was a problem hiding this comment.
🟢 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
-Infas the log-scale lower bound, producing0on the ratio scale foralternative = "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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
means_ratio(c(1, 2, 3), c(4, 5, 6), alternative = "less")returnsMeans_ratio_adjusted = 0.41with 95% CI[1.00, 0.70], and withlog = TRUEreturns-0.88with 95% CI[0.00, -0.36]..limit_ci(out, alternative, 0, Inf)runs whileoutis on the log scale, settingCI_low = 0(exp(0) = 1on the ratio scale), whereas the log response ratio has support(-Inf, Inf)(matchingoddsratio()'s[0, Inf)ratio-scale /(-Inf, Inf)log-scale convention).Proposed Changes
Pass
-Infas the lower bound to.limit_ci()on the log scale inR/means_ratio.RsoCI_lowis-Infforlog = TRUEandexp(-Inf) = 0forlog = FALSE, and add regression tests intests/testthat/test-rom-ci.R. Happy to fold the test intotest-rom.Rinstead if you prefer.Testing:
testthat::test_local(".", filter = "rom")passes (47 passed, 0 failed;test-rom-ci.Rhas 6 failures onmain).