tab_cross {surveytable} | R Documentation |
Tabulate subsets or interactions
Description
Create subsets of the survey using one variable, and tabulate another variable within each of the subsets. Interact two variables and tabulate.
Usage
tab_cross(
vr,
vrby,
max_levels = getOption("surveytable.max_levels"),
csv = getOption("surveytable.csv")
)
tab_subset(
vr,
vrby,
lvls = c(),
test = FALSE,
alpha = 0.05,
p_adjust = FALSE,
drop_na = getOption("surveytable.drop_na"),
max_levels = getOption("surveytable.max_levels"),
csv = getOption("surveytable.csv")
)
Arguments
vr |
variable to tabulate |
vrby |
use this variable to subset the survey |
max_levels |
a categorical variable can have at most this many levels. Used to avoid printing huge tables. |
csv |
name of a CSV file |
lvls |
(optional) only show these levels of |
test |
perform hypothesis tests? |
alpha |
significance level for tests |
p_adjust |
adjust p-values for multiple comparisons? |
drop_na |
drop missing values ( |
Details
tab_subset
creates subsets using the levels of vrby
, and tabulates
vr
in each subset. Optionally, only use the lvls
levels of vrby
.
vr
can be categorical (factor), logical, or numeric.
tab_cross
crosses or interacts vr
and vrby
and tabulates the new
variable. Tables created using tab_subset
and tab_cross
have the same
counts but different percentages. With tab_subset
, percentages within each
subset add up to 100%. With tab_cross
, percentages across the entire
population add up to 100%. Also see var_cross()
.
test = TRUE
performs a test of association between the two variables. Also
performs t-tests for all possible pairs of levels of vr
and vrby
.
Value
A list of tables or a single table.
See Also
Other tables:
tab()
,
tab_rate()
,
tab_subset_rate()
,
total()
,
total_rate()
Examples
set_survey(namcs2019sv)
# For each SEX, tabulate AGER
tab_subset("AGER", "SEX")
# Same counts as tab_subset(), but different percentages.
tab_cross("AGER", "SEX")
# Numeric variables
tab_subset("NUMMED", "AGER")
# Hypothesis testing
tab_subset("NUMMED", "AGER", test = TRUE)