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