
ARD Categorical Survey Statistics
Source:R/ard_tabulate.survey.design.R
ard_tabulate.survey.design.RdCompute tabulations on survey-weighted data.
The counts and proportion ("N", "n", "p") are calculated using survey::svytable(),
and the standard errors and design effect ("p.std.error", "deff") are
calculated using survey::svymean().
The design effect ("deff") is calculated only when requested in the statistic argument.
The unweighted statistics are calculated with cards::ard_tabulate.data.frame().
Usage
# S3 method for class 'survey.design'
ard_tabulate(
data,
variables,
by = NULL,
statistic = everything() ~ c("n", "N", "p", "p.std.error", "n_unweighted",
"N_unweighted", "p_unweighted"),
denominator = c("column", "row", "cell"),
fmt_fun = NULL,
stat_label = everything() ~ list(p = "%", p.std.error = "SE(%)", deff =
"Design Effect", n_unweighted = "Unweighted n", N_unweighted = "Unweighted N",
p_unweighted = "Unweighted %"),
fmt_fn = deprecated(),
...
)Arguments
- data
(
survey.design)
a design object often created withsurvey::svydesign().- variables
(
tidy-select)
columns to include in summaries.- by
(
tidy-select)
results are calculated for all combinations of the column specified and the variables. A single column may be specified.- statistic
(
formula-list-selector)
a named list, a list of formulas, or a single formula where the list element is a character vector of statistic names to include. See default value for options.- denominator
(
string)
a string indicating the type proportions to calculate. Must be one of"column"(the default),"row", and"cell".- fmt_fun
(
formula-list-selector)
a named list, a list of formulas, or a single formula where the list element is a named list of functions (or the RHS of a formula), e.g.list(mpg = list(mean = \(x) round(x, digits = 2) |> as.character())).- stat_label
(
formula-list-selector)
a named list, a list of formulas, or a single formula where the list element is either a named list or a list of formulas defining the statistic labels, e.g.everything() ~ list(mean = "Mean", sd = "SD")oreverything() ~ list(mean ~ "Mean", sd ~ "SD").- fmt_fn
- ...
These dots are for future extensions and must be empty.
Examples
svy_titanic <- survey::svydesign(~1, data = as.data.frame(Titanic), weights = ~Freq)
ard_tabulate(svy_titanic, variables = c(Class, Age), by = Survived)
#> {cards} data frame: 84 x 11
#> group1 group1_level variable variable_level stat_name stat_label stat
#> 1 Survived No Class 1st n n 122
#> 2 Survived No Class 1st N N 1490
#> 3 Survived No Class 1st p % 0.082
#> 4 Survived No Class 1st p.std.error SE(%) 0.086
#> 5 Survived No Class 2nd n n 167
#> 6 Survived No Class 2nd N N 1490
#> 7 Survived No Class 2nd p % 0.112
#> 8 Survived No Class 2nd p.std.error SE(%) 0.111
#> 9 Survived No Class 3rd n n 528
#> 10 Survived No Class 3rd N N 1490
#> ℹ 74 more rows
#> ℹ Use `print(n = ...)` to see more rows
#> ℹ 4 more variables: context, fmt_fun, warning, error