[R] How odds ratio is computed in fisher.test()?

Ben Bolker bolker at ufl.edu
Fri Oct 16 20:58:42 CEST 2009




  From ?fisher.test:

estimate: an estimate of the odds ratio.  Note that the _conditional_
          Maximum Likelihood Estimate (MLE) rather than the
          unconditional MLE (the sample odds ratio) is used. Only
          present in the 2 by 2 case.

from fisher.test:

    mle <- function(x) {
            if (x == lo) 
                return(0)
            if (x == hi) 
                return(Inf)
            mu <- mnhyper(1)
            if (mu > x) 
                uniroot(function(t) mnhyper(t) - x, c(0, 1))$root
            else if (mu < x) 
                1/uniroot(function(t) mnhyper(1/t) - x,
c(.Machine$double.eps, 
                  1))$root
            else 1
        }
        ESTIMATE <- mle(x)




Peng Yu wrote:
> 
> I'm wondering how odds ratio is computed. I thought that it is
> (n11/n12)/(n21/n22), but it is not what fisher.test() computes. Could
> somebody let me know?
> 
>> n11=3
>> n12=1
>> n21=1
>> n22=3
>>
>> n1_=n11+n12
>> n2_=n21+n22
>>
>> n_1=n11+n21
>> n_2=n12+n22
>>
>> x=rbind(c(n11,n12),c(n21,n22))
>>
>> threshold=dhyper(n11,n1_,n2_,n_1)
>> probability=dhyper(0:n_1,n1_,n2_,n_1)
>> sum(probability[probability<=threshold])
> [1] 0.4857143
>> (n11/n12)/(n21/n22)
> [1] 9
>> fisher.test(x)
> 
>         Fisher's Exact Test for Count Data
> 
> data:  x
> p-value = 0.4857
> alternative hypothesis: true odds ratio is not equal to 1
> 95 percent confidence interval:
>    0.2117329 621.9337505
> sample estimates:
> odds ratio
>   6.408309
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: http://www.nabble.com/How-odds-ratio-is-computed-in-fisher.test%28%29--tp25929899p25930580.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list