【问题标题】:running paired wilcoxon test on rows of two dataframes对两个数据帧的行运行配对 wilcoxon 测试
【发布时间】:2022-01-27 22:35:25
【问题描述】:

我有两个大数据框(大约 19000 行和 71 列)如下 df1

sample1 sample2 sample3
gene1 5 10 15
gene2 2 8 10
gene3 3 9 10

df2

sample1 sample2 sample3
gene1 40 50 65
gene2 12 18 0
gene3 31 19 10

我正在尝试对具有相同索引的行执行 wilcoxon 秩和检验,但代码在 google colab 上一直占用!! 到目前为止我的代码

wilc_results= c()
for( x in 1:nrow(df1)){
  for (y in 1:nrow(df2)){
    result= wilcox.test(as.numeric(df2[y,]), as.numeric(f1d[x,]), 
                        alternative= 'two.sided', paired= T )
    wilc_results[length(wilc_results) + 1] <- result$p.value
  }
}

有没有更快的方法来获得所需的输出?

【问题讨论】:

    标签: r dataframe matrix hypothesis-test pairwise.wilcox.test


    【解决方案1】:

    无需循环两次,因为两个数据框的列数相同。它在我计算机上类似大小的数据集上运行大约 10 秒。

    wilc_results <- list()
    for(i in 1:nrow(df1)) {
      result <- wilcox.test(as.numeric(df1[i,]), as.numeric(df2[i,]),
                            alternative='two.sided', paired=T)
      wilc_results[[i]] <- result$p.value
    }
    

    【讨论】:

    • @dbodgan 非常感谢!!!
    猜你喜欢
    • 2022-11-15
    • 2018-03-21
    • 2020-09-13
    • 2022-01-09
    • 1970-01-01
    • 2012-09-13
    • 2013-02-05
    • 2021-07-06
    • 2021-09-29
    相关资源
    最近更新 更多