A wrapper function for gtsummary::tbl_hierarchical() to calculate rates of highest toxicity grades with the options to add rows for grade groups and additional summary sections at each variable level.

Only the highest grade level recorded for each subject will be analyzed. Prior to running the function, ensure that the toxicity grade variable (grade) is a factor variable, with factor levels ordered lowest to highest.

Grades will appear in rows in the order of the factor levels given, with each grade group appearing prior to the first level in its group.

tbl_hierarchical_rate_by_grade(
  data,
  variables,
  denominator,
  by = NULL,
  id = "USUBJID",
  include_overall = everything(),
  statistic = everything() ~ "{n} ({p}%)",
  label = NULL,
  digits = NULL,
  sort = "alphanumeric",
  filter = NULL,
  grade_groups = list(),
  grades_exclude = NULL,
  keep_zero_rows = FALSE
)

# S3 method for class 'tbl_hierarchical_rate_by_grade'
add_overall(
  x,
  last = FALSE,
  col_label = "**Overall**  \nN = {style_number(N)}",
  statistic = NULL,
  digits = NULL,
  ...
)

Arguments

data

(data.frame)
a data frame.

variables

(tidy-select)
A character vector or tidy-selector of 3 columns in data specifying a system organ class variable, an adverse event terms variable, and a toxicity grade level variable, respectively.

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().

include_overall

(tidy-select)
Variables from variables for which an overall section at that hierarchy level should be computed. An overall section at the SOC variable level will have label "- Any adverse events -". An overall section at the AE term variable level will have label "- Overall -". If the grade level variable is included it has no effect. The default is everything().

statistic

(formula-list-selector)
used to specify the summary statistics to display for all variables in tbl_hierarchical(). The default is everything() ~ "{n} ({p})".

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 column label attribute, attr(., 'label'). If no label has been set, the column name is used.

digits

(formula-list-selector)
specifies how summary statistics are rounded. Values may be either integer(s) or function(s). If not specified, default formatting is assigned via label_style_number() for statistics n and N, and label_style_percent(digits=1) for statistic p.

sort

(formula-list-selector, string)
a named list, a list of formulas, a single formula where the list element is a named list of functions (or the RHS of a formula), or a string specifying the types of sorting to perform at each hierarchy level. If the sort method for any variable is not specified then the method will default to "descending". If a single unnamed string is supplied it is applied to all hierarchy levels. For each variable, the value specified must be one of:

  • "alphanumeric" - at the specified hierarchy level, groups are ordered alphanumerically (i.e. A to Z) by variable_level text.

  • "descending" - at the specified hierarchy level, count sums are calculated for each row and rows are sorted in descending order by sum. If sort is "descending" for a given variable and n is included in statistic for the variable then n is used to calculate row sums, otherwise p is used. If neither n nor p are present in x for the variable, an error will occur.

Defaults to everything() ~ "descending".

filter

(expression)
An expression that is used to filter rows of the table. Filter will be applied to the second variable (adverse event terms) specified via variables. See the Details section below for more information.

grade_groups

(named list)
A named list of grade groups for which rates should be calculated. Grade groups must be mutually exclusive, i.e. each grade cannot be assigned to more than one grade group. Each grade group must be specified in the list as a character vector of the grades included in the grade group, named with the corresponding name of the grade group, e.g. "Grade 1-2" = c("1", "2").

grades_exclude

(character)
A vector of grades to omit individual rows for when printing the table. These grades will still be used when computing overall totals and grade group totals. For example, to avoid duplication, if a grade group is defined as "Grade 5" = "5", the individual rows corresponding to grade 5 can be excluded by setting grades_exclude = "5".

keep_zero_rows

(logical)
Whether rows containing zero rates across all columns should be kept. If FALSE, this filter will be applied prior to any filters specified via the filter argument which may still remove these rows. Defaults to FALSE.

x

(tbl_hierarchical_rate_by_grade)
A gtsummary table of class 'tbl_hierarchical_rate_by_grade'.

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 of class "tbl_hierarchical_rate_by_grade".

Details

When using the filter argument, the filter will be applied to the second variable from variables, i.e. the adverse event terms variable. If an AE does not meet the filtering criteria, the AE overall row as well as all grade and grade group rows within an AE section will be excluded from the table. Filtering out AEs does not exclude the records corresponding to these filtered out rows from being included in rate calculations for overall sections. If all AEs for a given SOC have been filtered out, the SOC will be excluded from the table. If all AEs are filtered out and the SOC variable is included in include_overall the - Any adverse events - section will still be kept.

