# NOT RUN {
# Generate an example data set consisting of 5 rows (variables)
# and 200 columns (observations) by randomly drawing integers
# between 1 and 3.
mat <- matrix(sample(3, 1000, TRUE), 5)
rownames(mat) <- paste("SNP", 1:5, sep = "")
# For each pair of rows of mat, test if they are independent.
r1 <- rowChisqStats(mat)
# The values of Pearson's ChiSquare statistic as matrix.
r1$stats
# And the corresponding (unadjusted) p-values.
r1$rawp
# Obtain only the values of the test statistic as vector
rowChisqStats(mat, compPval = FALSE, asMatrix =FALSE)
# Generate an example data set consisting of 10 rows (variables)
# and 200 columns (observations) by randomly drawing integers
# between 1 and 3, and a vector of class labels of length 200
# indicating that the first 100 observation belong to class 1
# and the other 100 to class 2.
mat2 <- matrix(sample(3, 2000, TRUE), 10)
cl <- rep(1:2, e = 100)
# For each row of mat2, test if they are associated with cl.
r2 <- rowChisqStats(mat2, cl)
r2$stats
# And the results are identical to the one of chisq.test
pv <- stat <- numeric(10)
for(i in 1:10){
tmp <- chisq.test(mat2[i,], cl)
pv[i] <- tmp$p.value
stat[i] <- tmp$stat
}
all.equal(r2$stats, stat)
all.equal(r2$rawp, pv)
# }
Run the code above in your browser using DataLab