R: Odds ratio

getOddsRatio {hypergea} | R Documentation

## Odds ratio

### Description

This function calculates odds ratios for 2x2 and 2x2x2 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).

### Details

If `x` is a 2x2 table then the odds ratio is returned, defined as

OR=(x_00 x_11 )/( x_10 x_01 )

If `x` is a 2x2 table then Bartlett's ratio of odds ratios is calculated, defined as

OR=(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).

### Value

the odds ratio (numeric) if `x` is a 2x2 or 2x2x2 table, `NA` otherwise

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

    CT <- matrix(c(1:4), nrow=2)
    getOddsRatio(CT)

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

[Package hypergea version 1.3.6 Index]