R/or.table.R

Defines functions or.table

Documented in or.table

or.table <- function(x, y, weights = NULL, na.rm = FALSE, na.value = "NAs", digits = 3) {
  t0 <- weighted.table(x, y, weights, stat = "freq", mar = FALSE, na.rm = na.rm, na.value = na.value)
  OR <- t0
  for(i in 1:nrow(t0)) {
    for(j in 1:ncol(t0)) {
      a <- t0[i,j]
      b <- rowSums(t0)[i] - a
      c <- colSums(t0)[j] - a
      d <- sum(t0) - (a+b+c)
      OR[i,j] <- (a*d) / (b*c)
    }
  }
  if(!is.null(digits)) OR <- round(OR,digits)
  return(OR)
}

Try the descriptio package in your browser

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

descriptio documentation built on June 8, 2025, 10:50 a.m.