Solves #1535: Refactored prop_diff_cmh() and its helper functions - #1538
Conversation
…s helper functions to address the issue.
|
Hi @munoztd0 - would it be possible to run the |
|
For reviewers (@danielinteractive , @Melkiades ). Please specifically check the test "test_proportion_diff edge case: all responder by CMH with Sato variance estimator" in I’m also open to changing this to Let me know what do you think. |
danielinteractive
left a comment
There was a problem hiding this comment.
Thanks @wwojciech , please see comments below.
General recommendation: not everywhere where we divide something by a variable we have to first check whether that thing is positive etc. We can leave such things in many cases to the R functions, which usually do a good job with infinite, NaN etc. Sometimes we need to do something manually, but not all the time. Otherwise it becomes too hard to read and maintain.
Thank you @danielinteractive for the review and for raising this point. I agree that we don't need to explicitly check for undefined expressions everywhere, and we should absolutely avoid cluttering the code where R's defaults work well.
I will update the code to handle this cleanly and address the other comments inline. Let me know if that sounds like a fair compromise. |
|
@wwojciech yeah for those cases with integer counts I agree it might make sometimes more sense to use |
Sure, thanks @danielinteractive. Let me update the code and remove the explicit handling where it’s unnecessary. |
Melkiades
left a comment
There was a problem hiding this comment.
Dear @wwojciech, thanks for the addition. As far as I could understand from the issue, this was meant to be a bug fix, while I see major refactoring. Please consider dividing this in 2 PRs, one with the bug fix, and the other with the refactoring. For example, the change of order and function names should be in a separate PR as it makes difficult to read the PR. Also remember that if it is exported you need the deprecation cycle
Thank you @Melkiades for quick comment. Yeah, if we want to solve this bug completely and in a good, permanent way, some refactoring is required (although I wouldn’t call it major refactoring). Otherwise, we would end up with a quick fix that might not be reliable in the long term. So I decided to address the issue properly rather than just patching the immediate symptom. Also, once I started fixing this bug properly, it exposed a few related issues that needed to be addressed as well, which is why the scope of the changes grew. Honestly, though, I don’t see a straightforward way to split this into separate PRs at this point, as the changes are quite interconnected. If reviewing the PR would take significant time because of the amount of changes, I’m happy to leave it until after the P.S. I didn’t change the names of any exported functions, only internal ones. Please let me know what do you think. |
here you go insightsengineering/scda.test#260 |
danielinteractive
left a comment
There was a problem hiding this comment.
Looks good to me, thanks @wwojciech. @Melkiades agree that this is a bigger PR than expected from the issue description, but there is almost no change to the user interface/behavior here (the p-value being NA instead of 1 for the empty data case being the only exception) so I would vouch for merging it nevertheless
prop_diff_cmh() and it helper functionsprop_diff_cmh() and its helper functions
|
Thank you @danielinteractive ! @Melkiades , @shajoezhu - would you be willing to merge this PR before the release? |
Melkiades
left a comment
There was a problem hiding this comment.
Thanks a lot for this, really nice work, and thanks for the patience during the review. Given how connected the fix is, no need to split it.
I pushed a small commit on top:
uniroot_catch_na()checks forNAat the interval ends instead of matching theuniroot()error message. That message is translated in non-English R sessions (e.g. German or French), so theNAcase was erroring there.- NEWS moved under 0.9.12 and lists the user-facing changes.
- A small test checking that strata with only one group don't change the
prop_diff_cmh()results. - A few doc typos.
Approving, good to merge once CI is green.
Thank you very much indeed @Melkiades - this is a great news!. Many thanks again for helping with this! |
Fixed #1535
Summary of the main changes
h_diff_cmh():h_prop_cmh().diff_estfrom the output list so that this function is concerned only with proportions and their inference.h_diff_cmh_se():h_cmh_sato_var().prop_diff_cmh().h_miettinen_nurminen_var_est():h_miettinen_nurminen_var().h_miettinen_nurminen_stratified_ci():prop_diff_cmh().prop_cmh():h_cmh_sato_var().Added
uniroot_catch_na().