See gtsummary::filter_hierarchical() for more details and examples.

Examples

theme_gtsummary_roche()
#> Setting theme "Roche"
ADSL <- cards::ADSL
ADAE_subset <- cards::ADAE |>
  dplyr::filter(
    AESOC %in% unique(cards::ADAE$AESOC)[1:5],
    AETERM %in% unique(cards::ADAE$AETERM)[1:10]
  )

grade_groups <- list(
  "Grade 1-2" = c("1", "2"),
  "Grade 3-4" = c("3", "4"),
  "Grade 5" = "5"
)

# Example 1 ----------------------------------
tbl_hierarchical_rate_by_grade(
  ADAE_subset,
  variables = c(AEBODSYS, AEDECOD, AETOXGR),
  denominator = ADSL,
  by = TRTA,
  label = list(
    AEBODSYS = "MedDRA System Organ Class",
    AEDECOD = "MedDRA Preferred Term",
    AETOXGR = "Grade"
  ),
  grade_groups = grade_groups,
  grades_exclude = "5"
)
MedDRA System Organ Class
    MedDRA Preferred Term
Grade Placebo
(N = 86)
Xanomeline High Dose
(N = 84)
Xanomeline Low Dose
(N = 84)
- Any adverse events - - Any Grade - 32 (37.2%) 46 (54.8%) 42 (50.0%)
         Grade 1-2 27 (31.4%) 36 (42.9%) 30 (35.7%)
             1 23 (26.7%) 27 (32.1%) 21 (25.0%)
             2 4 (4.7%) 9 (10.7%) 9 (10.7%)
         Grade 3-4 5 (5.8%) 10 (11.9%) 12 (14.3%)
             3 4 (4.7%) 10 (11.9%) 10 (11.9%)
             4 1 (1.2%) 0 2 (2.4%)
CARDIAC DISORDERS


    - Overall - - Any Grade - 3 (3.5%) 3 (3.6%) 0
         Grade 1-2 2 (2.3%) 3 (3.6%) 0
             1 2 (2.3%) 1 (1.2%) 0
             2 0 2 (2.4%) 0
         Grade 3-4 1 (1.2%) 0 0
             4 1 (1.2%) 0 0
    ATRIOVENTRICULAR BLOCK SECOND DEGREE - Any Grade - 2 (2.3%) 3 (3.6%) 0
         Grade 1-2 1 (1.2%) 3 (3.6%) 0
             1 1 (1.2%) 1 (1.2%) 0
             2 0 2 (2.4%) 0
         Grade 3-4 1 (1.2%) 0 0
             4 1 (1.2%) 0 0
    BUNDLE BRANCH BLOCK LEFT - Any Grade - 1 (1.2%) 0 0
         Grade 1-2 1 (1.2%) 0 0
             1 1 (1.2%) 0 0
GASTROINTESTINAL DISORDERS


    - Overall - - Any Grade - 10 (11.6%) 4 (4.8%) 5 (6.0%)
         Grade 1-2 10 (11.6%) 4 (4.8%) 5 (6.0%)
             1 9 (10.5%) 2 (2.4%) 5 (6.0%)
             2 1 (1.2%) 2 (2.4%) 0
    DIARRHOEA - Any Grade - 9 (10.5%) 4 (4.8%) 5 (6.0%)
         Grade 1-2 9 (10.5%) 4 (4.8%) 5 (6.0%)
             1 9 (10.5%) 2 (2.4%) 5 (6.0%)
             2 0 2 (2.4%) 0
    HIATUS HERNIA - Any Grade - 1 (1.2%) 0 0
         Grade 1-2 1 (1.2%) 0 0
             2 1 (1.2%) 0 0
GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS


    - Overall - - Any Grade - 9 (10.5%) 28 (33.3%) 27 (32.1%)
         Grade 1-2 8 (9.3%) 19 (22.6%) 18 (21.4%)
             1 8 (9.3%) 15 (17.9%) 14 (16.7%)
             2 0 4 (4.8%) 4 (4.8%)
         Grade 3-4 1 (1.2%) 9 (10.7%) 9 (10.7%)
             3 1 (1.2%) 9 (10.7%) 7 (8.3%)
             4 0 0 2 (2.4%)
    APPLICATION SITE ERYTHEMA - Any Grade - 3 (3.5%) 15 (17.9%) 12 (14.3%)
         Grade 1-2 3 (3.5%) 12 (14.3%) 7 (8.3%)
             1 3 (3.5%) 9 (10.7%) 4 (4.8%)
             2 0 3 (3.6%) 3 (3.6%)
         Grade 3-4 0 3 (3.6%) 5 (6.0%)
             3 0 3 (3.6%) 3 (3.6%)
             4 0 0 2 (2.4%)
    APPLICATION SITE PRURITUS - Any Grade - 6 (7.0%) 22 (26.2%) 22 (26.2%)
         Grade 1-2 5 (5.8%) 15 (17.9%) 17 (20.2%)
             1 5 (5.8%) 10 (11.9%) 13 (15.5%)
             2 0 5 (6.0%) 4 (4.8%)
         Grade 3-4 1 (1.2%) 7 (8.3%) 5 (6.0%)
             3 1 (1.2%) 7 (8.3%) 4 (4.8%)
             4 0 0 1 (1.2%)
    FATIGUE - Any Grade - 1 (1.2%) 5 (6.0%) 5 (6.0%)
         Grade 1-2 1 (1.2%) 5 (6.0%) 3 (3.6%)
             1 1 (1.2%) 5 (6.0%) 3 (3.6%)
         Grade 3-4 0 0 2 (2.4%)
             3 0 0 2 (2.4%)
INFECTIONS AND INFESTATIONS


    - Overall - - Any Grade - 6 (7.0%) 3 (3.6%) 1 (1.2%)
         Grade 1-2 5 (5.8%) 2 (2.4%) 1 (1.2%)
             1 4 (4.7%) 2 (2.4%) 1 (1.2%)
             2 1 (1.2%) 0 0
         Grade 3-4 1 (1.2%) 1 (1.2%) 0
             3 1 (1.2%) 1 (1.2%) 0
    UPPER RESPIRATORY TRACT INFECTION - Any Grade - 6 (7.0%) 3 (3.6%) 1 (1.2%)
         Grade 1-2 5 (5.8%) 2 (2.4%) 1 (1.2%)
             1 4 (4.7%) 2 (2.4%) 1 (1.2%)
             2 1 (1.2%) 0 0
         Grade 3-4 1 (1.2%) 1 (1.2%) 0
             3 1 (1.2%) 1 (1.2%) 0
SKIN AND SUBCUTANEOUS TISSUE DISORDERS


    - Overall - - Any Grade - 9 (10.5%) 15 (17.9%) 15 (17.9%)
         Grade 1-2 7 (8.1%) 14 (16.7%) 12 (14.3%)
             1 5 (5.8%) 11 (13.1%) 6 (7.1%)
             2 2 (2.3%) 3 (3.6%) 6 (7.1%)
         Grade 3-4 2 (2.3%) 1 (1.2%) 3 (3.6%)
             3 2 (2.3%) 1 (1.2%) 3 (3.6%)
    ERYTHEMA - Any Grade - 9 (10.5%) 14 (16.7%) 15 (17.9%)
         Grade 1-2 7 (8.1%) 13 (15.5%) 13 (15.5%)
             1 5 (5.8%) 10 (11.9%) 7 (8.3%)
             2 2 (2.3%) 3 (3.6%) 6 (7.1%)
         Grade 3-4 2 (2.3%) 1 (1.2%) 2 (2.4%)
             3 2 (2.3%) 1 (1.2%) 2 (2.4%)
    PRURITUS GENERALISED - Any Grade - 0 1 (1.2%) 1 (1.2%)
         Grade 1-2 0 1 (1.2%) 0
             1 0 1 (1.2%) 0
         Grade 3-4 0 0 1 (1.2%)
             3 0 0 1 (1.2%)
# Example 2 ---------------------------------- # Filter: Keep AEs with an overall prevalence of greater than 10% tbl_hierarchical_rate_by_grade( ADAE_subset, variables = c(AEBODSYS, AEDECOD, AETOXGR), denominator = ADSL, by = TRTA, grade_groups = list("Grades 1-2" = c("1", "2"), "Grades 3-5" = c("3", "4", "5")), filter = sum(n) / sum(N) > 0.10 ) |> add_overall(last = TRUE)
Body System or Organ Class
    Dictionary-Derived Term
