View source: R/rowWelchTests.R
rowWelchTests | R Documentation |
Welch T-tests for rows of a matrix
rowWelchTests(X, categ, alternative = c("two.sided", "less", "greater"))
X |
A |
categ |
Either a numeric vector of |
alternative |
A character string specifying the alternative hypothesis.
Must be one of "two.sided" (default), "greater" or "less". As in
|
This function performs m x B
Welch T tests on
n
observations using matrix operations. Its time complexity is
O(mBn)
. The code is 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 't.test' function is avoided and
the code is vectorized
A list containing the following components:
the value of the t-statistics
the degrees of freedom for the t-statistics
the p-values for the tests
the mean difference between groups
Each of these elements is a matrix of size m x B
, coerced to a vector of length m
if B=1
Pierre Neuvial
B. L. Welch (1951), On the comparison of several mean values: an alternative approach. Biometrika, 38, 330-336
m <- 300
n <- 38
mat <- matrix(rnorm(m * n), ncol = n)
categ <- rep(c(0, 1), times = c(27, n - 27))
system.time(fwt <- rowWelchTests(mat, categ, alternative = "greater"))
str(fwt)
# compare with ordinary t.test:
system.time(pwt <- apply(mat, 1, FUN = function(x) {
t.test(x[categ == 1], x[categ == 0], alternative = "greater")$p.value
}))
all(abs(fwt$p.value - pwt) < 1e-10) ## same results
# with several contrasts/permutations
B <- 100
categ_perm <- replicate(B, sample(categ))
system.time(fwt_perm <- rowWelchTests(mat, categ_perm, alternative = "greater"))
str(fwt_perm)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.