为什么在fisher.test()函数中获得的估计比值比与计算的比值比不同?

时间:2016-09-01 09:05:39

标签: r

这是我的列联表:

X
#      Yes   No
# Pre    5  685
# Post  17 1351
费希尔测试

fisher.test(X)

#        Fisher's Exact Test for Count Data

# data:  X
# p-value = 0.3662
# alternative hypothesis: true odds ratio is not equal to 1
# 95 percent confidence interval:
# 0.1666371 1.6474344
# sample estimates:
# odds ratio 
# 0.5802157

计算优势比

P1<-5/(5+685)
P2<-17/(17+1351)
(P1/(1-P1))/(P2/(1-P2))
# [1] 0.5800773

为什么值不同? R中的Fisher测试函数如何计算估计的比值比?

1 个答案:

答案 0 :(得分:0)

查看ESTIMATE <- c(`odds ratio` = mle(x)) 底层代码,我看到了

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
        }

紧接其上方是

mle

在没有探索fisher.test定义之上的代码的所有细节的情况下,看起来mnhyper正在根据fisher.test中定义的理论假设求解赔率的等式(另一个函数定义在?fisher.test [1]中,而不是直接从数据中计算出来。我怀疑如果我想得到一个完整的答案,我需要阅读fisher.test

中的参考文献

[1] dnhyper中有几个函数,例如mnhyperpnhyper <script src='fullcalendar/lang/es.js'></script> ,它们似乎是非中心超几何分布的分布函数。

相关问题