Toxicity Grade Placebo
(N = 86)
Xanomeline High Dose
(N = 84)
Xanomeline Low Dose
(N = 84)
All Participants
(N = 254)
- Any adverse events - - Any Grade - 32 (37.2%) 46 (54.8%) 42 (50.0%) 120 (47.2%)
         Grades 1-2 27 (31.4%) 36 (42.9%) 30 (35.7%) 93 (36.6%)
             1 23 (26.7%) 27 (32.1%) 21 (25.0%) 71 (28.0%)
             2 4 (4.7%) 9 (10.7%) 9 (10.7%) 22 (8.7%)
         Grades 3-5 5 (5.8%) 10 (11.9%) 12 (14.3%) 27 (10.6%)
             3 4 (4.7%) 10 (11.9%) 10 (11.9%) 24 (9.4%)
             4 1 (1.2%) 0 2 (2.4%) 3 (1.2%)
GENERAL DISORDERS AND ADMINISTRATION SITE CONDITIONS



    - Overall - - Any Grade - 9 (10.5%) 28 (33.3%) 27 (32.1%) 64 (25.2%)
         Grades 1-2 8 (9.3%) 19 (22.6%) 18 (21.4%) 45 (17.7%)
             1 8 (9.3%) 15 (17.9%) 14 (16.7%) 37 (14.6%)
             2 0 4 (4.8%) 4 (4.8%) 8 (3.1%)
         Grades 3-5 1 (1.2%) 9 (10.7%) 9 (10.7%) 19 (7.5%)
             3 1 (1.2%) 9 (10.7%) 7 (8.3%) 17 (6.7%)
             4 0 0 2 (2.4%) 2 (0.8%)
    APPLICATION SITE ERYTHEMA - Any Grade - 3 (3.5%) 15 (17.9%) 12 (14.3%) 30 (11.8%)
         Grades 1-2 3 (3.5%) 12 (14.3%) 7 (8.3%) 22 (8.7%)
             1 3 (3.5%) 9 (10.7%) 4 (4.8%) 16 (6.3%)
             2 0 3 (3.6%) 3 (3.6%) 6 (2.4%)
         Grades 3-5 0 3 (3.6%) 5 (6.0%) 8 (3.1%)
             3 0 3 (3.6%) 3 (3.6%) 6 (2.4%)
             4 0 0 2 (2.4%) 2 (0.8%)
    APPLICATION SITE PRURITUS - Any Grade - 6 (7.0%) 22 (26.2%) 22 (26.2%) 50 (19.7%)
         Grades 1-2 5 (5.8%) 15 (17.9%) 17 (20.2%) 37 (14.6%)
             1 5 (5.8%) 10 (11.9%) 13 (15.5%) 28 (11.0%)
             2 0 5 (6.0%) 4 (4.8%) 9 (3.5%)
         Grades 3-5 1 (1.2%) 7 (8.3%) 5 (6.0%) 13 (5.1%)
             3 1 (1.2%) 7 (8.3%) 4 (4.8%) 12 (4.7%)
             4 0 0 1 (1.2%) 1 (0.4%)
SKIN AND SUBCUTANEOUS TISSUE DISORDERS



    - Overall - - Any Grade - 9 (10.5%) 15 (17.9%) 15 (17.9%) 39 (15.4%)
         Grades 1-2 7 (8.1%) 14 (16.7%) 12 (14.3%) 33 (13.0%)
             1 5 (5.8%) 11 (13.1%) 6 (7.1%) 22 (8.7%)
             2 2 (2.3%) 3 (3.6%) 6 (7.1%) 11 (4.3%)
         Grades 3-5 2 (2.3%) 1 (1.2%) 3 (3.6%) 6 (2.4%)
             3 2 (2.3%) 1 (1.2%) 3 (3.6%) 6 (2.4%)
    ERYTHEMA - Any Grade - 9 (10.5%) 14 (16.7%) 15 (17.9%) 38 (15.0%)
         Grades 1-2 7 (8.1%) 13 (15.5%) 13 (15.5%) 33 (13.0%)
             1 5 (5.8%) 10 (11.9%) 7 (8.3%) 22 (8.7%)
             2 2 (2.3%) 3 (3.6%) 6 (7.1%) 11 (4.3%)
         Grades 3-5 2 (2.3%) 1 (1.2%) 2 (2.4%) 5 (2.0%)
             3 2 (2.3%) 1 (1.2%) 2 (2.4%) 5 (2.0%)