R/oddsratioWald.R

Defines functions oddsratioWald

Documented in oddsratioWald

##..................................................................................
## data analysis
##..................................................................................
### odds ratio
# http://www.r-bloggers.com/computing-odds-ratios-in-r/
#' @title FUNCTION_TITLE
#' @description FUNCTION_DESCRIPTION
#' @param n00 PARAM_DESCRIPTION
#' @param n01 PARAM_DESCRIPTION
#' @param n10 PARAM_DESCRIPTION
#' @param n11 PARAM_DESCRIPTION
#' @param alpha PARAM_DESCRIPTION, Default: 0.05
#' @return OUTPUT_DESCRIPTION
#' @details DETAILS
#' @examples 
#' \dontrun{
#' if(interactive()){
#'  #EXAMPLE1
#'  }
#' }
#' @rdname oddsratioWald
#' @export 
oddsratioWald <- function(n00, n01, n10, n11, alpha = 0.05){
  #
  #  Compute the odds ratio between two binary variables, x and y,
  #  as defined by the four numbers nij:
  #
  #    n00 = number of cases where x = 0 and y = 0
  #    n01 = number of cases where x = 0 and y = 1
  #    n10 = number of cases where x = 1 and y = 0
  #    n11 = number of cases where x = 1 and y = 1
  #
  OR <- (n00 * n11)/(n01 * n10)
  #
  #  Compute the Wald confidence intervals (1-alpha)%CI):
  #
  siglog <- sqrt((1/n00) + (1/n01) + (1/n10) + (1/n11))
  zalph <- stats::qnorm(1 - alpha/2)
  logOR <- log(OR)
  loglo <- logOR - zalph * siglog
  loghi <- logOR + zalph * siglog
  #
  ORlo <- exp(loglo)
  ORhi <- exp(loghi)
  #
  oframe <- data.frame(LowerCI = ORlo, OR = OR, UpperCI = ORhi, alpha = alpha)
  oframe
}
holgerman/toolboxH documentation built on June 25, 2022, 2:42 p.m.