Phi(x, y = NULL, ...)
ContCoef(x, y = NULL, correct = FALSE, ...)
CramerV(x, y = NULL, conf.level = NA, ...)
YuleQ(x, y = NULL, ...)
YuleY(x, y = NULL, ...)
TschuprowT(x, y = NULL, ...)
x
. If y is provided, table(x, y)
is calculated.NA
(which is the default) no confidence interval will be calculated.
See examples for how to compute bootstrap intervals.ContCoef
and indicates, whether the Sakoda's adjusted Pearson's C should be returned or not.
Default is FALSE
.table
, allowing i.e. to set useNA
.x
and y
are expected. In latter case table(x, y, ...)
is calculated.
The function handles NAs the same way the table
function does, so tables are by default calculated with NAs omitted.
A provided matrix is interpreted as a contingency table, which seems in the case of frequency data the natural interpretation
(this is what chisq.test
expects).
Use the function PairApply
(pairwise apply) if the measure should be calculated pairwise for all columns.
This allows matrices of association measures to be calculated the same way cor
does. NAs are by default omitted pairwise,
which corresponds to the pairwise.complete option of cor
.
Use complete.cases
, if only the complete cases of a data.frame are to be used. (see examples)
The maximum value for Phi is sqrt(min(r, c) - 1), for the corrected contingency coefficient and for Cramer's V it's 1.
The minimum value for all is 0 under statistical independence.table
, PlotCorr
, PairApply
data(d.pizza)
tab <- table(d.pizza$driver, d.pizza$wine_delivered)
Phi(tab)
ContCoef(tab)
CramerV(tab)
TschuprowT(tab)
# just x and y
CramerV(d.pizza$driver, d.pizza$wine_delivered)
# data.frame
PairApply(d.pizza[,c("driver","operator","area")], CramerV)
# useNA is passed to table
PairApply(d.pizza[,c("driver","operator","area")], CramerV, useNA="ifany")
d.frm <- d.pizza[,c("driver","operator","area")]
PairApply(d.frm[complete.cases(d.frm),], CramerV)
m <- as.table(matrix(c(2,4,1,7), nrow=2))
YuleQ(m)
YuleY(m)
# Bootstrap confidence intervals for Cramer's V
# http://support.sas.com/documentation/cdl/en/statugfreq/63124/PDF/default/statugfreq.pdf, p. 1821
tab <- as.table(rbind(
c(26,26,23,18, 9),
c( 6, 7, 9,14,23)))
d.frm <- Untable(tab)
n <- 1000
idx <- matrix(sample(nrow(d.frm), size=nrow(d.frm) * n, replace=TRUE), ncol=n, byrow=FALSE)
v <- apply(idx, 2, function(x) CramerV(d.frm[x,1], d.frm[x,2]))
quantile(v, probs=c(0.025,0.975))
# compare this to the analytical ones
CramerV(tab, conf.level=0.95)
Run the code above in your browser using DataLab