Learn R Programming

mosaic (version 0.8-18)

oddsRatio: Odds Ratio for 2X2 Contingency Tables

Description

This function calculates the odds ratio for a 2 X 2 contingency table and a confidence interval (default conf.level is 95 percent) for the estimated odds ratio. x should be a matrix, data frame or table. "Successes" should be located in column 1 of x, and the treatment of interest should be located in row 2. The odds ratio is calculated as (Odds row 2) / (Odds row 1). The confidence interval is calculated from the log(OR) and backtransformed.

Usage

oddsRatio(x, conf.level = 0.95)

## S3 method for class 'oddsRatio': print(x, digits = 4, ...)

Arguments

x
a 2 X 2 matrix, data frame or table of counts
conf.level
the confidence interval level
digits
number of digits to display
...
additional arguments

Value

  • p1, p2Proportions for rows 1 and 2
  • o1, o2Odds for rows 1 and 2
  • OROdds ratio
  • lowerthe lower bound of the confidence interval
  • upperthe upper bound of the confidence interval
  • conf.levelthe confidence interval level

See Also

chisq.test

Examples

Run this code
M1 <- matrix(c(14, 38, 51, 11), nrow = 2)
M1
oddsRatio(M1)

M2 <- matrix(c(18515, 18496, 1427, 1438), nrow = 2)
rownames(M2) <- c("Placebo", "Aspirin")
colnames(M2) <- c("No", "Yes")
M2
oddsRatio(M2)

Run the code above in your browser using DataLab