Learn R Programming

scrime (version 1.3.5)

computeContClass: Rowwise Contigency Tables

Description

Generates a matrix containing a contingency table for each row of a matrix and a vector of class labels.

Usage

computeContClass(data, cl, n.cat)

Arguments

data

a numeric matrix consisting of integers between 1 and n.cat. Each row of data is assumed to represent a variable, and each column to represent an observation. Missing values are not allowed. All variables must comprise the same number of levels.

cl

a numeric vector of length ncol(data) specifying the class labels of the observations represented by the columns of data. cl must consist of integers between 1 and \(n_{cl}\), where \(n_{cl}\) is the number of classes.

n.cat

an integer giving the number of levels the variables can take. If not specified, n.cat will be determined automatically. It is highly recommended not to specify n.cat.

Value

A list composed of the following two matrices:

mat.obs

a matrix consisting of \(m\) rows and n.cat \(* n_{cl}\) columns, where \(m\) is the number of variables, i.e.\ the number of rows of data. Each row of data shows the contingency table of cl and the corresponding row of data.

mat.exp

a matrix of the same size as mat.obs containing the numbers of observations expected under the null hypothesis of equal distribution in all classes that correspond to the respective entries in mat.obs.

References

Schwender, H.\ (2007). A Note on the Simultaneous Computation of Thousands of Pearson's \(\chi^2\)-Statistics. Technical Report, SFB 475, Deparment of Statistics, University of Dortmund.

See Also

computeContCells, rowChisqStats

Examples

Run this code
# NOT RUN {
# Generate an example data set consisting of 10 rows (variables)
# and 200 columns (observations) by randomly drawing integers 
# between 1 and 3, and a vector of class labels of length 200
# indicating that the first 100 observation belong to class 1
# and the other 100 to class 2. 

mat <- matrix(sample(3, 2000, TRUE), 10)
cl <- rep(1:2, e = 100)

# Applying computeContClass to this data set

out <- computeContClass(mat, cl)

# generates the observed numbers of observations

out$mat.obs

# and the corresponding expected numbers of observations.

out$mat.exp

# }

Run the code above in your browser using DataLab