# oddsRatio: Odds Ratio and Relative Risk for 2 x 2 Contingency Tables In mosaic: Project MOSAIC Statistics and Mathematics Teaching Utilities

## Description

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.

## Usage

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20``` ```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 class 'oddsRatio' print(x, digits = 4, ...) ## S3 method for class 'relrisk' print(x, digits = 4, ...) ## S3 method for class 'oddsRatio' summary(object, digits = 4, ...) ## S3 method for class '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 `...` additional arguments `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.

## Author(s)

Kevin Middleton ([email protected]); modified by R Pruim.

`chisq.test()`, `fisher.test()`

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15``` ```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) oddsRatio(M2, verbose=TRUE) relrisk(M2, verbose=TRUE) if (require(mosaicData)) { relrisk(tally(~ homeless + sex, data=HELPrct) ) do(3) * relrisk( tally( ~ homeless + shuffle(sex), data=HELPrct) ) } ```

### Example output

```Loading required package: dplyr

Attaching package: 'dplyr'

The following objects are masked from 'package:stats':

filter, lag

The following objects are masked from 'package:base':

intersect, setdiff, setequal, union

New to ggformula?  Try the tutorials:
learnr::run_tutorial("introduction", package = "ggformula")
learnr::run_tutorial("refining", package = "ggformula")

The 'mosaic' package masks several functions from core packages in order to add
additional features.  The original behavior of these functions should not be affected by this.

Attaching package: 'mosaic'

The following object is masked from 'package:Matrix':

mean

The following objects are masked from 'package:dplyr':

count, do, tally

The following objects are masked from 'package:stats':

IQR, binom.test, cor, cor.test, cov, fivenum, median, prop.test,
quantile, sd, t.test, var

The following objects are masked from 'package:base':

max, mean, min, prod, range, sample, sum

[,1] [,2]
[1,]   14   51
[2,]   38   11
[1] 12.58442
No  Yes
Placebo 18515 1427
Aspirin 18496 1438
[1] 0.9913321

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
[1] 0.9913321

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
[1] 0.9993747
RR
1 0.8406952
2 1.3256245
3 1.0528518
```

mosaic documentation built on May 23, 2018, 9:03 a.m.