Skip to contents

[Stable]

Primary analysis variable .var indicates the toxicity grade (factor), and additional analysis variables are id (character or factor), param (factor) and grade_dir (factor). The pre-processing steps are crucial when using this function. For a certain direction (e.g. high or low) this function counts patients in the denominator as number of patients with at least one valid measurement during treatment, and patients in the numerator as follows:

  • 1 to 4: Numerator is number of patients with worst grades 1-4 respectively;

  • Any: Numerator is number of patients with at least one abnormality, which means grade is different from 0.

Usage

s_count_abnormal_by_worst_grade(
  df,
  .var = "GRADE_ANL",
  .spl_context,
  variables = list(id = "USUBJID", param = "PARAM", grade_dir = "GRADE_DIR")
)

a_count_abnormal_by_worst_grade(
  df,
  .var = "GRADE_ANL",
  .spl_context,
  variables = list(id = "USUBJID", param = "PARAM", grade_dir = "GRADE_DIR")
)

count_abnormal_by_worst_grade(
  lyt,
  var,
  nested = TRUE,
  ...,
  .stats = NULL,
  .formats = NULL,
  .labels = NULL,
  .indent_mods = NULL
)

Arguments

df

(data.frame)
data set containing all analysis variables.

.var, var

(string)
single variable name that is passed by rtables when requested by a statistics function.

.spl_context

(data.frame)
gives information about ancestor split states that is passed by rtables.

variables

(named list of string)
list of additional analysis variables.

lyt

(layout)
input layout where analyses will be added to.

nested

(flag)
whether this layout instruction should be applied within the existing layout structure if possible (TRUE, the default) or as a new top-level element (FALSE). Ignored if it would nest a split. underneath analyses, which is not allowed.

...

additional arguments for the lower level functions.

.stats

(character)
statistics to select for the table.

.formats

(named character or list)
formats for the statistics.

.labels

(named character)
labels for the statistics (without indent).

.indent_mods

(named integer)
indent modifiers for the labels. Defaults to 0, which corresponds to the unmodified default behavior. Can be negative.

Value

  • s_count_abnormal_by_worst_grade() returns the single statistic count_fraction with grades 1 to 4 and "Any" results.

  • a_count_abnormal_by_worst_grade() returns the corresponding list with formatted rtables::CellValue().

  • count_abnormal_by_worst_grade() returns a layout object suitable for passing to further layouting functions, or to rtables::build_table(). Adding this function to an rtable layout will add formatted rows containing the statistics from s_count_abnormal_by_worst_grade() to the table layout.

Details

The pre-processing steps are crucial when using this function. From the standard lab grade variable ATOXGR, derive the following two variables:

  • A grade direction variable (e.g. GRADE_DIR) is required in order to obtain the correct denominators when building the layout as it is used to define row splitting.

  • A toxicity grade variable (e.g. GRADE_ANL) where all negative values from ATOXGR are replaced by their absolute values.

Functions

  • s_count_abnormal_by_worst_grade(): Statistics function which counts patients by worst grade.

  • a_count_abnormal_by_worst_grade(): Formatted analysis function which is used as afun in count_abnormal_by_worst_grade().

  • count_abnormal_by_worst_grade(): Layout-creating function which can take statistics function arguments and additional format arguments. This function is a wrapper for rtables::analyze().

Note

Prior to tabulation, df must be filtered to include only post-baseline records with worst grade flags.

Examples

library(dplyr)
library(forcats)
adlb <- tern_ex_adlb

# Data is modified in order to have some parameters with grades only in one direction
# and simulate the real data.
adlb$ATOXGR[adlb$PARAMCD == "ALT" & adlb$ATOXGR %in% c("1", "2", "3", "4")] <- "-1"
adlb$ANRIND[adlb$PARAMCD == "ALT" & adlb$ANRIND == "HIGH"] <- "LOW"
adlb$WGRHIFL[adlb$PARAMCD == "ALT"] <- ""

adlb$ATOXGR[adlb$PARAMCD == "IGA" & adlb$ATOXGR %in% c("-1", "-2", "-3", "-4")] <- "1"
adlb$ANRIND[adlb$PARAMCD == "IGA" & adlb$ANRIND == "LOW"] <- "HIGH"
adlb$WGRLOFL[adlb$PARAMCD == "IGA"] <- ""

