rowBinomialTests: Binomial proportion tests for each row of a matrix

View source: R/rowBinomialTests.R

rowBinomialTestsR Documentation

Binomial proportion tests for each row of a matrix

Description

Binomial proportion tests for each row of a matrix

Usage

rowBinomialTests(
  mat,
  categ,
  alternative = c("two.sided", "less", "greater"),
  warn = TRUE
)

Arguments

mat

A 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 binom.test, alternative = "greater" is the alternative that class 1 is shifted to the right of class 0.

warn

A boolean value indicating whether to issue a warning if alternative=="two-sided". Defaults to TRUE.

Details

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'))

Value

A list containing the following components:

statistic

the value of the statistics

p.value

the p-values for the tests

estimate

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

Author(s)

Gilles Blanchard, Pierre Neuvial and Etienne Roquain

See Also

binom.test

Examples


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




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