Add Mantel-Fleiss criterion function mantel_fleiss_crit(). - #1513
Add Mantel-Fleiss criterion function mantel_fleiss_crit().#1513wwojciech wants to merge 15 commits into
Conversation
|
@danielinteractive - I was wondering whether I should introduce an Do you think having an |
danielinteractive
left a comment
There was a problem hiding this comment.
Thanks @wwojciech , please see few comments below - otherwise looks nice.
I don't think we need na.rm argument when the other functions which are used together with this don't have it.
|
@danielinteractive - I am now thinking that it would probably be better to change the UI to Most (if not all) of the |
|
@wwojciech yeah starting from the table is probably a good idea |
|
Thank you @danielinteractive for your review. I’ve updated the code to address all of your suggestions and changed the UI as discussed. Please review the PR again when you have a chance. Thanks! |
|
@danielinteractive - do you think this below little helper should go to #' @param rsp (`logical`)\cr
#' A logical vector indicating whether each observation is a responder.
#' @param grp (`factor`)\cr
#' A factor assigning observations to one of two groups (e.g., reference
#' and treatment). It must have exactly two levels.
#' @param strata (`factor`)\cr
#' Factor defining the stratification variable. Each unique
#' stratum defines a separate 2 x 2 contingency table.
safe_2x2_strat_table <- function(rsp, grp, strata) {
checkmate::assert_logical(rsp, any.missing = FALSE)
checkmate::assert_factor(grp, len = length(rsp), any.missing = FALSE, n.levels = 2)
checkmate::assert_factor(strata, len = length(rsp), any.missing = FALSE)
# Make rsp a factor to handle cases with only TRUE or only FALSE.
rsp <- factor(rsp, levels = c("TRUE", "FALSE"))
table(grp, rsp, strata)
} |
|
Thanks @wwojciech yeah to |
|
Thank you @danielinteractive . |
|
@wwojciech do you still need to write this CLA comment thing? |
Thanks @danielinteractive , I am not sure about it? Do I have to do this? I thought this is will be disabled - see this PR #1508 (my previous PRs were merged with the CLA check failing). What do you think? |
|
@wwojciech ah yes now that |
|
Looks good to me @wwojciech . @shajoezhu @Melkiades can we merge ? |
|
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. Thanks! |
Melkiades
left a comment
There was a problem hiding this comment.
The function itself is fine, math checks out and tests are solid. My blocker is the same as before: it is exported but not used anywhere in tern. s_test_proportion_diff() still picks CMH vs Fisher purely from the method arg, it never calls this. Moving it to prop_diff.R does not fix that, the problem is integration not location.
So a decision is needed: is this an internal helper that drives method selection, or a public function users call themselves?
- internal: drop @export, use the h_ prefix, and call it from s_test_proportion_diff(). This also settles the value/crit attribute thread, no need for it if it is internal.
- public: keep it exported but the examples must show the full tern workflow that builds the tbl, not just table() on random data. Otherwise users have no way to know when or how to use it.
Until one of those is done I do not think this should go in.
|
Thank you @Melkiades for your review and valuable comments. I completely agree with your concerns. Here are my thoughts regarding them:
Many thanks again! |
Melkiades
left a comment
There was a problem hiding this comment.
Thanks for this. The stats side is clear and I am happy to have the criterion available, the issue is purely how it connects into tern.
Right now mantel_fleiss_crit() is exported but nothing calls it, no table or analysis function uses it, and no test reaches it through any tern mechanism. The documentation describes it in isolation, unconnected to anything in the package.
Two options:
- Wire it into the prop diff test path and add a test plus examples that show it in the context where it is actually used, with @Seealso pointing to those functions.
- If it is a standalone utility, say so, move it to its own utils file, and document it as such. If it really is meant to stand alone, a short vignette showcasing when and how to use it would make it discoverable.
Naming should state the action too: check_mantel_fleiss() reads better than mantel_fleiss_crit().
I would rather we solve this here than defer to a follow-up issue. We are trying not to leave orphan functions that get forgotten and unmaintained, so let us land it properly connected in this PR.
|
Hi @Melkiades Thanks for the detailed feedback. I understand the concern about not introducing an exported function that is disconnected from the rest of However, I think that integration is beyond the scope of what I can reasonably take on in this PR. I am not a tern developer (anymore), and while I was happy to contribute the Mantel-Fleiss criterion and make the necessary minimal changes around it, I don't have the time to refactor the relevant analysis/test paths and add the broader integration, examples, and tests you are asking for. I have already invested quite a bit of time in this PR, so rather than extending its scope substantially, I think the best solution is to close it and implement the Mantel-Fleiss criterion in the package I support, where I can maintain and use it directly. I appreciate the review and understand the rationale behind the request. I just don't think I can take on the additional @danielinteractive - FYI. |
Fixes #1512