Description Usage Arguments Details Value Author(s) References See Also Examples

Calculate Cramer's V, Pearson's contingency coefficient and phi,
Yule's Q and Y and Tschuprow's T of `x`

, if `x`

is a table. If both, `x`

and `y`

are given, then the according table will be built first.

1 2 3 4 5 6 7 8 |

`x` |
can be a numeric vector, a matrix or a table. |

`y` |
NULL (default) or a vector with compatible dimensions to |

`conf.level` |
confidence level of the interval. This is only implemented for Cramer's V. If set to |

`method` |
string defining the method to calculate confidence intervals for Cramer's V. One out of |

`correct` |
logical. This argument only applies to |

`...` |
further arguments are passed to the function |

For x either a matrix or two vectors `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 e.g. also 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 *√(min(r, c) - 1)*. The contingency coefficient goes from 0 to *√(\frac{min(r, c) - 1}{min(r, c)})*. For the corrected contingency coefficient and for Cramer's V the range is 0 to 1.

A Cramer's V in the range of [0, 0.3] is considered as weak, [0.3,0.7] as medium and > 0.7 as strong.
The minimum value for all is 0 under statistical independence.

a single numeric value if no confidence intervals are requested,

and otherwise a numeric vector with 3 elements for the estimate, the lower and the upper confidence interval

Andri Signorell <[email protected]>,

Michael Smithson <[email protected]> (confidence intervals for Cramer V)

Yule, G. Uday (1912) On the methods of measuring association between two attributes. *Journal of the Royal Statistical Society, LXXV*, 579-652

Tschuprow, A. A. (1939) *Principles of the Mathematical Theory of Correlation*, translated by M. Kantorowitsch. W. Hodge & Co.

Cramer, H. (1946) *Mathematical Methods of Statistics*. Princeton University Press

Agresti, Alan (1996) *Introduction to categorical data analysis*. NY: John Wiley and Sons

Sakoda, J.M. (1977) Measures of Association for Multivariate Contingency Tables,
*Proceedings of the Social Statistics Section of the American Statistical Association* (Part III), 777-780.

Smithson, M.J. (2003) *Confidence Intervals, Quantitative Applications in the Social Sciences Series*, No. 140. Thousand Oaks, CA: Sage. pp. 39-41

`table`

, `PlotCorr`

, `PairApply`

, `Assocs`

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | ```
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, symmetric = TRUE)
# useNA is passed to table
PairApply(d.pizza[,c("driver","operator","area")], CramerV,
useNA="ifany", symmetric = TRUE)
d.frm <- d.pizza[,c("driver","operator","area")]
PairApply(d.frm[complete.cases(d.frm),], CramerV, symmetric = TRUE)
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)
``` |

```
[1] 0.1328222
[1] 0.1316659
[1] 0.1328222
[1] 0.08486583
[1] 0.1328222
driver operator area
driver 1.0000000 0.23585686 0.65018461
operator 0.2358569 1.00000000 0.08670047
area 0.6501846 0.08670047 1.00000000
driver operator area
driver 1.0000000 0.20253639 0.53066544
operator 0.2025364 1.00000000 0.07847762
area 0.5306654 0.07847762 1.00000000
driver operator area
driver 1.0000000 0.2345141 0.6504665
operator 0.2345141 1.0000000 0.0869935
area 0.6504665 0.0869935 1.0000000
[1] 0.5555556
[1] 0.303337
2.5% 97.5%
0.2928624 0.5585503
Cramer V lwr.ci upr.ci
0.4064888 0.2211672 0.5410622
```

DescTools documentation built on March 19, 2018, 9:03 a.m.

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.