Compute Analysis Results Data (ARD) for dichotomous summary statistics.
Usage
ard_dichotomous(
data,
variables,
by = dplyr::group_vars(data),
strata = NULL,
value = maximum_variable_value(data[variables]),
statistic = everything() ~ categorical_summary_fns(),
denominator = NULL,
fmt_fn = NULL,
stat_label = everything() ~ default_stat_labels()
)
Arguments
- data
(
data.frame
)
a data frame- variables
(
tidy-select
)
columns to include in summaries. Default iseverything()
.- by, strata
-
(
tidy-select
)
columns to tabulate by/stratify by for tabulation. Arguments are similar, but with an important distinction:by
: results are tabulated by all combinations of the columns specified, including unobserved combinations and unobserved factor levels.strata
: results are tabulated by all observed combinations of the columns specified.Arguments may be used in conjunction with one another.
- value
(named
list
)
named list of dichotomous values to tabulate. Default ismaximum_variable_value(data)
, which returns the largest/last value after a sort.- statistic
(
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 = categorical_summary_fns())
.- denominator
(
data.frame
,integer
)
Specify this optional argument to change the denominator, e.g. the"N"
statistic. Default isNULL
. See below for details.- fmt_fn
(
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(n = "n", p = "pct")
oreverything() ~ list(n ~ "n", p ~ "pct")
.
Examples
ard_dichotomous(mtcars, by = vs, variables = c(cyl, am), value = list(cyl = 4))
#> {cards} data frame: 12 x 11
#> group1 group1_level variable variable_level stat_name stat_label stat
#> 1 vs 0 cyl 4 n n 1
#> 2 vs 0 cyl 4 N N 18
#> 3 vs 0 cyl 4 p % 0.056
#> 4 vs 1 cyl 4 n n 10
#> 5 vs 1 cyl 4 N N 14
#> 6 vs 1 cyl 4 p % 0.714
#> 7 vs 0 am 1 n n 6
#> 8 vs 0 am 1 N N 18
#> 9 vs 0 am 1 p % 0.333
#> 10 vs 1 am 1 n n 7
#> 11 vs 1 am 1 N N 14
#> 12 vs 1 am 1 p % 0.5
#> ℹ 4 more variables: context, fmt_fn, warning, error
mtcars |>
dplyr::group_by(vs) |>
ard_dichotomous(
variables = c(cyl, am),
value = list(cyl = 4),
statistic = ~ categorical_summary_fns("p")
)
#> {cards} data frame: 4 x 11
#> group1 group1_level variable variable_level stat_name stat_label stat
#> 1 vs 0 cyl 4 p % 0.056
#> 2 vs 1 cyl 4 p % 0.714
#> 3 vs 0 am 1 p % 0.333
#> 4 vs 1 am 1 p % 0.5
#> ℹ 4 more variables: context, fmt_fn, warning, error