This is a preview of this function. There will be changes in the coming releases, and changes will not undergo a formal deprecation cycle.
Constructs tables from nested or hierarchical data structures (e.g. adverse events).
Usage
tbl_ard_hierarchical(
cards,
variables,
by = NULL,
include = everything(),
statistic = ~"{n} ({p}%)",
overall_row = FALSE,
label = NULL
)Arguments
- cards
(
card)
An ARD object of class"card"typically created withcards::ard_*()functions.- variables
(
tidy-select)
character vector or tidy-selector of columns indataused to create a hierarchy. Hierarchy will be built with variables in the order given.- by
(
tidy-select)
a single column fromdata. Summary statistics will be stratified by this variable. Default isNULL.- include
(
tidy-select)
columns from thevariablesargument for which summary statistics should be returned (on the variable label rows). Including the last element ofvariableshas no effect since each level has its own row for this variable. The default iseverything().- statistic
(
formula-list-selector)
used to specify the summary statistics to display for all variables intbl_hierarchical(). The default iseverything() ~ "{n} ({p})".- overall_row
(scalar
logical)
whether an overall summary row should be included at the top of the table. The default isFALSE.- label
(
formula-list-selector)
used to override default labels in hierarchical table, e.g.list(AESOC = "System Organ Class"). The default for each variable is the label saved in the ARD (e.g. when created withcards::ard_stack_hierarchical(attributes = TRUE)). If no label is present, the column name is used.
Overall Row
An overall row can be added to the table as the first row by specifying overall_row = TRUE.
The cards object must contain the overall results, which are calculated by
cards::ard_stack_hierarchical(over_variables = TRUE) and cards::ard_stack_hierarchical_count(over_variables = TRUE).
A label for this overall row can be specified by passing an '..ard_hierarchical_overall..' element in label.
Examples
ADAE_subset <- cards::ADAE |>
dplyr::filter(
AESOC %in% unique(cards::ADAE$AESOC)[1:5],
AETERM %in% unique(cards::ADAE$AETERM)[1:5]
)
# Example 1: Event Rates --------------------
# First, build the ARD
ard <-
cards::ard_stack_hierarchical(
data = ADAE_subset,
variables = c(AESOC, AETERM),
by = TRTA,
denominator = cards::ADSL,
id = USUBJID,
over_variables = TRUE,
attributes = TRUE
)
# Second, build table from the ARD
tbl_ard_hierarchical(
cards = ard,
variables = c(AESOC, AETERM),
by = TRTA,
overall_row = TRUE,
label = list(..ard_hierarchical_overall.. = "Any Adverse Event")
)
Primary System Organ Class
Reported Term for the Adverse Event
Placebo
N = 861
Xanomeline High Dose
N = 841
Xanomeline Low Dose
N = 841
1 n (%)
# Example 2: Event Counts -------------------
ard <-
cards::ard_stack_hierarchical_count(
data = ADAE_subset,
variables = c(AESOC, AETERM),
by = TRTA,
denominator = cards::ADSL
)
tbl_ard_hierarchical(
cards = ard,
variables = c(AESOC, AETERM),
by = TRTA,
statistic = ~"{n}"
)
AESOC
AETERM
Placebo
N = 861
Xanomeline High Dose
N = 841
Xanomeline Low Dose
N = 841
1 n
