Skip to content

fix(r_to_oddsratio): forward n1 and n2 to r_to_d() - #725

Merged
mattansb merged 2 commits into
easystats:mainfrom
finite-sample:fix/r-to-oddsratio-n1-n2
Nov 29, 2026
Merged

mattansb merged 2 commits into
easystats:mainfrom
finite-sample:fix/r-to-oddsratio-n1-n2

Conversation

@soodoku

@soodoku soodoku commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Description

In r_to_oddsratio() (R/convert_between_d_to_r.R:138), the group sizes n1 and n2 are currently passed to d_to_oddsratio() (which absorbs them in ... and ignores them) instead of to r_to_d():

r_to_oddsratio <- function(r, n1, n2, log = FALSE, ...) {
  d_to_oddsratio(r_to_d(r), log = log, n1, n2)
}

As a result, n1 and n2 are silently ignored by both r_to_oddsratio() and r_to_logoddsratio(), which always fall back to the equal-group-size approximation (h = 4), breaking round-trip consistency with oddsratio_to_r(..., n1, n2) and d_to_oddsratio(r_to_d(r, n1, n2)).

Proposed Changes

  • R/convert_between_d_to_r.R: pass n1 and n2 to r_to_d(r, n1, n2) inside r_to_oddsratio(). Because r_to_logoddsratio() delegates directly to r_to_oddsratio(r, n1, n2, log = log), both functions are fixed.
  • tests/testthat/test-convert_between.R: add regression tests verifying r_to_oddsratio() and r_to_logoddsratio() with unequal n1/n2, single-argument n1/n2, and round-trip consistency with oddsratio_to_r().

Minimal Reproducible Example

r_to_oddsratio(0.5, n1 = 10, n2 = 40)
r_to_logoddsratio(0.5, n1 = 10, n2 = 40)
d_to_oddsratio(r_to_d(0.5, n1 = 10, n2 = 40))
  • Before (main):
    • r_to_oddsratio(0.5, n1 = 10, n2 = 40): 8.120527 (identical to r_to_oddsratio(0.5))
    • r_to_logoddsratio(0.5, n1 = 10, n2 = 40): 2.094395
  • After (this PR):
    • r_to_oddsratio(0.5, n1 = 10, n2 = 40): 13.00195 (matches d_to_oddsratio(r_to_d(0.5, 10, 40)))
    • r_to_logoddsratio(0.5, n1 = 10, n2 = 40): 2.5651 (matches d_to_logoddsratio(r_to_d(0.5, 10, 40)))

Verification

  • testthat::test_file("tests/testthat/test-convert_between.R"): 68/68 passed (1 CRAN skip).
  • Revert check (reverting only R/convert_between_d_to_r.R): 3 failures in test-convert_between.R; restoring R/convert_between_d_to_r.R returns to 68/68 passed.
  • Formatted with air format and checked with lintr (0 lints on R/convert_between_d_to_r.R, 0 new lints on test-convert_between.R).

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

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

No active review issues remain for the group-size forwarding fix.

No open issues 🎉

What changed in this PR

Fixes correlation-to-odds-ratio conversion by forwarding group sizes to r_to_d(), so unequal group sizes are respected by both r_to_oddsratio() and r_to_logoddsratio().

Changes:

  • Passes n1 and n2 to r_to_d() instead of d_to_oddsratio().
  • Adds regression tests for unequal group sizes, single-group-size arguments, and round-trip consistency.
File Description
tests/​testthat/​test-convert_between.R Adds regression coverage for group-size forwarding and conversion consistency.
R/​convert_between_d_to_r.R Corrects group-size forwarding in r_to_oddsratio().

Review effort: Balanced

@mattansb
mattansb merged commit c06329c into easystats:main Nov 29, 2026
17 of 25 checks passed
@codecov

codecov Bot commented Nov 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.04%. Comparing base (86f6003) to head (85706c7).
⚠️ Report is 10 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #725      +/-   ##
==========================================
- Coverage   90.75%   89.04%   -1.71%     
==========================================
  Files          59       59              
  Lines        4488     4491       +3     
==========================================
- Hits         4073     3999      -74     
- Misses        415      492      +77     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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