R/chi2Test.R

Defines functions chi2Test

Documented in chi2Test

#' Chi-squared Test
#'
#' Performs the chi-squared test with or without Yates's continuity
#' correction to a collection of 2 x 2 tables of the form
#' \tabular{lcc}{
#'    \tab event \tab not event\cr
#'   drug \tab `a` \tab `c`\cr
#'   not drug \tab `b` \tab `d`
#' }
#' 
#' @note The standard warnings for when the counts are too low 
#' in the 2 x 2 tables are suppressed. Due to the sparse nature 
#' of spontaneous reporting data, this happens quite frequently.
#'
#' @template standardParams
#' @param yates If `TRUE`, Yates's correction is used
#'
#' @return p-value
#' @export
chi2Test <- function(a, b, c, d, yates = FALSE) {
  mapply(
    function(a, b, c, d) {
      suppressWarnings(chisq.test(createTable(a, b, c, d), correct = yates)$p.value)
    },
    a, b, c, d
  )
}
bips-hb/pvm documentation built on Feb. 13, 2025, 3:32 a.m.