【问题标题】:Why does estimated odds ratio obtained in fisher.test() function different from calculated odds ratio?为什么在 fisher.test() 函数中获得的估计优势比与计算的优势比不同?
【发布时间】:2016-09-04 21:33:20
【问题描述】:

这是我的列联表:

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检验函数如何计算估计的优势比?

【问题讨论】:

    标签: r


    【解决方案1】:

    查看fisher.test底层的代码,我明白了

    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[1 中定义的另一个函数) ]),而不是直接从数据中计算出来。我怀疑如果我想得到一个完整的答案,我需要阅读?fisher.test中的参考资料

    [1] fisher.test 中有几个函数,例如 dnhypermnhyperpnhyper,它们似乎是非中心超几何分布的分布函数。

    【讨论】:

    • 在您看来,我应该在分析中报告哪个优势比值?
    • 就个人而言,我会将优势比四舍五入到百分之一。我怀疑您可能会遇到差异甚至达到千分之一的情况。
    猜你喜欢
    • 2020-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-23
    相关资源
    最近更新 更多