Patient Counts for Laboratory Events (Worsen From Baseline) by Highest Grade Post-Baseline
Source:R/abnormal_by_worst_grade_worsen.R
      abnormal_by_worst_grade_worsen.RdUsage
h_adlb_worsen(
  adlb,
  worst_flag_low = NULL,
  worst_flag_high = NULL,
  direction_var
)
h_worsen_counter(df, id, .var, baseline_var, direction_var)
s_count_abnormal_lab_worsen_by_baseline(
  df,
  .var = "ATOXGR",
  variables = list(id = "USUBJID", baseline_var = "BTOXGR", direction_var = "GRADDR")
)
a_count_abnormal_lab_worsen_by_baseline(
  df,
  .var = "ATOXGR",
  variables = list(id = "USUBJID", baseline_var = "BTOXGR", direction_var = "GRADDR")
)
count_abnormal_lab_worsen_by_baseline(
  lyt,
  var,
  ...,
  table_names = NULL,
  .stats = NULL,
  .formats = NULL,
  .labels = NULL,
  .indent_mods = NULL
)Arguments
- adlb
- ( - data frame)- ADLBdataframe
- worst_flag_low
- (named - vector)
 Worst low post-baseline lab grade flag variable
- worst_flag_high
- (named - vector)
 Worst high post-baseline lab grade flag variable
- direction_var
- 
( string)
 Direction variable specifying the direction of the shift table of interest. Only lab records flagged byL,HorBare included in the shift table.- L: low direction only
- H: high direction only
- B: both low and high directions
 
- df
- ( - data frame)
 data set containing all analysis variables.
- id
- ( - string)
 subject variable name.
- .var, var
- ( - string)
 single variable name that is passed by- rtableswhen requested by a statistics function.
- baseline_var
- ( - string)
 baseline lab grade variable
- variables
- 
(named listofstring)
 list of additional analysis variables including:- id(- string):
 subject variable name
- baseline_var(- string):
 name of the data column containing baseline toxicity variable
- direction_var(- string): See- direction_varfor more detail
 
- lyt
- ( - layout)
 input layout where analyses will be added to.
- ...
- additional arguments for the lower level functions. 
- table_names
- ( - character)
 this can be customized in case that the same- varsare analyzed multiple times, to avoid warnings from- rtables.
- .stats
- ( - character)
 statistics to select for the table.
- .formats
- (named - characteror- list)
 formats for the statistics.
- .labels
- (named - character)
 labels for the statistics (without indent).
- .indent_mods
- (named - integer)
 indent modifiers for the labels.
Value
h_adlb_worsen() returns the adlb
data frame containing only the
worst labs specified according to worst_flag_low or worst_flag_high for the
direction specified according to direction_var. For instance, for a lab that is
needed for the low direction only, only records flagged by worst_flag_low are
selected. For a lab that is needed for both low and high directions, the worst
low records are selected for the low direction, and the worst high record are selected
for the high direction.
h_worsen_counter() returns the counts and fraction of patients
whose worst post-baseline lab grades are worse than their baseline grades, for
post-baseline worst grades "1", "2", "3", "4" and "Any".
s_count_abnormal_lab_worsen_by_baseline() returns the
counts and fraction of patients whose worst post-baseline lab grades are worse than
their baseline grades, for post-baseline worst grades "1", "2", "3", "4" and "Any".
a_count_abnormal_lab_worsen_by_baseline() returns
the corresponding list with formatted rtables::CellValue().
Functions
- h_adlb_worsen(): Helper function to prepare a- dffor generate the patient count shift table
- h_worsen_counter(): Helper function to count the number of patients and the fraction of patients according to highest post-baseline lab grade variable- .var, baseline lab grade variable- baseline_var, and the direction of interest specified in- direction_var.
- s_count_abnormal_lab_worsen_by_baseline(): Statistics function which calculates the counts and fraction of patients whose worst post-baseline lab grades are worse than their baseline grades, for post-baseline worst grades "1", "2", "3", "4" and "Any".
- a_count_abnormal_lab_worsen_by_baseline(): Formatted Analysis function which can be further customized by calling- rtables::make_afun()on it. It is used as- afunin- rtables::analyze().
- count_abnormal_lab_worsen_by_baseline(): Layout creating function which can be used for creating tables, which can take statistics function arguments and additional format arguments (see below).
Examples
library(scda)
library(dplyr)
adlb <- synthetic_cdisc_data("latest")$adlb
adsl <- synthetic_cdisc_data("latest")$adsl
# The direction variable, GRADDR, is based on metadata
adlb <- adlb %>%
  mutate(
    GRADDR = case_when(
      PARAMCD == "ALT" ~ "B",
      PARAMCD == "CRP" ~ "L",
      PARAMCD == "IGA" ~ "H"
    )
  ) %>%
  filter(SAFFL == "Y" & ONTRTFL == "Y" & GRADDR != "")
