Computes bivariate statistics for a set of variables according to the subgroups of observations defined by a categorical variable.

cattab(x, y, weights = NULL, percent = "column",
       robust = TRUE, show.n = TRUE, show.asso = TRUE,
       digits = c(1,1), na.rm = TRUE, na.value = "NAs")

Arguments

x

data frame. The variables which are described in rows. They can be numerical or factors.

y

factor. The categorical variable which defines subgroups of observations described in columns.

weights

numeric vector of weights. If NULL (default), uniform weights (i.e. all equal to 1) are used.

percent

character. Whether to compute row percentages ("row") or column percentages ("column", default).

robust

logical. Whether to use medians instead of means. Default is TRUE.

show.n

logical. Whether to display frequencies (between brackets) in addition to the percentages. Default is TRUE.

show.asso

logical. Whether to add a column with measures of global association (Cramer's V and eta-squared). Default is TRUE.

digits

vector of 2 integers. The first value sets the number of digits for percentages, the second one sets the number of digits for medians and means. Default is c(1,1). If NULL, the results are not rounded.

na.rm

logical, indicating whether NA values should be silently removed before the computation proceeds. If FALSE (default), an additional level is added to the variables (see na.value argument).

na.value

character. Name of the level for NA category. Default is "NAs". Only used if na.rm = FALSE.

Details

The function uses gtsummary package to build the table of statistics, and then gt package to finalize the layout. Weights are handled silently with survey package.

Besides, the function is compatible with the attribute labels assigned with labelled package : these labels are displayed automatically.

Note

This function is quite similar to profiles, but displays the results in a fancier way.

Value

An object of class gt_tbl.

Author

Nicolas Robette

Examples

data(Movies)
cattab(x = Movies[, c("Genre", "ArtHouse", "Critics", "BoxOffice")],
       y = Movies$Country)