Compute Analysis Results Data (ARD) for simple continuous summary statistics.

ard_summary(data, ...)

# S3 method for class 'data.frame'
ard_summary(
  data,
  variables,
  by = dplyr::group_vars(data),
  strata = NULL,
  statistic = everything() ~ continuous_summary_fns(),
  fmt_fun = NULL,
  stat_label = everything() ~ default_stat_labels(),
  fmt_fn = deprecated(),
  ...
)

Arguments

data

(data.frame)
a data frame

...

Arguments passed to methods.

variables

(tidy-select)
columns to include in summaries.

by, strata

(tidy-select)
columns to tabulate by/stratify by for summary statistic calculation. Arguments are similar, but with an important distinction:

by: results are calculated for all combinations of the columns specified, including unobserved combinations and unobserved factor levels.

strata: results are calculated for all observed combinations of the columns specified.

Arguments may be used in conjunction with one another.

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 = list(mean = \(x) mean(x))).

The value assigned to each variable must also be a named list, where the names are used to reference a function and the element is the function object. Typically, this function will return a scalar statistic, but a function that returns a named list of results is also acceptable, e.g. list(conf.low = -1, conf.high = 1). However, when errors occur, the messaging will be less clear in this setting.

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") or everything() ~ list(mean ~ "Mean", sd ~ "SD").

fmt_fn

[Deprecated]

Value

an ARD data frame of class 'card'

Examples

ard_summary(ADSL, by = "ARM", variables = "AGE")
#> # An ARD data frame: 24 × 10
#>    group1 group1_level       variable context stat_name stat_label  stat fmt_fun
#>    <chr>  <list>             <chr>    <chr>   <chr>     <chr>      <lis>  <list>
#>  1 ARM    Placebo            AGE      summary N         N          86          0
#>  2 ARM    Placebo            AGE      summary mean      Mean       75.2        1
#>  3 ARM    Placebo            AGE      summary sd        SD          8.59       1
#>  4 ARM    Placebo            AGE      summary median    Median     76          1
#>  5 ARM    Placebo            AGE      summary p25       Q1         69          1
#>  6 ARM    Placebo            AGE      summary p75       Q3         82          1
#>  7 ARM    Placebo            AGE      summary min       Min        52          1
#>  8 ARM    Placebo            AGE      summary max       Max        89          1
#>  9 ARM    Xanomeline High D… AGE      summary N         N          84          0
#> 10 ARM    Xanomeline High D… AGE      summary mean      Mean       74.4        1
#> # ℹ 14 more rows
#> # ℹ 2 more variables: warning <list>, error <list>

# if a single function returns a named list, the named
# results will be placed in the resulting ARD
ADSL |>
  dplyr::group_by(ARM) |>
  ard_summary(
    variables = "AGE",
    statistic =
      ~ list(conf.int = \(x) t.test(x)[["conf.int"]] |>
        as.list() |>
        setNames(c("conf.low", "conf.high")))
  )
#> # An ARD data frame: 6 × 10
#>   group1 group1_level        variable context stat_name stat_label  stat fmt_fun
#>   <chr>  <list>              <chr>    <chr>   <chr>     <chr>      <lis>  <list>
#> 1 ARM    Placebo             AGE      summary conf.low  conf.low    73.4       1
#> 2 ARM    Placebo             AGE      summary conf.high conf.high   77.1       1
#> 3 ARM    Xanomeline High Do… AGE      summary conf.low  conf.low    72.7       1
#> 4 ARM    Xanomeline High Do… AGE      summary conf.high conf.high   76.1       1
#> 5 ARM    Xanomeline Low Dose AGE      summary conf.low  conf.low    73.9       1
#> 6 ARM    Xanomeline Low Dose AGE      summary conf.high conf.high   77.5       1
#> # ℹ 2 more variables: warning <list>, error <list>