Performs a Wilcoxon rank sum (Mann-Whitney) test on each column of a
matrix, comparing the rows labeled TRUE with the rows labeled
FALSE, and computes the area under the ROC curve (AUC).
tgs_wilcox(x, labels, alternative = c("two.sided", "less", "greater"))a numeric matrix or a data frame of numeric columns. Rows are observations and columns are features.
a logical vector of length nrow(x). Rows labeled
TRUE form the first sample and rows labeled FALSE the
second.
one of "two.sided", "less" or
"greater", with the same meaning as in wilcox.test.
A numeric matrix with ncol(x) rows and 3 columns named
"W", "auc" and "pval". Row names are the column names
of x. Columns where one of the samples has no non-missing values are
NA. When the p-value is not defined (e.g. all values of the column
are tied and alternative is "two.sided"), it is NA.
For each column j, the statistic and the p-value are equal to those of
wilcox.test(x[labels, j], x[!labels, j], alternative = alternative,
exact = FALSE, correct = TRUE): W is the number of pairs of a
TRUE and a FALSE observation where the TRUE
observation is higher, with ties counted as 1/2, and the p-value is
computed from the normal approximation with correction for ties and
continuity correction. auc = W / (n1 * n2), where n1 and
n2 are the numbers of non-missing observations of the column in each
sample: the probability that a TRUE observation is higher than a
FALSE one.
Missing values (NA, NaN) are dropped from each column
separately, and rows whose label is NA are ignored. Infinite values
are kept, as in wilcox.test.
# \donttest{
# Note: all the available CPU cores might be used
set.seed(42)
x <- matrix(rnorm(2000 * 100), ncol = 100)
labels <- rep(c(TRUE, FALSE), each = 1000)
x[labels, 1:10] <- x[labels, 1:10] + 0.5
result <- tgs_wilcox(x, labels)
head(result)
#> W auc pval
#> [1,] 634823 0.634823 1.616212e-25
#> [2,] 644253 0.644253 5.656732e-29
#> [3,] 625041 0.625041 3.555008e-22
#> [4,] 655510 0.655510 2.118949e-33
#> [5,] 657403 0.657403 3.544604e-34
#> [6,] 641295 0.641295 7.266915e-28
# }