cont_table: Build contingency tables for frequency comparison (corpora)

cont.tableR Documentation

Build contingency tables for frequency comparison (corpora)

Description

This is a convenience function which constructs 2x2 contingency tables needed for frequency comparisons with chisq.test, fisher.test and similar functions.

Usage


cont.table(k1, n1, k2, n2, as.list=NA)

Arguments

k1

frequency of a type in the first corpus, a numeric scalar or vector

n1

the size of the first corpus (sample size), a numeric scalar or vector

k2

frequency of the type in the second corpus, a numeric scalar or vector

n2

the size of the second corpus (sample size), a numeric scalar or vector

as.list

whether multiple contingency tables can be constructed and are returned as a list (see "Details" below)

Details

If all four arguments k1 n1 k2 n2 are scalars (vectors of length 1), cont.table constructs a single contingency table, i.e. a 2x2 matrix. If at least one argument has length > 1, shorter vectors are replicated as necessary, and a list of 2x2 contingency tables is constructed.

With as.list=TRUE, the return value is always a list, even if it contains just a single contingency table. With as.list=FALSE, only scalar arguments are accepted and the return value is guaranteed to be a 2x2 matrix.

Value

A numeric matrix containing a two-by-two contingency table for the specified frequency comparison, or a list of such matrices (see "Details").

Author(s)

Stephanie Evert (https://purl.org/stephanie.evert)

See Also

chisq.test, fisher.test

Examples

ct <- cont.table(42, 100, 66, 200)
ct

chisq.test(ct)

corpora documentation built on Aug. 21, 2023, 1:07 a.m.

Related to cont_table in corpora...