Nai*_*mos 5 statistics performance r matrix hypothesis-test
我目前正在尝试对多个数据集实施Wilcoxon Ranksum测试,这些数据集已合并到一个大矩阵中A,即705x17635(即,我想运行ranksum测试17,635时间。使用for循环是lapply,我已将其运行为:
> lapply(data.frame(A), function(x)
wilcox.test(x,b,alternative="greater",exact=FALSE,correct=FALSE))
Run Code Online (Sandbox Code Playgroud)
b我们的阴性对照数据在哪里,是一个20000x1向量。但是,运行它会花费很长时间(我在30分钟后放弃了),我想知道是否有一种更快的方法来运行它,尤其是因为我可以在MATLAB中(甚至使用forloop)在大约5秒钟内完成相同的过程分钟,但出于各种原因,我需要使用R。
有一些软件包试图解决这个问题。IE:
A <- matrix(rnorm(705*17635), nrow=705)
b <- rnorm(20000)
library(matrixTests)
res <- col_wilcoxon_twosample(A, b) # running time: 83 seconds
Run Code Online (Sandbox Code Playgroud)
结果中的几行:
res[1:2,]
obs.x obs.y obs.tot statistic pvalue alternative location.null exact corrected
1 705 20000 20705 6985574 0.6795783 two.sided 0 FALSE TRUE
2 705 20000 20705 7030340 0.8997009 two.sided 0 FALSE TRUE
Run Code Online (Sandbox Code Playgroud)
wilcox.test()检查结果是否与逐列执行相同:
wilcox.test(A[,1], b)
Wilcoxon rank sum test with continuity correction
data: A[, 1] and b
W = 6985574, p-value = 0.6796
alternative hypothesis: true location shift is not equal to 0
Run Code Online (Sandbox Code Playgroud)