# 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 we consider a case-control study,
# i.e. two groups, and that the first 25 columns
# of mat 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 liner trend test are
# computed by
rowMsquares(cases, controls)
# which leads to the same results as
listTab <- list(cases, controls)
rowMsquares(listTables = listTab)
# or as
rowTrendStats(mat, cl, use.n = FALSE)
# or as
out <- rowCATTs(cases, controls)
n <- ncol(mat)
out$stats * (n - 1) / n
# }
Run the code above in your browser using DataLab