cramer_v() computes Cramer's V for a two-way contingency table,
measuring the strength of association between two categorical variables.
Arguments
- x
A contingency table (of class
table).- detail
Logical. If
FALSE(default), return the estimate as a numeric scalar. IfTRUE, return a named numeric vector including confidence interval and p-value.- conf_level
A number between 0 and 1 giving the confidence level (default
0.95). Only used whendetail = TRUE. Set toNULLto omit the confidence interval.- digits
Number of decimal places used when printing the result (default
3). Only affects thedetail = TRUEoutput.- .include_se
Internal parameter; do not use.
Value
When detail = FALSE: a single numeric value (the
estimate).
When detail = TRUE and conf_level is non-NULL:
c(estimate, ci_lower, ci_upper, p_value).
When detail = TRUE and conf_level = NULL:
c(estimate, p_value).
The p-value tests the null hypothesis of no association
(Pearson chi-squared test).
Details
Cramer's V is computed as
\(V = \sqrt{\chi^2 / (n \cdot (k - 1))}\), where \(\chi^2\)
is the Pearson chi-squared statistic, \(n\) is the total count,
and \(k = \min(r, c)\). The point estimate matches the
DescTools (Signorell et al., 2024) and SPSS implementations.
The confidence interval uses the Fisher z-transformation
on \(V\) (\(\tanh(\mathrm{atanh}(V) \pm z_{\alpha/2} /
\sqrt{n - 3})\)), which differs from the noncentral chi-squared
or bootstrap CIs reported by DescTools::CramerV().
References
Agresti, A. (2002). Categorical Data Analysis (2nd ed.). Wiley.
Liebetrau, A. M. (1983). Measures of Association. Sage.
Signorell, A. et al. (2024). DescTools: Tools for Descriptive Statistics. R package.
See also
phi(), contingency_coef(), assoc_measures()
Other association measures:
assoc_measures(),
contingency_coef(),
gamma_gk(),
goodman_kruskal_tau(),
kendall_tau_b(),
kendall_tau_c(),
lambda_gk(),
phi(),
somers_d(),
uncertainty_coef(),
yule_q()
Examples
tab <- table(sochealth$smoking, sochealth$education)
cramer_v(tab)
#> [1] 0.1356677
cramer_v(tab, detail = TRUE)
#> Estimate CI lower CI upper p
#> 0.136 0.079 0.191 <.001
cramer_v(tab, detail = TRUE, conf_level = NULL)
#> Estimate p
#> 0.136 <.001