# Here starts the real pre-processing.
adlb_f <- adlb %>%
  filter(!AVISIT %in% c("SCREENING", "BASELINE")) %>%
  mutate(
    GRADE_DIR = factor(
      case_when(
        ATOXGR %in% c("-1", "-2", "-3", "-4") ~ "LOW",
        ATOXGR == "0" ~ "ZERO",
        ATOXGR %in% c("1", "2", "3", "4") ~ "HIGH"
      ),
      levels = c("LOW", "ZERO", "HIGH")
    ),
    GRADE_ANL = fct_relevel(
      fct_recode(ATOXGR, `1` = "-1", `2` = "-2", `3` = "-3", `4` = "-4"),
      c("0", "1", "2", "3", "4")
    )
  ) %>%
  filter(WGRLOFL == "Y" | WGRHIFL == "Y") %>%
  droplevels()

adlb_f_alt <- adlb_f %>%
  filter(PARAMCD == "ALT") %>%
  droplevels()
full_parent_df <- list(adlb_f_alt, "not_needed")
cur_col_subset <- list(rep(TRUE, nrow(adlb_f_alt)), "not_needed")

# This mimics a split structure on PARAM and GRADE_DIR for a total column
spl_context <- data.frame(
  split = c("PARAM", "GRADE_DIR"),
  full_parent_df = I(full_parent_df),
  cur_col_subset = I(cur_col_subset)
)

# Map excludes records without abnormal grade since they should not be displayed
# in the table.
map <- unique(adlb_f[adlb_f$GRADE_DIR != "ZERO", c("PARAM", "GRADE_DIR", "GRADE_ANL")]) %>%
  lapply(as.character) %>%
  as.data.frame() %>%
  arrange(PARAM, desc(GRADE_DIR), GRADE_ANL)

basic_table() %>%
  split_cols_by("ARMCD") %>%
  split_rows_by("PARAM") %>%
  split_rows_by("GRADE_DIR", split_fun = trim_levels_to_map(map)) %>%
  count_abnormal_by_worst_grade(
    var = "GRADE_ANL",
    variables = list(id = "USUBJID", param = "PARAM", grade_dir = "GRADE_DIR")
  ) %>%
  build_table(df = adlb_f)
#>                                          ARM A        ARM B        ARM C   
#> ———————————————————————————————————————————————————————————————————————————
#> Alanine Aminotransferase Measurement                                       
#>   LOW                                                                      
#>     1                                  12 (17.4%)    5 (6.8%)    8 (13.8%) 
#>     2                                   9 (13%)     13 (17.8%)   6 (10.3%) 
#>     3                                   6 (8.7%)     4 (5.5%)    6 (10.3%) 
#>     4                                  7 (10.1%)     7 (9.6%)    6 (10.3%) 
#>     Any                                34 (49.3%)   29 (39.7%)   26 (44.8%)
#> C-Reactive Protein Measurement                                             
#>   LOW                                                                      
#>     1                                  11 (15.9%)   12 (16.4%)   7 (12.1%) 
#>     2                                  8 (11.6%)     2 (2.7%)    6 (10.3%) 
#>     3                                   4 (5.8%)    9 (12.3%)    6 (10.3%) 
#>     4                                  7 (10.1%)     6 (8.2%)     4 (6.9%) 
#>     Any                                30 (43.5%)   29 (39.7%)   23 (39.7%)
#>   HIGH                                                                     
#>     1                                  8 (11.6%)    11 (15.1%)    2 (3.4%) 
#>     2                                   9 (13%)     11 (15.1%)    11 (19%) 
#>     3                                  14 (20.3%)   10 (13.7%)    5 (8.6%) 
#>     4                                   2 (2.9%)     4 (5.5%)    6 (10.3%) 
#>     Any                                33 (47.8%)   36 (49.3%)   24 (41.4%)
#> Immunoglobulin A Measurement                                               
#>   HIGH                                                                     
#>     1                                  7 (10.1%)     7 (9.6%)    6 (10.3%) 
#>     2                                  8 (11.6%)     6 (8.2%)    8 (13.8%) 
#>     3                                  7 (10.1%)     5 (6.8%)    9 (15.5%) 
#>     4                                   6 (8.7%)     2 (2.7%)     3 (5.2%) 
#>     Any                                28 (40.6%)   20 (27.4%)   26 (44.8%)