rowZTests | R Documentation |
Z tests for rows of a matrix
rowZTests(mat, categ, alternative)
mat |
A numeric matrix whose rows correspond to |
categ |
Either a numeric vector of |
alternative |
A character string specifying the alternative hypothesis.
Must be one of "two.sided" (default), "greater" or "less". |
A list containing the following components:
the value of the statistics
the p-values for the tests
Each of these elements is a matrix of size nrow(mat) x B
, coerced to a vector of length nrow(mat)
if B=1
Pierre Neuvial
p <- 1e4+1
n <- 380
mat <- matrix(rnorm(p*n, mean = 1), ncol=n)
zt <- rowZTests(mat, alternative = "greater")
str(zt)
# compare with apply version:
p <- apply(mat, 1, FUN=function(x) {
stat <- sum(x)/sqrt(length(x))
pnorm(stat, lower.tail = FALSE)
})
all(abs(zt$p.value - p) < 1e-10) ## same results
# Sign flipping
B <- 10
eps <- replicate(B, rbinom(n, 1, 0.5)*2 - 1) ## Rademacher
zt_perm <- rowZTests(mat, eps, alternative = "greater")
str(zt_perm)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.