head(Data)
Gene1 Gene2 Gene3 Gene4 Gene5 Gene6 Gene7 Gene8
SAMPLE1 0 1 0 0 0 1 1 1
SAMPLE2 0 1 0 1 0 1 0 1
SAMPLE3 0 0 0 1 0 0 1 1
SAMPLE4 1 0 0 0 1 0 0 0
我正在运行fisher检验和卡方检验,如下所示
Gene7_Gene8<- table (Data[, c ("Gene7", "Gene8")])
chisq.test( Gene7_Gene8) and
fisher.test(Gene7_Gene8)
我怎样才能在所有的数据集中同时运行for loop
的chisq检验呢?我正在寻找我的数据集中每一对可能的基因的p值。(我的原始数据有大约60列)
3条答案
按热度按时间w51jfk4q1#
我希望这对你有用。
nzk0hqpo2#
我们可以使用
combn
ve7v8dk23#
不需要
for
循环,我们可以这样做:对于Fisher检验,我们遇到了一些问题:
这是因为不是所有的表都是2x2的,所以我们需要捕获这个错误并返回一些有意义的信息。
从这里,我们可以轻松地将它们组合在一起:
虽然
combn
确实有FUN=
参数,但我发现在fisher.test
自动化中重用结果也更容易。它还清除了输出(在我看来),因为它清楚地显示了在每次比较中考虑哪些基因。