A mix of adverse event rates (from gtsummary::tbl_hierarchical()) and counts (from gtsummary::tbl_hierarchical_count()). The function produces additional summary rows for the higher level nesting variables providing both rates and counts.

When a hierarchical summary is filtered, the summary rows no longer provide useful/consistent information. When creating a filtered summary, use gtsummary::tbl_hierarchical() or gtsummary::tbl_hierarchical_count() directly, followed by a call to gtsummary::filter_hierarchical().

tbl_hierarchical_rate_and_count(
  data,
  variables,
  denominator,
  by = NULL,
  id = "USUBJID",
  digits = NULL,
  sort = NULL,
  label_overall_rate = "Total number of participants with at least one adverse event",
  label_overall_count = "Overall total number of events",
  label_rate = "Total number of participants with at least one adverse event",
  label_count = "Total number of events"
)

# S3 method for class 'tbl_hierarchical_rate_and_count'
add_overall(
  x,
  last = FALSE,
  col_label = "All Participants  \n(N = {style_number(N)})",
  ...
)

Arguments

data

(data.frame)
a data frame.

variables

(tidy-select)
Hierarchical variables to summarize. Must be 2 or 3 variables. Typical inputs are c(AEBODSYS, AEDECOD) for an SOC/AE summary or c(AEBODSYS, AEHLT, AEDECOD) for an SOC/HLT/AE summary.

Variables must be specified in the nesting order.

denominator

(data.frame, integer)
used to define the denominator and enhance the output. The argument is required for tbl_hierarchical() and optional for tbl_hierarchical_count(). The denominator argument must be specified when id is used to calculate event rates.

by

(tidy-select)
a single column from data. Summary statistics will be stratified by this variable. Default is NULL.

id

(tidy-select)
argument used to subset data to identify rows in data to calculate event rates in tbl_hierarchical().

digits

(formula-list-selector)
Specifies how summary statistics are rounded. Values may be either integer(s) or function(s). If a theme is applied, the digits specifications of the theme is applied.

sort

Optional arguments passed to gtsummary::sort_hierarchical(sort).

label_overall_rate

(string)
String for the overall rate summary. Default is "Total number of participants with at least one adverse event".

label_overall_count

(string)
String for the overall count summary. Default is "Overall total number of events".

label_rate

(string)
String for the rate summary. Default is "Overall total number of events". "Total number of participants with at least one adverse event".

label_count

(string)
String for the overall count summary. Default is "Total number of events".

x

(tbl_hierarchical_rate_and_count)
a stratified 'tbl_hierarchical_rate_and_count' table

last

(scalar logical)
Logical indicator to display overall column last in table. Default is FALSE, which will display overall column first.

col_label

(string)
String indicating the column label. Default is "**Overall** \nN = {style_number(N)}"

...

These dots are for future extensions and must be empty.

Value

a gtsummary table

Examples

# Example 1 ----------------------------------
cards::ADAE[c(1, 2, 3, 8, 16), ] |>
  tbl_hierarchical_rate_and_count(
    variables = c(AEBODSYS, AEDECOD),
    denominator = cards::ADSL,
    by = TRTA
  ) |>
  add_overall(last = TRUE)
Body System or Organ Class
    Dictionary-Derived Term
Placebo
(N = 86)
Xanomeline High Dose
(N = 84)
Xanomeline Low Dose
(N = 84)
All Participants
(N = 254)
Total number of participants with at least one adverse event 1 (1.2%) 1 (1.2%) 1 (1.2%) 3 (1.2%)
Overall total number of events 3 1 1 5
GASTROINTESTINAL DISORDERS



    Total number of participants with at least one adverse event 1 (1.2%) 0 0 1 (0.4%)
    Total number of events 1 0 0 1
    DIARRHOEA 1 (1.2%) 0 0 1 (0.4%)
GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS



    Total number of participants with at least one adverse event 1 (1.2%) 1 (1.2%) 0 2 (0.8%)
    Total number of events 2 1 0 3
    APPLICATION SITE ERYTHEMA 1 (1.2%) 1 (1.2%) 0 2 (0.8%)
    APPLICATION SITE PRURITUS 1 (1.2%) 0 0 1 (0.4%)
SKIN AND SUBCUTANEOUS TISSUE DISORDERS



    Total number of participants with at least one adverse event 0 0 1 (1.2%) 1 (0.4%)
    Total number of events 0 0 1 1
    ERYTHEMA 0 0 1 (1.2%) 1 (0.4%)