我的数据框架如下所示
SYMBOL INTENSITY1 CALL1 PVALUE1 INTENSITY2 CALL2 PVALUE2 INTENSITY3 CALL3 PVALUE3
CCL5 NA <NA> 0.000 NA <NA> NA 1125.518318 P 0.000943658
CYP2A6 141.73193 A 0.060419342 102.5146 A 0.08940508 227.369549 A 0.218983229
CYP2E1 57.67287 P 0.024710915 134.4076 P 0.000000 6.090816 A 0.040000000
DDR1 3242.90209 P 0.000218932 NA <NA> NA 7015.297075 P 0.000218932
EPHB3 78.58733 A 0.234556513 453.3487 P 0.00222774 125.238085 A 0.418069378
我使用以下代码通过Fisher方法
计算p值Fisher.test <- function(p) {
Xsq <- -2*sum(log(p))
p.val <- pchisq(Xsq, df = 2*length(p), lower.tail = FALSE)
return(c( p.value = p.val)) #
}
感谢Tim Biegeleisen
p.cols <- grep("PVALUE", names(data))
data$Fishers <- apply(data[, names(data)[p.cols]], 1, function(x) Fisher.test(x))
现在问题是行中的零条目。在第一行中,PVALUE
条目为0.000, 0.00094365
,如果我在Fisher.test
Fisher.test`上计算c(0.000, 0.00094365) , it give the result as zero, but the correct result is 0.00094365. So i need to skip the zero entries of the rows from passing through the
。
所需的输出
SYMBOL INTENSITY1 CALL1 PVALUE1 INTENSITY2 CALL2 PVALUE2 INTENSITY3 CALL3 PVALUE3 Fisher's
CCL5 NA <NA> 0.000 NA <NA> NA 1125.518318 P 0.000943658 0.000943658
CYP2A6 141.73193 A 0.060419342 102.5146 A 0.08940508 227.369549 A 0.218983229 0.03602191
CYP2E1 57.67287 P 0.024710915 134.4076 P 0.000000 6.090816 A 0.040000000 0.007828
DDR1 3242.90209 P 0.000218932 NA <NA> NA 7015.297075 P 0.000218932 0.0000008557
EPHB3 78.58733 A 0.234556513 453.3487 P 0.00222774 125.238085 A 0.418069378 0.00982
答案 0 :(得分:3)
我们可以在应用Fisher.test
apply(data[, names(data)][p.cols]], 1, function(x) Fisher.test(x[x!=0]))