Learn R Programming

SciencesPo (version 1.02.12)

orrr: Odds Ratio and Relative Risk for 2 x 2 Contingency Tables

Description

Calculates odds ratios, relative risk, and confidence intervals on odds ratios.

Usage

orrr(x, conf.level = 0.95, verbose = TRUE, digits = 3, relrisk = FALSE)

oddsRatio(x, conf.level = 0.95, verbose = TRUE, digits = 3)

relrisk(x, conf.level = 0.95, verbose = TRUE, digits = 3)

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

## S3 method for class 'relrisk': print(x, digits = 3, ...)

## S3 method for class 'oddsRatio': summary(object, digits = 3, ...)

## S3 method for class 'relrisk': summary(object, digits = 3, ...)

Arguments

x
a 2 X 2 matrix, data frame or table of counts
conf.level
the confidence interval level
verbose
a logical indicating whether verbose output should be displayed
digits
number of digits to display
relrisk
a logical indicating whether the relative risk should be returned instead of the odds ratio
object
an R object to print or summarise. Here an object of class "oddsRatio" or "relrisk".
...
further arguments passed to or used by other methods.

Value

  • an odds ratio or relative risk. If verpose=TRUE, more details and the confidence intervals are displayed.

encoding

UTF-8

Details

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 back transformed.

Examples

Run this code
mat <- matrix(c(100, 100, 100, 100), nrow = 2)
mat
oddsRatio(mat)

mat2 <- matrix(c(18515, 18496, 1427, 1438), nrow = 2)
rownames(mat2) <- c("Placebo", "Aspirin")
colnames(mat2) <- c("No", "Yes")
mat2
oddsRatio(mat2)
oddsRatio(mat2, verbose=FALSE)
relrisk(mat2, verbose=FALSE)
# example 2
out <- matrix(c(131,75,27, 6), nrow=2)
 rownames(out) <- c("No disease", "Have disease")
 colnames(out) <- c("<40%", ">40%")
 oddsRatio(out)

Run the code above in your browser using DataLab