Repository navigation
fix(means_ratio): use addition in Lajeunesse (2015) Eq. 5 variance adjustment - #722
Merged
mattansb merged 2 commits intoNov 29, 2026
Merged
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
There are no active review issues for the small-sample variance adjustment correction.
No open issues 🎉
What changed in this PR
Corrects the small-sample variance adjustment in means_ratio(..., adjust = TRUE) to match Lajeunesse (2015, Eq. 5), making the variance symmetric when groups are swapped.
Changes:
- Adds both groups’ fourth-order variance terms instead of subtracting the second.
- Adds regression checks for symmetric variance, reciprocal confidence intervals, and agreement with Eq. 5.
- Updates existing adjusted confidence interval expectations.
| File | Description |
|---|---|
| tests/testthat/test-rom.R | Adds symmetry and formula regression tests; updates adjusted confidence interval expectations. |
| R/means_ratio.R | Corrects the sign in the small-sample variance adjustment. |
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
In
.logrom_calc()(R/means_ratio.R:235), the small-sample variance adjustment term (Jvar) formeans_ratio(..., adjust = TRUE)currently subtracts the second group's fourth-order term instead of adding it:In Lajeunesse (2015, Ecology, Eq. 5), the bias-corrected variance estimator is symmetric in the two groups and adds both terms:
Because of the minus sign,
var_romis not invariant to swappingxandy, someans_ratio(x, y, adjust = TRUE)andmeans_ratio(y, x, adjust = TRUE)produce non-reciprocal confidence intervals, and the adjustment underestimates sampling variance whenever group 2's squared coefficient of variation term exceeds group 1's.Proposed Changes
R/means_ratio.R: change-to+inJvarinside.logrom_calc().tests/testthat/test-rom.R:var_romand reciprocal CIs formeans_ratio(x, y, adjust = TRUE)vsmeans_ratio(y, x, adjust = TRUE), plus exact agreement with Lajeunesse (2015, Eq. 5).mtcarsswapped CIs andsleeppaired CIs) that previously pinned values computed with the-sign; updated values were verified directly against Lajeunesse (2015, Eq. 5).Minimal Reproducible Example
main):means_ratio(x, y, adjust = TRUE):1.31 [0.82, 2.10](var_rom = 0.0577)means_ratio(y, x, adjust = TRUE):0.76 [0.47, 1.23](var_rom = 0.0590; reciprocal ofCI_highis0.8132 != 0.8174)means_ratio(x, y, adjust = TRUE):1.31 [0.81, 2.11](var_rom = 0.0593)means_ratio(y, x, adjust = TRUE):0.76 [0.47, 1.23](var_rom = 0.0593; exact reciprocals to1e-12)Verification
testthat::test_file("tests/testthat/test-rom.R"): 39/39 passed.R/means_ratio.R): 5 failures intest-rom.R; restoringR/means_ratio.Rreturns to 39/39 passed.air formatand checked withlintr(0 lints).This PR was assisted by Gemini 4 Neon via Antigravity CLI; I have reviewed and verified the change.