# 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(1:2, e=25)
# and the matrices summarizing the numbers of subjects
# showing the respective levels at the different variables
# are computed by
cases <- rowTables(mat[, cl==1])
controls <- rowTables(mat[,cl==2])
# The values of the rowwise Cochran-Armitage trend test
# are computed by
rowCATTs(cases, controls)
# which leads to the same results as
rowTrendStats(mat, cl)
# or as
out <- rowMsquares(cases, controls)
n <- ncol(mat)
out$stats * n / (n-1)
# }
Run the code above in your browser using DataLab