【问题标题】:Integrate odds ratio and CI with p-value in Fisher test R在 Fisher 检验 R 中将优势比和 CI 与 p 值相结合
【发布时间】:2020-08-22 02:32:30
【问题描述】:

对于矩阵的每一行,我想计算 p 值、优势比和优势比的 95% CI。 我可以按如下方式计算 Fisher p 值:

df <- read.table(text="
          h_p    d_p    h_a    d_a
                  bgc1    0         10          1        3
                  bgc2    0          0          5           25
                  ", header=T, row.names=1)
Fisher_output<-data.frame(apply(df, 1, 
      function(x) {
        tbl <- matrix(as.numeric(x[1:4]), ncol=2, byrow=T) # converting each matrix row to contingency tables
        fisher.test(tbl, alternative="two.sided")$p.value
      }))

我希望我的最终输出格式为:

P-value OR  95%_CI
BGC1    xxx yyy zzz1-zzz2
BGC2            

谢谢。

【问题讨论】:

    标签: r


    【解决方案1】:

    我们可以从broom中提取带有tidy的组件

    library(dplyr)
    library(broom)
    apply(df, 1, function(x) {
       tbl <- matrix(as.numeric(x[1:4]), ncol=2, byrow=T)
      ft <- fisher.test(tbl, alternative="two.sided")
      tidy(ft) %>% 
         select(estimate, p.value, conf.low, conf.high) }) %>% 
     bind_rows(.id = 'grp')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-07
      • 1970-01-01
      • 1970-01-01
      • 2011-02-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多