rowWilcoxonTests: Wilcoxon rank sum tests for each row of a matrix

rowWilcoxonTestsR Documentation

Wilcoxon rank sum tests for each row of a matrix

Description

Wilcoxon rank sum tests for each row of a matrix

Usage

rowWilcoxonTests(
  mat,
  categ,
  alternative = c("two.sided", "less", "greater"),
  correct = TRUE
)

Arguments

mat

A m x n numeric matrix whose rows correspond to variables and columns to observations

categ

Either a numeric vector of n categories in 0, 1 for the observations, or a n x B matrix stacking B such vectors (typically permutations of an original vector of size n)

alternative

A character string specifying the alternative hypothesis. Must be one of "two.sided" (default), "greater" or "less". As in wilcox.test, alternative = "greater" is the alternative that class 1 is shifted to the right of class 0.

correct

A logical indicating whether to apply continuity correction in the normal approximation for the p-value.

Details

This function performs m x B Wilcoxon T tests on n observations. It is vectorized along the rows of mat. This makes the code much faster than using loops of 'apply' functions, especially for high-dimensional problems (small n and large m) because the overhead of the call to the 'wilcox.test' function is avoided. Note that it is not vectorized along the columns of categ (if any), as a basic 'for' loop is used.

The p-values are computed using the normal approximation as described in the wilcox.test function. The exact p-values (which can be useful for small samples with no ties) are not implemented (yet).

For simplicity, 'estimate' returns the difference between the group medians, which does not match the component 'estimate' output by wilcox.test

Value

A list containing the following components:

statistic

the value of the statistics

p.value

the p-values for the tests

A list containing the following components:

statistic

the value of the statistics

p.value

the p-values for the tests

estimate

the median difference between groups (only calculated if B=1 for computational efficiency)

Each of these elements is a matrix of size m x B, coerced to a vector of length m if B=1

Author(s)

Gilles Blanchard, Pierre Neuvial and Etienne Roquain

See Also

wilcox.test

Examples


p <- 200
n <- 50
mat <- matrix(rnorm(p*n), ncol = n)
cls <- rep(c(0, 1), each = n/2)

stats <- rowWilcoxonTests(mat, categ = cls, alternative = "two.sided")
str(stats)

# permutation of class labels
cls_perm <- replicate(11, sample(cls))
stats <- rowWilcoxonTests(mat, categ = cls_perm, alternative = "two.sided")
str(stats)

# several unrelated contrasts
cls2 <- cls
cls[1:10] <- 1 # varying nx, ny
cls_mat <- cbind(cls, cls2)
stats <- rowWilcoxonTests(mat, categ = cls_mat, alternative = "two.sided")
str(stats)

pneuvial/sanssouci documentation built on Feb. 12, 2024, 4:18 a.m.