abnormal_by_worst_grade: Count patients by most extreme post-baseline toxicity grade...

abnormal_by_worst_gradeR Documentation

Count patients by most extreme post-baseline toxicity grade per direction of abnormality

Description

[Stable]

The analyze function count_abnormal_by_worst_grade() creates a layout element to count patients by highest (worst) analysis toxicity grade post-baseline for each direction, categorized by parameter value.

This function analyzes primary analysis variable var which indicates toxicity grades. Additional analysis variables that can be supplied as a list via the variables parameter are id (defaults to USUBJID), a variable to indicate unique subject identifiers, param (defaults to PARAM), a variable to indicate parameter values, and grade_dir (defaults to GRADE_DIR), a variable to indicate directions (e.g. High or Low) for each toxicity grade supplied in var.

For each combination of param and grade_dir levels, patient counts by worst grade are calculated as follows:

  • 1 to 4: The number of patients with worst grades 1-4, respectively.

  • Any: The number of patients with at least one abnormality (i.e. grade is not 0).

Fractions are calculated by dividing the above counts by the number of patients with at least one valid measurement recorded during treatment.

Pre-processing is crucial when using this function and can be done automatically using the h_adlb_abnormal_by_worst_grade() helper function. See the description of this function for details on the necessary pre-processing steps.

Prior to using this function in your table layout you must use rtables::split_rows_by() to create two row splits, one on variable param and one on variable grade_dir.

Usage

count_abnormal_by_worst_grade(
  lyt,
  var,
  variables = list(id = "USUBJID", param = "PARAM", grade_dir = "GRADE_DIR"),
  na_str = default_na_str(),
  nested = TRUE,
  ...,
  .stats = NULL,
  .formats = NULL,
  .labels = NULL,
  .indent_mods = NULL
)

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")
)

Arguments

lyt

(PreDataTableLayouts)
layout that analyses will be added to.

variables

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

na_str

(string)
string used to replace all NA or empty values in the output.

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. Run get_stats("abnormal_by_worst_grade") to see available statistics for this function.

.formats

(named character or list)
formats for the statistics. See Details in analyze_vars for more information on the "auto" setting.

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

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.

Value

  • 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.

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

Functions

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

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

See Also

h_adlb_abnormal_by_worst_grade() which pre-processes ADLB data frames to be used in count_abnormal_by_worst_grade().

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"] <- ""

# Pre-processing
adlb_f <- adlb %>% h_adlb_abnormal_by_worst_grade()

# 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)


tern documentation built on Sept. 24, 2024, 9:06 a.m.