View source: R/rowBinomialTests.R
rowBinomialTests | R Documentation |
Binomial proportion tests for each row of a matrix
rowBinomialTests(
mat,
categ,
alternative = c("two.sided", "less", "greater"),
warn = TRUE
)
mat |
A numeric matrix whose rows correspond to variables and columns to observations |
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
|
warn |
A boolean value indicating whether to issue a warning if
|
Note that the return element 'estimate' is inconsistent with the element 'estimate' returned by 'binomial.test', which is "the estimated probability of success". We find it more sensible to return an estimate of the effect size (as e.g. done by 't.test'))
A list containing the following components:
the value of the statistics
the p-values for the tests
the difference between observed group proportions
Each of these elements is a matrix of size nrow(mat) x B
, coerced to a vector of length nrow(mat)
if B=1
Gilles Blanchard, Pierre Neuvial and Etienne Roquain
binom.test
alt <- c("two.sided", "less", "greater")[1]
p <- 100
n0 <- 60; n1 <- 40
mat0 <- matrix(rbinom(p*n0, size = 1, prob = 0.05), ncol = n0)
mat1 <- matrix(rbinom(p*n1, size = 1, prob = 0.02), ncol = n1)
mat <- cbind(mat0, mat1)
cls <- rep(c(0, 1), times = c(n0, n1))
fbt <- rowBinomialTests(mat, categ = cls, alternative = alt)
str(fbt)
# compare with ordinary binom.test:
pbt <- t(sapply(1:p, FUN=function(ii) {
x1 <- mat[ii, cls==1]
x0 <- mat[ii, cls==0]
bt <- binom.test(sum(x1), length(x1), mean(x0), alternative = alt)
c(statistic = bt[["statistic"]], p.value = bt[["p.value"]])
}))
all(abs(fbt$p.value-pbt[, "p.value"]) < 1e-10) ## same results
all(abs(fbt$statistic-pbt[, "statistic.number of successes"]) < 1e-10) ## same results
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.