cramerV.RdCalculates Cramer's V for a table of nominal variables; confidence intervals by bootstrap.
cramerV(
x,
y = NULL,
ci = FALSE,
conf = 0.95,
type = "perc",
R = 1000,
histogram = FALSE,
digits = 4,
bias.correct = FALSE,
reportIncomplete = FALSE,
verbose = FALSE,
tolerance = 1e-16,
...
)Either a two-way table or a two-way matrix. Can also be a vector of observations for one dimension of a two-way table.
If x is a vector, y is the vector of observations for
the second dimension of a two-way table.
If TRUE, returns confidence intervals by bootstrap.
May be slow.
The level for the confidence interval.
The type of confidence interval to use.
Can be any of "norm", "basic",
"perc", or "bca".
Passed to boot.ci.
The number of replications to use for bootstrap.
If TRUE, produces a histogram of bootstrapped values.
The number of significant digits in the output.
If TRUE, a bias correction is applied.
If FALSE (the default),
NA will be reported in cases where there
are instances of the calculation of the statistic
failing during the bootstrap procedure.
If TRUE, prints additional statistics.
If the variance of the bootstrapped values are less than
tolerance, NA is returned for the confidence interval
values.
Additional arguments passed to chisq.test.
A single statistic, Cramer's V. Or a small data frame consisting of Cramer's V, and the lower and upper confidence limits.
Cramer's V is used as a measure of association between two nominal variables, or as an effect size for a chi-square test of association. For a 2 x 2 table, the absolute value of the phi statistic is the same as Cramer's V.
Because V is always positive, if type="perc",
the confidence interval will
never cross zero. In this case,
the confidence interval range should not
be used for statistical inference.
However, if type="norm", the confidence interval
may cross zero.
When V is close to 0 or very large, or with small counts, the confidence intervals determined by this method may not be reliable, or the procedure may fail.
### Example with table
data(Anderson)
fisher.test(Anderson)
#>
#> Fisher's Exact Test for Count Data
#>
#> data: Anderson
#> p-value = 0.000668
#> alternative hypothesis: two.sided
#>
cramerV(Anderson)
#> Cramer V
#> 0.4387
### Example with two vectors
Species = c(rep("Species1", 16), rep("Species2", 16))
Color = c(rep(c("blue", "blue", "blue", "green"),4),
rep(c("green", "green", "green", "blue"),4))
fisher.test(Species, Color)
#>
#> Fisher's Exact Test for Count Data
#>
#> data: Species and Color
#> p-value = 0.01211
#> alternative hypothesis: true odds ratio is not equal to 1
#> 95 percent confidence interval:
#> 1.463598 60.596055
#> sample estimates:
#> odds ratio
#> 8.279362
#>
cramerV(Species, Color)
#> Cramer V
#> 0.5