所以我想在3000+行表的每一行上做一个Fisher精确测试(单面),其格式与下面的示例匹配
基因 | sample_alt | sample_ref | Population_alt | Population_ref |
---|---|---|---|---|
一 | 4 | 556 | 770 | 37000 |
二 | 5 | 555 | 771 | 36999 |
三 | 6 | 554 | 772 | 36998 |
理想情况下,我想使表的另一列等于
[(4 + 556)!(4 + 770)!(770 + 37000)!(556 + 37000)!] / [4!(556!)770!(37000!)(4 + 556 + 770 + 37000)! ]
对于数据的第一行,依此类推,对于表的每一行,依此类推。
我知道如何在R中对简单的2x2表执行费舍尔测试,但是我不知道如何将fisher.test()函数应用于大型表的每一行。我也不能使用excel公式,因为阶乘的数量太大,以至于达到excel的位数限制并导致#NUM错误。简单地完成此操作的最佳方法是什么?提前致谢!
从桌面上的制表符分隔的文本文件(table.txt)开始,其格式与词干问题中显示的格式相同
if(!require(psych)){install.packages("psych")}
multiFisher = function(file="Desktop/table.txt", saveit=TRUE,
outfile="Desktop/table.csv", progress=T,
verbose=FALSE, digits=3, ... )
{
require(psych)
Data = read.table(file, skip=1, header=F,
col.names=c("Gene", "MD", "WTD", "MC", "WTC"), ...)
if(verbose){print(str(Data))}
Data$Fisher.p = NA
Data$phi = NA
Data$OR1 = format(0.123, nsmall=3)
Data$OR2 = NA
if(progress){cat("\n")}
for(i in 1:length(Data$Gene)){
Matrix = matrix(c(Data$WTC[i],Data$MC[i],Data$WTD[i],Data$MD[i]), nrow=2)
Fisher = fisher.test(Matrix, alternative = 'greater')
Data$Fisher.p[i] = signif(Fisher$p.value, digits=digits)
Data$phi[i] = phi(Matrix, digits=digits)
OR1 = (Data$WTC[i]*Data$MD[i])/(Data$MC[i]*Data$WTD[i])
OR2 = 1 / OR1
Data$OR1[i] = format(signif(OR1, digits=digits), nsmall=3)
Data$OR2[i] = signif(OR2, digits=digits)
if(progress) {cat(".")}
}
if(progress){cat("\n"); cat("\n")}
if(saveit){write.csv(Data, outfile)}
return(Data)
}
multiFisher()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句