Learn R Programming

tldr (version 0.3.0)

cat_compare: 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)

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.

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.

Examples

Run this code
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)

Run the code above in your browser using DataLab