# NOT RUN {
add_p_ex1 <-
trial %>%
dplyr::select(age, grade, response, trt) %>%
tbl_summary(by = trt) %>%
add_p()
# }
# NOT RUN {
# Conduct a custom McNemar test for response,
# Function must return a named list(p = 0.05, test = "McNemar's test")
# Function names begins with 'add_p_test.' and ends with the alias
add_p_test.mcnemar <- function(data, variable, by, ...) {
result <- list()
result$p <- stats::mcnemar.test(data[[variable]], data[[by]])$p.value
result$test <- "McNemar's test"
result
}
add_p_ex2 <-
trial[c("response", "trt")] %>%
tbl_summary(by = trt) %>%
add_p(test = vars(response) ~ "mcnemar")
# }
Run the code above in your browser using DataLab