Learn R Programming

hypergea (version 1.3.6)

getOddsRatio: Odds ratio

Description

This function calculates odds ratios for \(2\times2\) and \(2\times2\times2\) contingency tables.

Usage

getOddsRatio(x, za=TRUE)

Arguments

x

a contingency table (array or matrix)

za

zero adjustment, i.e. how to behave in case of zeros (logical). If FALSE than odds ratios as calculated. If TRUE, each cell is adjusted by addition of a small number (0.5).

Value

the odds ratio (numeric) if x is a \(2\times2\) or \(2\times2\times2\) table, NA otherwise

Details

If x is a \(2\times2\) table then the odds ratio is returned, defined as $$ OR=\frac{x_{00} x_{11} }{x_{10} x_{01}} $$ If x is a \(2\times2\times2\) table then Bartlett's ratio of odds ratios is calculated, defined as $$ OR=\frac{x_{000} x_{111} x_{011} x_{101} }{ x_{101} x_{001} x_{100} x_{111} } $$ To be able to calculate odds ratios even for huge numbers, the log of each cell count is taken.

Calculation of an odds ratio becomes difficult in presence of zeros. Depending on the position(s) of zero(s) in the table, the ratio becomes zero, NaN or Inf. This corresponds to the behaviour of the fisher.test in such a case. However, another strategy is (Haldane) to add a small number (\(0.5\)) to each cell when the table contains at least one zero.

Note that this routine calculates the sample odds ratio (also: unconditional Maximum Likelihood estimate). This is different to other routines like fisher.test, which calculate the conditional Maximum Likelihood Estimate (MLE).

References

MARTIN A. HAMILTON (1979) CHOOSING THE PARAMETER FOR A 2 x 2 TABLE OR A 2 x 2 x 2 TABLE ANALYSIS. Am. J. Epidemiol. (1979) 109 (3): 362-375

See Also

fisher.test, vcd package for visualisation of contingency tables

Examples

Run this code
# NOT RUN {
CT <- matrix(c(1:4), nrow=2)
getOddsRatio(CT)

CT <- array(c(1:8), dim=c(2,2,2))
getOddsRatio(CT)
# }

Run the code above in your browser using DataLab