df <- h_adlb_worsen(
  adlb,
  worst_flag_low = c("WGRLOFL" = "Y"),
  worst_flag_high = c("WGRHIFL" = "Y"),
  direction_var = "GRADDR"
)
# `h_worsen_counter`
h_worsen_counter(
  df %>% filter(PARAMCD == "CRP" & GRADDR == "Low"),
  id = "USUBJID",
  .var = "ATOXGR",
  baseline_var = "BTOXGR",
  direction_var = "GRADDR"
)
#> $fraction
#> $fraction$`1`
#>   num denom 
#>    44   367 
#> 
#> $fraction$`2`
#>   num denom 
#>    49   379 
#> 
#> $fraction$`3`
#>   num denom 
#>    38   386 
#> 
#> $fraction$`4`
#>   num denom 
#>    21   391 
#> 
#> $fraction$Any
#>   num denom 
#>   152   391 
#> 
#> 
# Internal function - s_count_abnormal_lab_worsen_by_baseline
if (FALSE) {
# Patients with worsening lab grade for CRP in the direction of low
s_count_abnormal_lab_worsen_by_baseline(
  df = df %>% filter(ARMCD == "ARM A" & PARAMCD == "CRP"),
  .var = "ATOXGR",
  variables = list(
    id = "USUBJID",
    baseline_var = "BTOXGR",
    direction_var = "GRADDR"
  )
)
}
# Internal function - a_count_abnormal_lab_worsen_by_baseline
if (FALSE) {
a_count_abnormal_lab_worsen_by_baseline(
  df = df %>% filter(ARMCD == "ARM A" & PARAMCD == "CRP"),
  .var = "ATOXGR",
  variables = list(id = "USUBJID", baseline_var = "BTOXGR", direction_var = "GRADDR")
)
}
basic_table() %>%
  split_cols_by("ARMCD") %>%
  add_colcounts() %>%
  split_rows_by("PARAMCD") %>%
  split_rows_by("GRADDR") %>%
  count_abnormal_lab_worsen_by_baseline(
    var = "ATOXGR",
    variables = list(
      id = "USUBJID",
      baseline_var = "BTOXGR",
      direction_var = "GRADDR"
    )
  ) %>%
  append_topleft("Direction of Abnormality") %>%
  build_table(df = df, alt_counts_df = adsl)
#> Direction of Abnormality       ARM A            ARM B            ARM C     
#>                               (N=134)          (N=134)          (N=132)    
#> ———————————————————————————————————————————————————————————————————————————
#> ALT                                                                        
#>   High                                                                     
#>     1                      16/121 (13.2%)   13/117 (11.1%)   17/117 (14.5%)
#>     2                      14/125 (11.2%)   12/121 (9.9%)    17/120 (14.2%)
#>     3                        9/129 (7%)      15/125 (12%)    13/124 (10.5%)
#>     4                      12/131 (9.2%)    11/130 (8.5%)    13/129 (10.1%)
#>     Any                    51/131 (38.9%)   51/130 (39.2%)   60/129 (46.5%)
#>   Low                                                                      
#>     1                      13/124 (10.5%)   12/121 (9.9%)     9/117 (7.7%) 
#>     2                      13/127 (10.2%)   17/127 (13.4%)   11/124 (8.9%) 
#>     3                      19/129 (14.7%)   12/128 (9.4%)    10/128 (7.8%) 
#>     4                       7/131 (5.3%)     7/131 (5.3%)    10/132 (7.6%) 
#>     Any                    52/131 (39.7%)   48/131 (36.6%)   40/132 (30.3%)
#> CRP                                                                        
#>   Low                                                                      
#>     1                      14/122 (11.5%)   17/125 (13.6%)   13/120 (10.8%)
#>     2                      21/124 (16.9%)   12/130 (9.2%)    16/125 (12.8%)
#>     3                      12/129 (9.3%)     9/131 (6.9%)    17/126 (13.5%)
#>     4                      10/131 (7.6%)     7/133 (5.3%)     4/127 (3.1%) 
#>     Any                    57/131 (43.5%)   45/133 (33.8%)   50/127 (39.4%)
#> IGA                                                                        
#>   High                                                                     
#>     1                      24/118 (20.3%)    12/120 (10%)    13/119 (10.9%)
#>     2                      13/120 (10.8%)   19/124 (15.3%)   13/125 (10.4%)
#>     3                      11/124 (8.9%)    10/128 (7.8%)    17/128 (13.3%)
#>     4                      11/129 (8.5%)     13/130 (10%)     4/130 (3.1%) 
#>     Any                    59/129 (45.7%)   54/130 (41.5%)   47/130 (36.2%)