Create an odds ratio estimate from a 2-by-2 table of frequencies or proportions

odds.ratio(x)

Arguments

x

A two-dimensional matrix or table containing frequencies or proportions.

Value

A numeric vector.

Author

Paul W. Egeler, M.S.

Examples

# Load in Titanic data from datasets package
data(Titanic, package = "datasets")

# Get marginal table of survival by sex
marginal_table <- margin.table(Titanic, c(2,4))
marginal_table
#>         Survived
#> Sex        No  Yes
#>   Male   1364  367
#>   Female  126  344

# Compute odds ratio of marginal table
odds.ratio(marginal_table)
#> [1] 10.14697

# Get partial tables of survival by sex, stratified by class
partial_tables <- margin.table(Titanic, c(2,4,1))
partial_tables
#> , , Class = 1st
#> 
#>         Survived
#> Sex       No Yes
#>   Male   118  62
#>   Female   4 141
#> 
#> , , Class = 2nd
#> 
#>         Survived
#> Sex       No Yes
#>   Male   154  25
#>   Female  13  93
#> 
#> , , Class = 3rd
#> 
#>         Survived
#> Sex       No Yes
#>   Male   422  88
#>   Female 106  90
#> 
#> , , Class = Crew
#> 
#>         Survived
#> Sex       No Yes
#>   Male   670 192
#>   Female   3  20
#> 

# Compute odds ratio of each partial table
apply(partial_tables, 3, odds.ratio)
#>       1st       2nd       3rd      Crew 
#> 67.088710 44.067692  4.071612 23.263889