gpt4 book ai didi

r - 如何使用 Bonferroni 校正计算数据框中每一行的超几何检验

转载 作者:行者123 更新时间:2023-12-02 02:31:30 26 4
gpt4 key购买 nike

我正在计算 R 数据框中每行的超几何测试,希望是正确的。

其中第 1 列是基因 (microRNA) 的名称,“Total_mRNA”列是基因组中总共存在多少 mRNA,因此不会改变。 “Total_targets_targets”列是如果所有 mRNA 都存在的话,每个 microRNA 可以靶向的 mRNA 数量。然而,对于这个例子,仅存在“subset_mRNA”(该数字也始终相同),并且其中我知道每个 microRNA 可以针对“subset_targets”有多少个 mRNA。

为了确定每个 microRNA 的目标与背景(总 mRNA 和针对它们的总 microRNA)相比是否富集,我对每行执行超几何测试,如下所示:

phyper(targets-in-subset, targets-in-bkgd, failure-in-bkgd, sample-size-subset, lower.tail= FALSE)



dput(df1)
structure(list(Genes_names = c("microRNA-1", "microRNA-2", "microRNA-3",
"microRNA-4", "microRNA-5", "microRNA-6", "microRNA-7", "microRNA-8",
"microRNA-9", "microRNA-10"), Total_mRNAs = c(61064L, 61064L,
61064L, 61064L, 61064L, 61064L, 61064L, 61064L, 61064L, 61064L
), Total_targets_targets = c(1918L, 7807L, 3969L, 771L, 2850L,
1355L, 1560L, 2478L, 1560L, 2478L), subset_mRNAs = c(17571L,
17571L, 17571L, 17571L, 17571L, 17571L, 17571L, 17571L, 17571L,
17571L), subset_targets = c(544L, 2109L, 1137L, 213L, 793L, 394L,
430L, 686L, 430L, 686L)), class = "data.frame", row.names = c(NA,
-10L))


df1$pvalue <- phyper(df1$subset_targets, df1$Total_targets_targets, df1$Total_mRNAs-df1$Total_targets_targets, df1$subset_mRNAs, lower.tail= FALSE)

现在的问题是 Bonferroni 如何纠正这个值?这个计算理论上正确吗?

最佳答案

如果您没有大量样本,请避免这种痛苦,只需使用 Fisher 测试并使用 p.adjust 进行 bonferroni:

library(broom)
result = lapply(1:nrow(df1),function(i){
not_target_subset = df1$Total_targets_targets[i] - df1$subset_targets[i]
not_subset = df1$Total_mRNAs[i] - df1$subset_mRNAs[i] - not_target_subset


M = cbind(c(df1$subset_targets[i],df1$subset_mRNAs[i]-df1$subset_targets[i]),
c(not_target_subset,not_subset))

res = data.frame(Genes_names=df1$Genes_names[i],
tidy(fisher.test(M,alternative="greater")))

return(res)
})

result= do.call(rbind,result)
result$padj = p.adjust(result$p.value,"bonferroni")

您的超几何代码略有偏差。请注意,您正在进行单侧超几何测试。

您可以查看这个post for how to put the tables into phyperthis for why you need the -1 。因此我们计算超几何 p 值:

result$hyper_p = with(df1, 
phyper(subset_targets-1,subset_mRNAs,Total_mRNAs-subset_mRNAs, Total_targets_targets, lower.tail= FALSE)
)

你可以看到它相符:

   Genes_names  estimate   p.value  conf.low conf.high
1 microRNA-1 0.9793710 0.6655527 0.8984025 Inf
2 microRNA-2 0.9047305 0.9998968 0.8647701 Inf
3 microRNA-3 0.9933480 0.5791759 0.9350214 Inf
4 microRNA-4 0.9441864 0.7722712 0.8229140 Inf
5 microRNA-5 0.9520878 0.8789562 0.8863785 Inf
6 microRNA-6 1.0151760 0.4119600 0.9168998 Inf
7 microRNA-7 0.9404619 0.8641420 0.8539585 Inf
8 microRNA-8 0.9454359 0.8942082 0.8756678 Inf
9 microRNA-9 0.9404619 0.8641420 0.8539585 Inf
10 microRNA-10 0.9454359 0.8942082 0.8756678 Inf
method alternative hyper_p
1 Fisher's Exact Test for Count Data greater 0.6655527
2 Fisher's Exact Test for Count Data greater 0.9998968
3 Fisher's Exact Test for Count Data greater 0.5791759
4 Fisher's Exact Test for Count Data greater 0.7722712
5 Fisher's Exact Test for Count Data greater 0.8789562
6 Fisher's Exact Test for Count Data greater 0.4119600
7 Fisher's Exact Test for Count Data greater 0.8641420
8 Fisher's Exact Test for Count Data greater 0.8942082
9 Fisher's Exact Test for Count Data greater 0.8641420
10 Fisher's Exact Test for Count Data greater 0.8942082

关于r - 如何使用 Bonferroni 校正计算数据框中每一行的超几何检验,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64969842/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com