| contTables {jmv} | R Documentation |
X² test of association
contTables(data, rows, cols, counts = NULL, layers = NULL, chiSq = TRUE, chiSqCorr = FALSE, likeRat = FALSE, fisher = FALSE, contCoef = FALSE, phiCra = FALSE, logOdds = FALSE, odds = FALSE, relRisk = FALSE, ci = TRUE, ciWidth = 95, gamma = FALSE, taub = FALSE, exp = FALSE, pcRow = FALSE, pcCol = FALSE, pcTot = FALSE)
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 |
chiSq |
|
chiSqCorr |
|
likeRat |
|
fisher |
|
contCoef |
|
phiCra |
|
logOdds |
|
odds |
|
relRisk |
|
ci |
|
ciWidth |
a number between 50 and 99.9 (default: 95), width of the confidence intervals to provide |
gamma |
|
taub |
|
exp |
|
pcRow |
|
pcCol |
|
pcTot |
|
A results object containing:
results$freqs | a table of proportions | ||||
results$chiSq | a table of X² test results | ||||
results$odds | a table of comparative measures | ||||
results$nom | a table of the 'nominal' test results | ||||
results$gamma | a table of the gamma test results | ||||
results$taub | a table of the Kendall's tau-b test results | ||||
Tables can be converted to data frames with asDF or as.data.frame. For example:
results$freqs$asDF
as.data.frame(results$freqs)
data('HairEyeColor')
dat <- as.data.frame(HairEyeColor)
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
# -----------------------------------------------------
#
#
# X² Tests
# -------------------------------
# Value df p
# -------------------------------
# X² 138 9 < .001
# N 592
# -------------------------------
#