Learn R Programming

scrime (version 1.3.5)

rowCATTs: Rowwise Cochran-Armitage Trend Test Based on Tables

Description

Given two matrices, each representing one group of subjects (e.g., cases and controls in a case-control study), that summarize the numbers of subjects showing the different (ordered) levels of the ordinal variables represented by the rows of the matrices, the value of the Cochran-Armitage Trend Test statistic is computed for each variable.

Using this function instead of rowTrendStats is in particular recommended when the total number of observations is very large.

Usage

rowCATTs(cases, controls, scores = NULL, add.pval = TRUE)

Arguments

cases

a numeric matrix in which each row represents one ordinal variable and each column one of the ordered levels that the variables exhibit. The entries of this matrix are the numbers of observations from one group (e.g., the cases in a case-control study) showing a particular level at the different variables. Such a matrix can, e.g., be generated by rowTables. The rowwise sums of cases are allowed to differ between variables (which might happen when some of the observations are missing for some of the variables).

controls

a numeric matrix of the same dimensions as cases comprising the numbers of observations from the second group (e.g., the controls in a case-control study) that show the respective level at the different ordinal variables. The rows of controls must represent the same variables in the same order as cases, and the columns must represent the same levels in the same order. This matrix can also be generated by employing rowTables. The rowwise sums of controls are allowed to differ between variables (which might happen when some of the observations are missing for some of the variables).

scores

a numeric vector of length ncol(cases) containing the scores for the different levels. If not specified, i.e.\ NULL, the column names of cases are interpreted as scores.

add.pval

should p-values be added to the output? If FALSE, only the rowwise values of the Cochran-Armitage trend test statistic will be returned. If TRUE, additionally the (raw) p-values based on an approximation to the ChiSquare-distribution with 1 degree of freedom are returned.

Value

Either a vector containing the rowwise values of the Cochran-Armitage trend test statistic (if add.pval = FALSE), or a list containing these values (stats), and the (raw) p-values (rawp) not adjusted for multiple comparisons (if add.pval = TRUE).

References

Agresti, A.\ (2002). Categorical Data Analysis. Wiley, Hoboken, NJ. 2nd Edition.

Armitage, P.\ (1955). Tests for Linear Trends in Proportions and Frequencies. Biometrics, 11, 375-386.

Cochran, W.~G.\ (1954). Some Methods for Strengthening the Common ChiSquare Tests. Biometrics, 10, 417-451.

See Also

rowTrendStats, rowMsquares, rowChisq2Class

Examples

Run this code
# 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