Add new (helper) functions for proportions that prepares safe 2x2 cont. tables(s). - #1515
Conversation
…fe_2x2_table(). Modfified check_diff_prop_ci() so that is uses new assert_prop_data().
|
Hi @danielinteractive , can you review this PR please? Thank you! |
danielinteractive
left a comment
There was a problem hiding this comment.
Thanks @wwojciech , please see first comments re: exporting
Thank you @danielinteractive . Corrected as you suggested. |
|
@wwojciech ok from my side, @Melkiades looks good to you too? |
|
Hi @Melkiades , @shajoezhu Please let me know if you think any further changes/clarifications are required for this PR. Your feedback is greatly appreciated, as this PR is a dependency for some new functions in our package, and development of those functions is currently on hold due to the missing functionality. @Melkiades - Maybe it is better to place Thanks! |
assert_prop_data() and safe_2x2_table().assert_proportion_data() and safe_2x2_table().
The 0.9.11 heading was placed above the unreleased g_forest() entries (pharmaverse#1499, pharmaverse#1498), which pushed them into the already-released 0.9.11 section. Move the heading below those entries so they stay under the 0.9.11.9000 development version, and the released 0.9.11 section starts at the df_explicit_na() entry (pharmaverse#1322) that shipped in the release.
There was a problem hiding this comment.
Thanks for this!!! the helpers are clean and the test coverage is excellent (empty data, single-outcome, unobserved levels, unused strata levels, sparse tables are all covered).
One substantive point plus a few minor issues, left inline. The main thing: issue #1514 frames this as removing duplication across s_test_proportion_diff(), prop_cmh(), prop_fisher(), etc., but as it stands safe_2x2_table() isn't applied at any of those call sites and the same factor(rsp, levels=c("TRUE","FALSE")) + switch(table(...)) logic is still duplicated inline in s_test_proportion_diff(). Could we wire that call site over in this PR?
I also pushed a small fix to NEWS.md: the # tern 0.9.11 heading had landed above the unreleased g_forest() entries (#1499/#1498), which moved them into the already-released 0.9.11 section. I moved the heading below them so they stay under 0.9.11.9000. Feel free to squash/adjust.
Thank you very much @Melkiades, for the detailed review. I’ve updated the code according to your suggestions. I only kept the Please let me know if you have any further suggestions or would like me to make any additional changes to this PR. |
|
Hi @Melkiades , @shajoezhu Apologies for the reminder, but significant functionality in the package I’m working on depends on this PR, and we have the package release coming up very soon. I’ve already written a substantial amount of the code on top of this, so I’d really appreciate it if we could merge this as soon as possible to avoid any delays with the release. Please let me know if there’s anything you’d like me to add or change, or if we’re good to merge it. Thanks! |
Signed-off-by: Wojtek <11532997+wwojciech@users.noreply.github.com>
|
Hi @munoztd0 , I think it would be reasonable to check on the |
|
Thank you, @Melkiades! I renamed the variables according to your suggestion. Please let me know if there’s anything else that needs to be done before this PR can be merged. Thanks! |
|
Created a scda.test branch with this new feature branch to check on snapshot tests -> https://github.com/insightsengineering/scda.test/actions/runs/34983541222 (had to tweak a little bit the version dependencies and fork WW branch to make it work nicely in scda.test but everything else is exactly the same in terms of code) |
Thank you very much indeed @munoztd0 for checking this. This is great! |
munoztd0
left a comment
There was a problem hiding this comment.
Passed all scda.test snapshot tests
|
hi @munoztd0 , can you share the link of the PR that you created for this, so we can track it. thanks |
|
I am reviewing this. Let me get back at you today @wwojciech @munoztd0 |
There was a problem hiding this comment.
@wwojciech This is a clear improvement on what was there. Centralising the 2x2 construction in h_prepare_2x2_table() fixes a real latent bug (the old factor(c(.ref_group[[.var]], df[[.var]]), levels = c("TRUE", "FALSE")) silently produced all NA when .var was a factor), adding cmh_sato to the strata-required set closes another gap, and the 21 tests on the new helper cover more than the code they replace. No existing snapshot moved, which is good evidence the numbers are preserved.
Requesting changes on a few things that change behaviour silently or will fail CI. None of them are design problems.
- Unstratified method plus
stratanow errors where it used to be silently ignored. Right call, but it is a behaviour change and needs its own NEWS entry. variables$weights_methodis silently dropped, so anyone on the old spelling gets different numbers with no error.- Strata columns must now be factors. Character strata used to work.
.in_ref_col = NULLsilently returns an empty result instead of erroring._pkgdown.ymllists theassertionstopic twice, which will fail the pkgdown build.- The duplicated
@param stratadropsassert_proportion_data()'s own documentation.
Two smaller ones worth folding in while you are here:
valis not a formal ofestimate_proportion_diff()ortest_proportion_diff(), so the new feature is only reachable through.... Most users never calls_*()directly.expect_error(..., "strat")matches almost any error in this area.expect_snapshot(..., error = TRUE)would lock the real message.
Details inline.
…tion_diff() and related helpers.
Hi @Melkiades , Thank you for your review. I’ve implemented all of your suggestions, except for the one regarding For the minor 2 comments:
Please let me know if there is anything else that needs to be addressed before this PR can be merged. Many thanks! |
Signed-off-by: Wojtek <11532997+wwojciech@users.noreply.github.com>
Melkiades
left a comment
There was a problem hiding this comment.
All six points addressed, thanks for turning it around quickly. Re-ran the affected suites on your branch, all green.
Two non-blocking leftovers noted inline: subset.of over set_equal for the variables guard, plus the same guard in s_test_proportion_diff(), and a doc line noting val reaches the layout functions through .... Happy for those to be a follow-up.
Nice work on h_prepare_2x2_table(), it fixes a real latent bug.
Thank you. I commented on why Thank you for reviewing it. |
Sorry I didn't do a PR just ran the actions before. Here is the clean all green PR -> insightsengineering/scda.test#253 |
that's fine. thanks so much. i added you to the repo |
Fixes #1514
What was done:
get_complete_cases()(removes observations containing missing values) as a prerequisite forh_prepare_2x2_table(),assert_proportion_data()as an assertion used inh_prepare_2x2_table(),assert_stratification_compatibility()as an assertion used ins_proportion_diff()ands_test_proportion_diff().s_proportion_diff(),s_test_proportion_diff(),so that they use the new functions
h_prepare_2x2_table()andassert_stratification_compatibility(),check_diff_prop_ci()so that is uses newassert_proportion_data().weights_methodargument not used ins_proportion_diff(). #1521.