# NOT RUN {
# Generate a matrix containing data for 10 categorical
# variables with levels 1, 2, 3.
mat <- matrix(sample(3, 500, TRUE), 10)
# Now assume that the first 25 columns correspond to
# cases and the remaining 25 columns to cases. Then
# a vector containing the class labels is given by
cl <- rep(0:1, e=25)
# The values of the Cochran-Armitage trend test can
# then be computed by
rowTrendStats(mat, cl)
# This leads to the same results as
cases <- rowTables(mat[, cl==1])
controls <- rowTables(mat[,cl==0])
rowCATTs(cases, controls)
# or as
out <- rowMsquares(cases, controls)
n <- ncol(mat)
out$stats * n / (n - 1)
# }
Run the code above in your browser using DataLab