Skip to contents

Suppose you need to create the table below, and need an ARD representation of the results to get started. Here, we will review an examples for creating a basic demographics table.

To get started, load the {cards} package.

Demographics

Characteristic Placebo
N = 86
Xanomeline Low Dose
N = 84
Xanomeline High Dose
N = 84
Age


    Median (IQR) 76 (69, 82) 78 (71, 82) 76 (71, 80)
    Mean (SD) 75 (9) 76 (8) 74 (8)
    Range 52 - 89 51 - 88 56 - 88
Age Group, n (%)


    <65 14 (16%) 8 (10%) 11 (13%)
    65-80 42 (49%) 47 (56%) 55 (65%)
    >80 30 (35%) 29 (35%) 18 (21%)
Female, n (%) 53 (62%) 50 (60%) 40 (48%)

The table above has three types of data summaries: a continuous variable summary for AGE, a categorical variable summary for AGEGR1, and a dichotomous variable summary for SEX.

Continuous Summaries

To get a continuous variable summary, we will use the ard_continuous() function from the {cards} package.

df_continuous_ard <-
  ard_continuous(
    ADSL,
    by = ARM,
    variables = AGE,
    statistic = ~ continuous_summary_fns(c("median", "p25", "p75", "mean", "sd", "min", "max"))
  )
df_continuous_ard |> head(5)
#> {cards} data frame: 5 x 10
#>   group1 group1_level variable stat_name stat_label   stat
#> 1    ARM      Placebo      AGE    median     Median     76
#> 2    ARM      Placebo      AGE       p25  25th Per…     69
#> 3    ARM      Placebo      AGE       p75  75th Per…     82
#> 4    ARM      Placebo      AGE      mean       Mean 75.209
#> 5    ARM      Placebo      AGE        sd         SD   8.59
#>  4 more variables: context, fmt_fn, warning, error

Categorical Summaries

To get the categorical variable summary, we will use the ard_categorical() function.

df_categoircal_ard <-
  ard_categorical(
    ADSL,
    by = ARM,
    variables = AGEGR1
  )
df_categoircal_ard |> head(5)
#> {cards} data frame: 5 x 11
#>   group1 group1_level variable variable_level stat_name stat_label  stat
#> 1    ARM      Placebo   AGEGR1            <65         n          n    14
#> 2    ARM      Placebo   AGEGR1            <65         N          N    86
#> 3    ARM      Placebo   AGEGR1            <65         p          % 0.163
#> 4    ARM    Xanomeli…   AGEGR1            <65         n          n    11
#> 5    ARM    Xanomeli…   AGEGR1            <65         N          N    84
#>  4 more variables: context, fmt_fn, warning, error

Dichotomous Summaries

To get the dichotomous variable summary, we will use ard_dichotomous(). In this case, we want to show the Female ("F") level of the SEX variable and specify this with the values argument.

df_dichotomous_ard <-
  ard_dichotomous(
    ADSL,
    by = ARM,
    variables = SEX,
    value = list(SEX = "F")
  )
df_dichotomous_ard |> head(5)
#> {cards} data frame: 5 x 11
#>   group1 group1_level variable variable_level stat_name stat_label  stat
#> 1    ARM      Placebo      SEX              F         n          n    53
#> 2    ARM      Placebo      SEX              F         N          N    86
#> 3    ARM      Placebo      SEX              F         p          % 0.616
#> 4    ARM    Xanomeli…      SEX              F         n          n    40
#> 5    ARM    Xanomeli…      SEX              F         N          N    84
#>  4 more variables: context, fmt_fn, warning, error

Combine Results

As a last step, you can combine all of these objects into a single object using bind_ard(), which is similar to dplyr::bind_rows() and includes additional structural checks for our results.

bind_ard(
  df_continuous_ard,
  df_categoircal_ard,
  df_dichotomous_ard
)
#> {cards} data frame: 57 x 11
#>    group1 group1_level variable variable_level stat_name stat_label   stat
#> 1     ARM      Placebo      AGE                   median     Median     76
#> 2     ARM      Placebo      AGE                      p25  25th Per…     69
#> 3     ARM      Placebo      AGE                      p75  75th Per…     82
#> 4     ARM      Placebo      AGE                     mean       Mean 75.209
#> 5     ARM      Placebo      AGE                       sd         SD   8.59
#> 6     ARM      Placebo      AGE                      min        Min     52
#> 7     ARM      Placebo      AGE                      max        Max     89
#> 8     ARM    Xanomeli…      AGE                   median     Median     76
#> 9     ARM    Xanomeli…      AGE                      p25  25th Per…   70.5
#> 10    ARM    Xanomeli…      AGE                      p75  75th Per…     80
#>  47 more rows
#>  Use `print(n = ...)` to see more rows
#>  4 more variables: context, fmt_fn, warning, error

Shortcut

The ard_stack() function provides a shortcut to perform the calculations above in a single step.

In the example below, the data and by arguments are passed to each subsequent ard_*() function call. Moreover, we will also be returned the univariate tabulation of the by variable, which would be used to add counts to the header row of the table.

ard_stack(
  data = ADSL,
  by = ARM,
  ard_continuous(
    variables = AGE,
    statistic = ~ continuous_summary_fns(c("median", "p25", "p75", "mean", "sd", "min", "max"))
  ),
  ard_categorical(variables = AGEGR1),
  ard_dichotomous(variables = SEX, value = list(SEX = "F"))
)
#> {cards} data frame: 60 x 11
#>    group1 group1_level variable variable_level stat_name stat_label   stat
#> 1     ARM      Placebo      AGE                   median     Median     76
#> 2     ARM      Placebo      AGE                      p25  25th Per…     69
#> 3     ARM      Placebo      AGE                      p75  75th Per…     82
#> 4     ARM      Placebo      AGE                     mean       Mean 75.209
#> 5     ARM      Placebo      AGE                       sd         SD   8.59
#> 6     ARM      Placebo      AGE                      min        Min     52
#> 7     ARM      Placebo      AGE                      max        Max     89
#> 8     ARM    Xanomeli…      AGE                   median     Median     76
#> 9     ARM    Xanomeli…      AGE                      p25  25th Per…   70.5
#> 10    ARM    Xanomeli…      AGE                      p75  75th Per…     80
#>  50 more rows
#>  Use `print(n = ...)` to see more rows
#>  4 more variables: context, fmt_fn, warning, error

Adverse Events

Example Coming Soon!