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<U+2026>     69
#> 3    ARM      Placebo      AGE       p75 75th Per<U+2026>     82
#> 4    ARM      Placebo      AGE      mean             Mean 75.209
#> 5    ARM      Placebo      AGE        sd               SD   8.59
#> i 4 more variables: context, fmt_fn, warning, error

Categorical Summaries

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

df_categorical_ard <-
  ard_categorical(
    ADSL,
    by = ARM,
    variables = AGEGR1
  )
df_categorical_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-80         n          n    42
#> 2    ARM          Placebo   AGEGR1          65-80         N          N    86
#> 3    ARM          Placebo   AGEGR1          65-80         p          % 0.488
#> 4    ARM Xanomeli<U+2026>   AGEGR1          65-80         n          n    55
#> 5    ARM Xanomeli<U+2026>   AGEGR1          65-80         N          N    84
#> i 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<U+2026>      SEX              F         n          n    40
#> 5    ARM Xanomeli<U+2026>      SEX              F         N          N    84
#> i 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_categorical_ard,
  df_dichotomous_ard
)
#> {cards} data frame: 57 x 11
#>    group1     group1_level variable variable_level stat_name       stat_label
#> 1     ARM          Placebo      AGE                   median           Median
#> 2     ARM          Placebo      AGE                      p25 25th Per<U+2026>
#> 3     ARM          Placebo      AGE                      p75 75th Per<U+2026>
#> 4     ARM          Placebo      AGE                     mean             Mean
#> 5     ARM          Placebo      AGE                       sd               SD
#> 6     ARM          Placebo      AGE                      min              Min
#> 7     ARM          Placebo      AGE                      max              Max
#> 8     ARM Xanomeli<U+2026>      AGE                   median           Median
#> 9     ARM Xanomeli<U+2026>      AGE                      p25 25th Per<U+2026>
#> 10    ARM Xanomeli<U+2026>      AGE                      p75 75th Per<U+2026>
#>      stat
#> 1      76
#> 2      69
#> 3      82
#> 4  75.209
#> 5    8.59
#> 6      52
#> 7      89
#> 8      76
#> 9    70.5
#> 10     80
#> i 47 more rows
#> i Use `print(n = ...)` to see more rows
#> i 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: 66 x 11
#>    group1     group1_level variable variable_level stat_name       stat_label
#> 1     ARM          Placebo      AGE                   median           Median
#> 2     ARM          Placebo      AGE                      p25 25th Per<U+2026>
#> 3     ARM          Placebo      AGE                      p75 75th Per<U+2026>
#> 4     ARM          Placebo      AGE                     mean             Mean
#> 5     ARM          Placebo      AGE                       sd               SD
#> 6     ARM          Placebo      AGE                      min              Min
#> 7     ARM          Placebo      AGE                      max              Max
#> 8     ARM Xanomeli<U+2026>      AGE                   median           Median
#> 9     ARM Xanomeli<U+2026>      AGE                      p25 25th Per<U+2026>
#> 10    ARM Xanomeli<U+2026>      AGE                      p75 75th Per<U+2026>
#>      stat
#> 1      76
#> 2      69
#> 3      82
#> 4  75.209
#> 5    8.59
#> 6      52
#> 7      89
#> 8      76
#> 9    70.5
#> 10     80
#> i 56 more rows
#> i Use `print(n = ...)` to see more rows
#> i 4 more variables: context, fmt_fn, warning, error

Adverse Events

Example Coming Soon!