R/test_fisher.R

Defines functions test_fisher

Documented in test_fisher

#' Fisher's Test
#'
#' @param data data
#' @param x x
#' @param y y
#' @importFrom dplyr summarise
#' @importFrom stats fisher.test
#' @return results
#' @export
#' @examples
#' design = c("A","B")
#' complete = c(11, 5)
#' incomplete = c(1, 5)
#' data <- data.frame(design, complete, incomplete)
#' data <- data |> tidyr::pivot_longer(!design, names_to = "rate", values_to = "n") |>
#'   tidyr::uncount(n)
#' test_fisher(data, design, rate)


test_fisher <- function(data, x, y) {

  table <- summarise(data, tab = list(table({{x}}, {{y}})))$tab[[1]]

  result <- fisher.test(table)

  as_tibble(data.frame(p_value = result$p.value,
             odds_ratio = unname(result$estimate)
             ))
}

Try the uxr package in your browser

Any scripts or data that you put into this service are public.

uxr documentation built on Dec. 28, 2022, 2:03 a.m.