set.seed(123)
n <- 40
grp <- factor(sample(c("Active", "Control"), n, replace = TRUE))
rsp <- sample(c(TRUE, FALSE), n, replace = TRUE)
strata1 <- factor(sample(c("A", "B"), n, replace = TRUE))
strata2 <- factor(sample(c("x", "y"), n, replace = TRUE))
strata <- interaction(strata1, strata2)
tbl <- table(grp, rsp, strata)
tbl
is_mf_satisfied <- mantel_fleiss_crit(tbl)
is_mf_satisfied
mantel_fleiss_crit(tbl, include_value = TRUE)
# Examples of use.
if (is_mf_satisfied) {
print("CMH")
prop_diff_cmh(rsp, grp, strata)$prop
} else {
print("Exact")
prop_diff_uncond_exact(rsp, grp)$prop
}
if (is_mf_satisfied) {
print("CMH")
prop_cmh(tbl)
} else {
print("Exact")
prop_fisher(table(grp, rsp))
}
Run the code above in your browser using DataLab