【发布时间】: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