Skip to content

Fix unconditional exact proportion intervals for tied tables - #1541

Closed
Arthur031221 wants to merge 2 commits into
pharmaverse:mainfrom
Arthur031221:1539_include_tied_tables
Closed

Arthur031221 wants to merge 2 commits into
pharmaverse:mainfrom
Arthur031221:1539_include_tied_tables

Conversation

@Arthur031221

Copy link
Copy Markdown

Fixes #1539

Users of prop_diff_uncond_exact() could get confidence intervals that were too narrow because floating point rounding excluded mathematically tied tables from the tails. Add a 1e-9 tolerance to include those ties.

Builds on @wwojciech's patch and regression table.

Added tests for the reported table and tail membership. Rscript -e 'testthat::test_local(filter = "prop_diff")' passes.

Co-authored-by: Wojtek 11532997+wwojciech@users.noreply.github.com

Apply the tolerance proposed in issue 1539 and cover its example in
both group orders and tail directions.

Co-authored-by: Wojtek <11532997+wwojciech@users.noreply.github.com>
Signed-off-by: Arthur031221 <levi74108520963@gmail.com>
@wwojciech
wwojciech self-requested a review October 4, 2026 08:15
@wwojciech wwojciech added the bug Something isn't working label Oct 4, 2026
@wwojciech

Copy link
Copy Markdown
Contributor

Hi @Arthur031221 !

Thank you for preparing the PR for this.

I think it would be better not to hard-code this tolerance, but instead pass it as an additional argument to worst_case_tail_probability(), e.g. tol = 1e-9. This would make the tolerance explicit and configurable to account for finite-precision arithmetic. It should of course also be exposed in prop_diff_uncond_exact().

Then:

include_table <- if (tail == "upper") {
  t_values >= (t0 - tol)
} else {
  t_values <= (t0 + tol)
}

@danielinteractive - FYI. Please also have a look and let me know if this approach is okay, or if there is a better way of handling this that I may not be aware of. Thanks!

@Arthur031221

Copy link
Copy Markdown
Author

I tested your tol = 1e-9 argument in both functions, and the proportion difference tests pass with new custom and zero tolerance cases in both tails. The PR branch is unchanged pending @danielinteractive's input on the API change.

@wwojciech wwojciech left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Introduce new tol argument for the respective functions.

Co-authored-by: Wojtek <11532997+wwojciech@users.noreply.github.com>
Signed-off-by: Arthur031221 <levi74108520963@gmail.com>
@Arthur031221

Copy link
Copy Markdown
Author

Added tol = 1e-9 to prop_diff_uncond_exact() and h_worst_case_tail_probability() and used it for both tail comparisons. Proportion difference tests pass for custom and zero tolerances and invalid inputs.

@danielinteractive

Copy link
Copy Markdown
Collaborator

I found a fix which does not need a tolerance at all. Preparing a separate PR for that now.

@wwojciech

Copy link
Copy Markdown
Contributor

I found a fix which does not need a tolerance at all. Preparing a separate PR for that now.

Ooo, that is amazing, I am very curios about it :)

@wwojciech wwojciech removed the bug Something isn't working label Oct 4, 2026
@wwojciech

wwojciech commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Hi @Arthur031221 , I noticed that @danielinteractive opened a separate PR to address this issue - #1542
Since Daniel is an author of these functions, lets handle this issue within the PR #1542 and close this one if you do not mind.
Thanks!

@Arthur031221

Copy link
Copy Markdown
Author

Agreed, let's continue in #1542. I'll close this PR. Thanks!

@danielinteractive

Copy link
Copy Markdown
Collaborator

Why do I have the feeling that this was kind of a "robot" generated PR?... 😄

@wwojciech

Copy link
Copy Markdown
Contributor

Why do I have the feeling that this was kind of a "robot" generated PR?... 😄

I had a similar feeling, although I wasn’t sure about it. It would be quite disappointing if that were actually the case.

@shajoezhu - could you please shed some light on what’s happening here? I’d be genuinely disappointed if this was indeed generated by a bot. I’ve spent quite a bit of time and effort reviewing and discussing this, and I’d hate to find out that I was essentially talking to a bot rather than a person.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Discrepancy between SAS and prop_diff_uncond_exact()

3 participants