cat_compare {tldr} | R Documentation |
Investigate association between two categorical variables
Description
cat_compare
gives details about the association between two categorical variables.
Usage
cat_compare(x, y, plot = TRUE)
Arguments
x |
A categorical variable: the predictor or group variable, if appropriate |
y |
A categorical variable: the outcome, if appropriate |
plot |
Logical. Whether a mosaic plot should be drawn |
Details
Strictly, x and y do not need to be factors but will be coerced into factors.
Value
Returns a list including (1) two-way table of counts, (2) chi-squared test for independence, (3) Cramer's V standardized effect, and (4) ggplot2 column plot of proportions conditional on x, if requested.
The table of counts will include missing values of both variables, but these rows/columns are discarded prior to the chi-squared test and Cramer's V calculations.
Examples
v1 = rbinom(n=50, size=1, p=0.5)
v2 = rbinom(n=50, size=2, p=0.3 + 0.2*v1)
cat_compare(x=v1, y=v2, plot=TRUE)
[Package tldr version 0.4.0 Index]