Skip to content

Add Mantel-Fleiss criterion function mantel_fleiss_crit(). - #1513

Open
wwojciech wants to merge 9 commits into
pharmaverse:mainfrom
wwojciech:1512_add_Mantel_Fleiss_criterion
Open

Add Mantel-Fleiss criterion function mantel_fleiss_crit().#1513
wwojciech wants to merge 9 commits into
pharmaverse:mainfrom
wwojciech:1512_add_Mantel_Fleiss_criterion

Conversation

@wwojciech

@wwojciech wwojciech commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Fixes #1512

@wwojciech

Copy link
Copy Markdown
Contributor Author

@danielinteractive - I was wondering whether I should introduce an na.rm = FALSE parameter and allow missing values. Currently, I want to be consistent with the other tern prop_*() functions, which expect no missing values.

Do you think having an na.rm argument and allowing missing values would be useful?

@danielinteractive danielinteractive left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Comment thread R/prop_diff_test.R Outdated
Comment thread R/prop_diff_test.R Outdated
Comment thread R/prop_diff_test.R Outdated
@wwojciech

wwojciech commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

@danielinteractive - I am now thinking that it would probably be better to change the UI to tbl (contingency table), instead of grp, rsp, and strata, and introduce a separate helper to reliably build tbl from these three vectors.

Most (if not all) of the prop_* test functions (prop_cmh(), prop_fisher(), ...) already require tbl, so I would need to create such a table anyway, since after checking the MF criterion I need to run the test.

@danielinteractive

Copy link
Copy Markdown
Collaborator

@wwojciech yeah starting from the table is probably a good idea

@wwojciech

Copy link
Copy Markdown
Contributor Author

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!

@wwojciech

wwojciech commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

@danielinteractive - do you think this below little helper should go to {tern} or to {junco}? I would probably say {tern}...

#' @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)
}

@danielinteractive

Copy link
Copy Markdown
Collaborator

Thanks @wwojciech yeah to tern because there it can be used in multiple places

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.

[Feature Request]: Implement the Mantel-Fleiss Criterion

2 participants