jmv

Contingency Tables

χ² test of association

Example usage

data('HairEyeColor')
dat <- as.data.frame(HairEyeColor)

jmv::contTables(dat, rows = 'Hair', cols = 'Eye', counts = 'Freq')

#
#  Contingency Tables
#
#  Contingency Tables
#  ─────────────────────────────────────────────────────
#    Hair     Brown    Blue    Hazel    Green    Total
#  ─────────────────────────────────────────────────────
#    Black       68      20       15        5      108
#    Brown      119      84       54       29      286
#    Red         26      17       14       14       71
#    Blond        7      94       10       16      127
#    Total      220     215       93       64      592
#  ─────────────────────────────────────────────────────
#
#
#  χ² Tests
#  ───────────────────────────────
#          Value    df    p
#  ───────────────────────────────
#    χ²      138     9    < .001
#    N       592
#  ───────────────────────────────
#
 

Arguments

data — the data as a data frame

rows — a string naming the variable to use as the rows in the contingency table

cols — a string naming the variable to use as the columns in the contingency table

counts — a string naming the variable to use as counts, or NULL if each row represents a single observation

layers — a character vector naming variables to split the contingency table across

chiSqTRUE (default) or FALSE, provide χ²

chiSqCorrTRUE or FALSE (default), provide χ² with continuity correction

likeRatTRUE or FALSE (default), provide the likelihood ratio

contCoefTRUE or FALSE (default), provide the contingency coefficient

phiCraTRUE or FALSE (default), provide Phi and Cramer's V

logOddsTRUE or FALSE (default), provide the log odds ratio (only available for 2x2 tables)

ciWidth — a number between 50 and 99.9 (default: 95), width of the confidence intervals to provide

gammaTRUE or FALSE (default), provide gamma

taubTRUE or FALSE (default), provide Kendall's tau-b

expTRUE or FALSE (default), provide the expected counts

pcRowTRUE or FALSE (default), provide row percentages

pcColTRUE or FALSE (default), provide column percentages

pcTotTRUE or FALSE (default), provide total percentages