This function calculates the odds ratio and relative risk for a 2 x 2 contingency table and a confidence interval (default conf.level is 95 percent) for the each estimate. 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.

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

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

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

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

# S3 method for relrisk
print(x, digits = 4, ...)

# S3 method for oddsRatio
summary(object, digits = 4, ...)

# S3 method for relrisk
summary(object, digits = 4, ...)

## 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

quiet

a logical indicating whether verbose output should be suppressed

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".

## Value

an odds ratio or relative risk. If verpose is true, more details and the confidence intervals are displayed.

chisq.test(), fisher.test()

## Author

Kevin Middleton (kmm@csusb.edu); modified by R Pruim.

## Examples

M1 <- matrix(c(14, 38, 51, 11), nrow = 2)
M1
#>      [,1] [,2]
#> [1,]   14   51
#> [2,]   38   11
oddsRatio(M1)
#>  12.58442

M2 <- matrix(c(18515, 18496, 1427, 1438), nrow = 2)
rownames(M2) <- c("Placebo", "Aspirin")
colnames(M2) <- c("No", "Yes")
M2
#>            No  Yes
#> Placebo 18515 1427
#> Aspirin 18496 1438
oddsRatio(M2)
#>  0.9913321
oddsRatio(M2, verbose = TRUE)
#>
#> Odds Ratio
#>
#> Proportions
#> 	   Prop. 1:	 0.9284
#> 	   Prop. 2:	 0.9279
#> 	 Rel. Risk:	 0.9994
#>
#> Odds
#> 	    Odds 1:	 12.97
#> 	    Odds 2:	 12.86
#> 	Odds Ratio:	 0.9913
#>
#> 95 percent confidence interval:
#> 	 0.9939 < RR < 1.005
#> 	 0.9188 < OR < 1.07
#> NULL
#>  0.9913321
relrisk(M2, verbose = TRUE)
#>
#> Odds Ratio
#>
#> Proportions
#> 	   Prop. 1:	 0.9284
#> 	   Prop. 2:	 0.9279
#> 	 Rel. Risk:	 0.9994
#>
#> Odds
#> 	    Odds 1:	 12.97
#> 	    Odds 2:	 12.86
#> 	Odds Ratio:	 0.9913
#>
#> 95 percent confidence interval:
#> 	 0.9939 < RR < 1.005
#> 	 0.9188 < OR < 1.07
#> NULL
#>  0.9993747
if (require(mosaicData)) {
relrisk(tally(~ homeless + sex, data = HELPrct) )
do(3) * relrisk( tally( ~ homeless + shuffle(sex), data = HELPrct) )
}
#> Using parallel package.
#>   * Set seed with set.rseed().
#>   * Disable this message with options(mosaic:parallelMessage = FALSE)
#>          RR
#> 1 1.0934775
#> 2 1.0528518
#> 3 0.8098361