rowChisq2Class {scrime} | R Documentation |
Rowwise Pearson's ChiSquare Test Based on Tables
Description
Given a set of matrices, each of which represents one group of subjects, and summarizes rowwise the numbers of these observations showing the levels of the categorical variables represented by the rows of the matrices, the value of Pearson's ChiSquare statistic for testing whether the distribution of the variable differs between the different groups is computed for each variable.
Using this function instead of rowChisqStats
is recommended
when the total number of observations is very large.
Usage
rowChisq2Class(cases, controls, add.pval = TRUE, sameNull = FALSE)
rowChisqMultiClass(..., listTables = NULL, add.pval = TRUE,
sameNull = FALSE)
Arguments
cases |
a numeric matrix in which each row represents one categorical
variable and each column one of the 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 |
controls |
a numeric matrix of the same dimensions as |
... |
numeric matrices (such as |
listTables |
instead of inputting the matrices directly into |
add.pval |
should p-values be added to the output? If |
sameNull |
should all variables follow the same null distribution? If |
Value
Either a vector containing the rowwise values of Pearson's ChiSquare statistic
(if add.pval = FALSE
) or a list containing these values (stats
),
the degrees of freedom (df
), and the p-values (rawp
) not adjusted
for multiple comparisons (if add.pval = TRUE
).
Note
In the case of a 2 x 2 table, no continuity correction is applied. In this
case, the results of rowChisq2Class
and rowChisMultiClass
are
only equal to the results of chisq.test
if in the latter correct = FALSE
is used.
The usual contingency table for a variable can be obtained from the matrices by forming a variable-specific matrix in which each row consists of the row of one of these matrices.
Author(s)
Holger Schwender, holger.schwender@udo.edu
See Also
rowChisqStats
, rowTables
, rowCATTs
,
rowMsquares
Examples
## 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])
# To obtain the ChiSquare values call
rowChisq2Class(cases, controls)
# This leads to the same results as
rowChisqStats(mat, cl)
# or
rowChisqMultiClass(cases, controls)
# or
listTab <- list(cases, controls)
rowChisqMultiClass(listTables = listTab)
## End(Not run)