View source: R/tbl_hierarchical.R
tbl_hierarchical | R Documentation |
This is an preview of this function. There will be changes in the coming releases, and changes will not undergo a formal deprecation cycle.
Use these functions to generate hierarchical tables.
tbl_hierarchical()
: Calculates rates of events (e.g. adverse events)
utilizing the denominator
and id
arguments to identify the rows in data
to include in each rate calculation. If variables
contains more than one
variable and the last variable in variables
is an ordered factor, then
rates of events by highest level will be calculated.
tbl_hierarchical_count()
: Calculates counts of events utilizing
all rows for each tabulation.
tbl_hierarchical(
data,
variables,
by = NULL,
id = NULL,
denominator = NULL,
include = everything(),
statistic = "{n} ({p})",
overall_row = FALSE,
label = NULL
)
tbl_hierarchical_count(
data,
variables,
by = NULL,
denominator = NULL,
include = everything(),
overall_row = FALSE,
label = NULL
)
data |
( |
variables |
( |
by |
( |
id |
( |
denominator |
( |
include |
( |
statistic |
( |
overall_row |
(scalar |
label |
( |
a gtsummary table of class "tbl_hierarchical"
(for tbl_hierarchical()
) or "tbl_hierarchical_count"
(for tbl_hierarchical_count()
).
An overall row can be added to the table as the first row by specifying overall_row = TRUE
. Assuming that each row
in data
corresponds to one event record, this row will count the overall number of events recorded when used in
tbl_hierarchical_count()
, or the overall number of patients recorded with any event when used in
tbl_hierarchical()
.
A label for this overall row can be specified by passing an overall
element in label
. If no overall
label has
been set and overall_row = TRUE
, "Total number of patients with any event"
will be used by tbl_hierarchical()
and "Total number of events"
will be used by tbl_hierarchical_count()
.
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 --------------------
tbl_hierarchical(
data = ADAE_subset,
variables = c(AESOC, AETERM),
by = TRTA,
denominator = cards::ADSL |> mutate(TRTA = ARM),
id = USUBJID,
overall_row = TRUE
)
# Example 2 - Rates by Highest Severity ------
tbl_hierarchical(
data = ADAE_subset |> mutate(AESEV = factor(AESEV, ordered = TRUE)),
variables = c(AESOC, AESEV),
by = TRTA,
id = USUBJID,
denominator = cards::ADSL |> mutate(TRTA = ARM),
include = AESEV,
label = list(AESEV = "Highest Severity")
)
# Example 3 - Event Counts -------------------
tbl_hierarchical_count(
data = ADAE_subset,
variables = c(AESOC, AETERM, AESEV),
by = TRTA,
overall_row = TRUE
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.