Reputation: 41
How is the oddsratio
function in R (from the epitools
package, but I have the same problem with odds.ratio from questionr
package) calculating the odds ratio? If I do the calculation manually I get a different result. Also, If I input a 2x3 matrix in oddsratio
for example, I get a 2x3 vector in return. Which odds ratios are those?
For example, if I create a 2X2 matrix m
and calculate the odds ratio manually and compare it to the results of oddsratio
:
m = matrix(c(1,6,3,1), ncol = 2, nrow = 2)
odds_rati_manual = ((1/4)/(3/4))/((6/7)/(1/7)) ## = 1/18 = 0.0556
oddsratio(m)$measure = 0.085075
why are the two different?
Also, if I input a matrix with 3 rows:
m = matrix(c(1,6,3,1,4,8), ncol = 2, nrow = 3)
oddsratio(m)$measure
I get an output with three rows. Is that the odds ratio of the odds from the first row to all the other rows?
Upvotes: 1
Views: 642
Reputation: 270348
oddsratio
supports 4 methods.
library(epitools)
args(oddsratio)
## function (x, y = NULL, method = c("midp", "fisher", "wald", "small"),
## conf.level = 0.95, rev = c("neither", "rows", "columns",
## "both"), correction = FALSE, verbose = FALSE)
Try method = "wald"
:
m <- matrix(c(1,6,3,1), ncol = 2, nrow = 2)
((1/4)/(3/4))/((6/7)/(1/7))
## [1] 0.05555556
oddsratio(m, method = "wald")$measure
## odds ratio with 95% C.I.
## Predictor estimate lower upper
## Exposed1 1.00000000 NA NA
## Exposed2 0.05555556 0.0025053 1.231956 <----------
## Warning message:
## In chisq.test(xx, correct = correction) :
## Chi-squared approximation may be incorrect
Regarding the example with 3 rows each odds ratio is based on the first row and one other row. Compare these:
library(epitools)
m3 <- matrix(c(1,6,3,1,4,8), ncol = 2, nrow = 3)
oddsratio(m3)$measure
## odds ratio with 95% C.I.
## Predictor estimate lower upper
## Exposed1 1.000000 NA NA
## Exposed2 0.690062 0.01478853 32.24304 <----- compare rows 1 & 2
## Exposed3 2.449511 0.05171633 115.75523 <----- compare rows 1 & 3
oddsratio(m3[-3, ])$measure
## odds ratio with 95% C.I.
## Predictor estimate lower upper
## Exposed1 1.000000 NA NA
## Exposed2 0.690062 0.01478853 32.24304 <----- compare rows 1 & 2
oddsratio(m3[-2, ])$measure
## odds ratio with 95% C.I.
## Predictor estimate lower upper
## Exposed1 1.000000 NA NA
## Exposed2 2.449511 0.05171633 115.7552 <----- compare rows 1 & 3
Upvotes: 3