TL Catalog
  1. Tables
  2. Clinical Laboratory Evaluation
  3. TSFLAB03A
  • Introduction

  • Index

  • Tables
    • Adverse Events
      • TSFAE01A
      • TSFAE01B
      • TSFAE02
      • TSFAE02A
      • TSFAE03
      • TSFAE03A
      • TSFAE04
      • TSFAE04A
      • TSFAE05
      • TSFAE05A
      • TSFAE06A
      • TSFAE06B
      • TSFAE07A
      • TSFAE07B
      • TSFAE08
      • TSFAE09
      • TSFAE10
      • TSFAE11
      • TSFAE12
      • TSFAE13
      • TSFAE14
      • TSFAE15
      • TSFAE16
      • TSFAE17A
      • TSFAE17B
      • TSFAE17C
      • TSFAE17D
      • TSFAE19A
      • TSFAE19B
      • TSFAE19C
      • TSFAE19D
      • TSFAE20A
      • TSFAE20B
      • TSFAE20C
      • TSFAE21A
      • TSFAE21B
      • TSFAE21C
      • TSFAE21D
      • TSFAE22A
      • TSFAE22B
      • TSFAE22C
      • TSFAE23A
      • TSFAE23B
      • TSFAE23C
      • TSFAE23D
      • TSFAE24A
      • TSFAE24B
      • TSFAE24C
      • TSFAE24D
      • TSFAE24F
      • TSFDTH01
    • Clinical Laboratory Evaluation
      • TSFLAB01
      • TSFLAB01A
      • TSFLAB02
      • TSFLAB02A
      • TSFLAB02B
      • TSFLAB03
      • TSFLAB03A
      • TSFLAB04A
      • TSFLAB04B
      • TSFLAB05
      • TSFLAB06
      • TSFLAB07
    • Demographic
      • TSIDEM01
      • TSIDEM02
      • TSIMH01
    • Disposition of Subjects
      • TSIDS01
      • TSIDS02
      • TSIDS02A
    • Electrocardiograms
      • TSFECG01
      • TSFECG01A
      • TSFECG02
      • TSFECG03
      • TSFECG04
      • TSFECG05
    • Exposure
      • TSIEX01
      • TSIEX02
      • TSIEX03
      • TSIEX04
      • TSIEX06
      • TSIEX07
      • TSIEX08
      • TSIEX09
      • TSIEX10
      • TSIEX11
    • Pharmacokinetics
      • TPK01A
      • TPK01B
      • TPK02
      • TPK03
    • Prior and Concomitant Therapies
      • TSICM01
      • TSICM02
      • TSICM03
      • TSICM04
      • TSICM05
      • TSICM06
      • TSICM07
      • TSICM08
    • Vital Signs and Physical Findings
      • TSFVIT01
      • TSFVIT01A
      • TSFVIT02
      • TSFVIT03
      • TSFVIT04
      • TSFVIT05
      • TSFVIT06
  • Listings
    • Adverse Events
      • LSFAE01
      • LSFAE02
      • LSFAE03
      • LSFAE04
      • LSFAE05
      • LSFAE06A
      • LSFAE06B
      • LSFDTH01
    • Clinical Laboratory Evaluation
      • LSFLAB01
    • Demographic
      • LSIDEM01
      • LSIDEM02
      • LSIMH01
    • Disposition of Subjects
      • LSIDS01
      • LSIDS02
      • LSIDS03
      • LSIDS04
      • LSIDS05
    • Electrocardiograms
      • LSFECG01
      • LSFECG02
    • Exposure
      • LSIEX01
      • LSIEX02
      • LSIEX03
    • Prior and Concomitant Therapies
      • LSICM01
    • Vital Signs and Physical Findings
      • LSFVIT01
      • LSFVIT02

  • Reproducibility

  • Changelog

On this page

  • Output
  • Edit this page
  • Report an issue
  1. Tables
  2. Clinical Laboratory Evaluation
  3. TSFLAB03A

TSFLAB03A

Subjects With =1 Laboratory Values With Elevated or Low Values Based on Worst On-treatment Value Using NCI-CTCAE Criteria by Subgroup


Output

  • Preview
Code
# Program Name:              tsflab03a

# Prep Environment

library(envsetup)
library(tern)
library(dplyr)
library(rtables)
library(junco)

# Define script level parameters:

tblid <- "TSFLAB03a"
fileid <- tblid
titles <- get_titles_from_file(input_path = '../../_data/', tblid)
string_map <- default_str_map

popfl <- "SAFFL"
trtvar <- "TRT01A"
ctrl_grp <- "Placebo"

subgrpvar <- "AGEGR1"
subgrplbl <- "Age: %s years"

page_by <- TRUE # Set page_by TRUE/FALSE if you (do not) wish to start a new page after a new subgroup
indent_adj <- -1L
if (page_by) {
  indent_adj <- 0L
}

## if the option TRTEMFL needs to be added to the TLF
trtemfl <- FALSE

## For analysis on SI units: use adlb dataset
## For analysis on Conventional units: use adlbc dataset -- shell is in conventional units

ad_domain <- "ADLB"

# Initial processing of data + check if table is valid for trial:

adlb_complete <- pharmaverseadamjnj::adlb


## parcat5 and 6 options :

availparcat56 <- c(
  "Investigations",
  "Metabolism and nutritional disorders",
  "Renal and urinary disorders",
  "Blood and lymphatic system disorders"
)

## resrict to some
selparcat56 <- availparcat56[c(1, 2, 4)]

## get all
selparcat56 <- availparcat56

lbtoxgrade_file <- file.path('../../_data', "lbtoxgrade.xlsx")
lbtoxgrade_sheets <- readxl::excel_sheets(path = lbtoxgrade_file)

### CTC5 or DAIDS21c : default CTC5

lbtoxgrade_defs <- readxl::read_excel(lbtoxgrade_file, sheet = "CTC5")

lbtoxgrade_defs <- unique(
  lbtoxgrade_defs %>%
    select(TOXTERM, TOXGRD, INDICATR)
) %>%
  mutate(
    ATOXDSCLH = TOXTERM,
    ATOXGRLH = paste("Grade", TOXGRD)
  ) %>%
  rename(ATOXDIR = INDICATR) %>%
  select(ATOXDSCLH, ATOXGRLH, ATOXDIR)

# Process Data:

adsl <- pharmaverseadamjnj::adsl %>%
  filter(.data[[popfl]] == "Y") %>%
  select(USUBJID, all_of(c(popfl, trtvar, subgrpvar)))

adsl$colspan_trt <- factor(
  ifelse(adsl[[trtvar]] == ctrl_grp, " ", "Active Study Agent"),
  levels = c("Active Study Agent", " ")
)

adsl$rrisk_header <- "Risk Difference (%) (95% CI)"
adsl$rrisk_label <- paste(adsl[[trtvar]], paste("vs", ctrl_grp))

colspan_trt_map <- create_colspan_map(
  adsl,
  non_active_grp = ctrl_grp,
  non_active_grp_span_lbl = " ",
  active_grp_span_lbl = "Active Study Agent",
  colspan_var = "colspan_trt",
  trt_var = trtvar
)

ref_path <- c("colspan_trt", " ", trtvar, ctrl_grp)


## for checking row_counts on AGEGR1 : should consist with counts from ADSL
adsl_agegr1 <- adsl %>%
  select(all_of(c(trtvar, subgrpvar))) %>%
  group_by(across(all_of(c(trtvar, subgrpvar)))) %>%
  summarise(n = n())

adlb00 <- adlb_complete %>%
  select(
    USUBJID,
    AVISITN,
    AVISIT,
    starts_with("PAR"),
    starts_with("ATOX"),
    starts_with("ANL"),
    ONTRTFL,
    TRTEMFL,
    AVAL,
    APOBLFL,
    ABLFL,
    LVOTFL
  ) %>%
  inner_join(adsl) %>%
  mutate(
    ATOXGRL = as.character(ATOXGRL),
    ATOXGRH = as.character(ATOXGRH)
  ) %>%
  relocate(
    .,
    USUBJID,
    all_of(subgrpvar),
    ANL04FL,
    ANL05FL,
    ONTRTFL,
    TRTEMFL,
    AVISIT,
    ATOXGRL,
    ATOXGRH,
    ATOXDSCL,
    ATOXDSCH,
    PARAMCD,
    AVISIT,
    AVAL,
    APOBLFL,
    ABLFL
  )


adlb00 <- adlb00 # %>%
## APT comment on PARCAT6 :
## HGB and WBC : Set to "Blood and lymphatic system disorders".
## HGB and WBC parameter are in 2 categories, one for the high and another one for the low direction grading.
## Anemia (HGB low) and Leukocytosis (WBC high) are in the category "Blood and lymphatic system disorders".
## The grading in the opposite directions are categorized under "Investigations".
## Therefor, both PARCAT5 and PARCAT6 are populated for HGB abd WBC.
## Deal with what is needed at later level, when we have splitted low and high
# mutate(PARCAT56 = coalesce(PARCAT6,PARCAT5)) %>%
# mutate(PARCAT56 = factor(PARCAT56,levels=unique(c(levels(adlb_complete$PARCAT6),levels(adlb_complete$PARCAT5)))))

# obj_label(adlb00$PARCAT56) <- "Combined PARCAT56"

### important: previous actions lost the label of variables

adlb00 <- var_relabel_list(adlb00, var_labels(adlb_complete, fill = T))

parcat <- unique(
  adlb00 %>%
    select(starts_with("PARCAT"), PARAMCD, PARAM, ATOXDSCL, ATOXDSCH) %>%
    filter(!(is.na(PARCAT5) & is.na(PARCAT6)))
)


### data preparation

if (all(selparcat56 != "")) {
  filtered_adlb <- adlb00 %>%
    filter((PARCAT5 %in% selparcat56) | (PARCAT6 %in% selparcat56))
}


### low grades : ATOXDSCL ATOXGRL ANL04FL
### Note on Worst On-treatment
### note: by filter ANL04FL/ANL05FL, this table is restricted to On-treatment values, per definition of ANL04FL/ANL05FL
### therefor, no need to add ONTRTFL in filter
### if derivation of ANL04FL/ANL05FL is not restricted to ONTRTFL records, adding ONTRTFL here will not give the correct answer either
### as mixing worst with other period is not giving the proper selection !!!

filtered_adlb_low <- filtered_adlb %>%
  filter(ANL04FL == "Y" & !is.na(ATOXDSCL) & !is.na(ATOXGRL)) %>%
  mutate(
    ATOXDSCLH = ATOXDSCL,
    ATOXGRLH = ATOXGRL,
    ATOXDIR = "LOW"
  ) %>%
  select(USUBJID, starts_with("PAR"), starts_with("ATOX"), TRTEMFL) %>%
  select(-c(ATOXGRL, ATOXGRH, ATOXDSCL, ATOXDSCH))

### high grades: ATOXDSCH ATOXGRH ANL05FL
filtered_adlb_high <- filtered_adlb %>%
  filter(ANL05FL == "Y" & !is.na(ATOXDSCH) & !is.na(ATOXGRH)) %>%
  mutate(
    ATOXDSCLH = ATOXDSCH,
    ATOXGRLH = ATOXGRH,
    ATOXDIR = "HIGH"
  ) %>%
  select(USUBJID, starts_with("PAR"), starts_with("ATOX"), TRTEMFL) %>%
  select(-c(ATOXGRL, ATOXGRH, ATOXDSCL, ATOXDSCH))

## combine Low and high into adlb_tox
filtered_adlb_tox <-
  bind_rows(
    filtered_adlb_low,
    filtered_adlb_high
  ) %>%
  select(-c(ATOXGR, ATOXGRN)) %>%
  inner_join(adsl)

### correction of proper category (PARCAT56) for HGB (LOW) and WBC (HIGH)
filtered_adlb_tox <-
  filtered_adlb_tox %>%
  mutate(
    PARCAT56 = case_when(
      PARAMCD == "HGB" & ATOXDIR == "LOW" ~ PARCAT6,
      PARAMCD == "WBC" & ATOXDIR == "HIGH" ~ PARCAT6,

      ### fix on synthetic data !!!!
      PARAMCD == "WBC" & ATOXDIR == "LOW" ~ "Investigations",
      TRUE ~ PARCAT5
    )
  ) %>%
  mutate(
    PARCAT56 = factor(
      PARCAT56,
      levels = unique(c(
        "Blood and lymphatic system disorders",
        levels(adlb_complete$PARCAT5)
      ))
    )
  )


#### DO NOT USE TRTEMFL = Y in filter, as this will remove subjects from both numerator and denominator
#### instead : set ATOXGRLH to a non-reportable value (ie Grade 0) and keep in dataset
if (trtemfl) {
  filtered_adlb_tox <- filtered_adlb_tox %>%
    mutate(
      ATOXGRLH = case_when(
        is.na(TRTEMFL) | TRTEMFL != "Y" ~ "0",
        TRUE ~ ATOXGRLH
      )
    )
}


## convert some to factors -- lty will fail if these are not factors
filtered_adlb_tox <-
  filtered_adlb_tox %>%
  mutate(
    ATOXGRLH = factor(paste("Grade", ATOXGRLH), levels = paste("Grade", 0:5)),
    ATOXDIR = factor(ATOXDIR, levels = c("LOW", "HIGH"))
  )


filtered_adlb_tox <- unique(
  filtered_adlb_tox
)

check_non_unique_subject <- filtered_adlb_tox %>%
  group_by(USUBJID, PARAMCD, ATOXDSCLH) %>%
  summarize(n_subject = n()) %>%
  filter(n_subject > 1)

if (nrow(check_non_unique_subject)) {
  message(
    "Please review your data selection process, subject has multiple records"
  )
}


params <- unique(
  filtered_adlb_tox %>% select(PARCAT56, PARAMCD, PARAM, ATOXDSCLH, ATOXDIR)
)

all_params <- unique(
  adlb_complete %>%
    filter(!(is.na(PARCAT5) & is.na(PARCAT6))) %>%
    select(PARCAT5, PARCAT6, PARAMCD, PARAM, ATOXDSCL, ATOXDSCH)
)

### add relevant extra vars to lbtoxgrade_defs, only restrict to those actually in trial
### Neutrophil Count Decreased (NEUTSG NEUT) is causing for the many-to-many warning
lbtoxgrade_defs <- lbtoxgrade_defs %>%
  inner_join(
    .,
    unique(
      filtered_adlb_tox %>%
        select(PARAMCD, PARAM, ATOXDIR, ATOXDSCLH, PARCAT5, PARCAT6, PARCAT56)
    )
  )


### Define param_map to be used in layout
param_map <- lbtoxgrade_defs %>%
  select(PARCAT56, PARAM, PARAMCD, ATOXDIR, ATOXDSCLH, ATOXGRLH) %>%
  ### for proper sorting: add factor levels to PARAMCD, ATOXDIR
  mutate(
    PARAMCD = factor(PARAMCD, levels = levels(adlb00$PARAMCD)),
    ATOXDIR = factor(ATOXDIR, levels = c("LOW", "HIGH"))
  ) %>%
  # ### actual sorting
  #   arrange(PARCAT56,PARAMCD,ATOXDIR,ATOXGRLH) %>%
  ### actual sorting -- all alphabetic on output
  arrange(PARCAT56, ATOXDSCLH) %>%
  ### !!!! no factors are allowed in this split_fun map definition
  mutate(
    PARCAT56 = as.character(PARCAT56),
    PARAMCD = as.character(PARAMCD),
    PARAM = as.character(PARAM),
    ATOXDIR = as.character(ATOXDIR),
    ATOXDSCLH = as.character(ATOXDSCLH)
  ) # %>%
### !!!! do not remove Grade 0 here, as this would lead to incorrect N and % derivation
### filter(ATOXGRLH != "Grade 0")
### Grade 0 will be removed as a post-processing step

# Define layout and build table:

extra_args_rr <- list(
  method = "wald",
  denom = "n_df",
  ref_path = ref_path,
  .stats = c("denom", "count_unique_fraction"),
  denom_by = subgrpvar
)
extra_args_rr2 <- list(
  method = "wald",
  denom = "n_df",
  ref_path = ref_path,
  .stats = c("denom", "count_unique_denom_fraction"),
  denom_by = subgrpvar
)


lyt0 <- basic_table(show_colcounts = TRUE, colcount_format = "N=xx") %>%
  ### first columns
  split_cols_by(
    "colspan_trt",
    split_fun = trim_levels_to_map(map = colspan_trt_map)
  ) %>%
  split_cols_by(trtvar) %>%
  split_cols_by("rrisk_header", nested = FALSE) %>%
  split_cols_by(
    trtvar,
    labels_var = "rrisk_label",
    split_fun = remove_split_levels(ctrl_grp)
  ) %>%
  split_rows_by(
    subgrpvar,
    label_pos = "hidden",
    section_div = " ",
    split_fun = drop_split_levels,
    page_by = page_by
  ) %>%
  ###
  summarize_row_groups(
    var = subgrpvar,
    cfun = a_freq_j,
    extra_args = list(
      label_fstr = subgrplbl,
      denom = "n_altdf",
      denom_by = subgrpvar,
      riskdiff = FALSE,
      extrablankline = TRUE,
      .stats = c("n_altdf")
    )
  ) %>%
  split_rows_by(
    "PARCAT56",
    label_pos = "topleft",
    child_labels = "visible",
    split_label = "NCI-CTCAE Category",
    ### trim_levels_to_map needs to be applied at ALL split_rows_by levels
    split_fun = trim_levels_to_map(param_map),
    section_div = " ",
    indent_mod = indent_adj,
  ) %>%
  split_rows_by(
    "ATOXDSCLH",
    label_pos = "topleft",
    child_labels = "visible",
    split_label = "Laboratory Test",
    ### trim_levels_to_map needs to be applied at ALL split_rows_by levels
    split_fun = trim_levels_to_map(param_map),
    section_div = " "
  ) %>%
  append_topleft("    Grade, n (%)")

# version without explicit denominator (as in shell)
lyt <- lyt0 %>%
  # for testing, it is sometimes convenient to explicitely show the used denominator
  analyze(
    "ATOXGRLH",
    a_freq_j,
    extra_args = extra_args_rr,
    show_labels = "hidden",
    indent_mod = 0L
  )

result <- build_table(lyt, filtered_adlb_tox, alt_counts_df = adsl)

# version with explicit denominator (for verification)
lyt2 <- lyt0 %>%
  # for testing, it is sometimes convenient to explicitely show the used denominator
  analyze(
    "ATOXGRLH",
    a_freq_j,
    extra_args = extra_args_rr2,
    show_labels = "visible",
    indent_mod = 0L
  )

### apply layout
result2 <- build_table(lyt2, filtered_adlb_tox, alt_counts_df = adsl)

# Post-Processing:

remove_grade0 <- function(tr) {
  if (is(tr, "DataRow") & (tr@label == "Grade 0")) {
    return(FALSE)
  } else {
    return(TRUE)
  }
}

result <- result %>% prune_table(prune_func = keep_rows(remove_grade0))
result2 <- result2 %>% prune_table(prune_func = keep_rows(remove_grade0))

# Remove colcount from rrisk_header:

result <- remove_col_count(result)
result2 <- remove_col_count(result2)

# Add titles and footnotes:

result <- set_titles(result, titles)

# Convert to tbl file and output table

tt_to_tlgrtf(string_map = string_map, tt = result, file = fileid, orientation = "landscape")

TSFLAB03a: Subjects With =1 Laboratory Values With Elevated or Low Values Based on Worst On-treatment Value Using NCI-CTCAE Criteria by [Subgroup]; Safety Analysis Set (Study jjcs - core)

NCI-CTCAE Category

Active Study Agent

Risk Difference (%) (95% CI)

Laboratory Test

Xanomeline High Dose

Xanomeline Low Dose

Placebo

Xanomeline High Dose vs Placebo

Xanomeline Low Dose vs Placebo

Grade, n (%)

N=53

N=73

N=59

Age: ≥18 to <65 years

8

5

7

Blood and lymphatic system
 disorders

Anemia

N

8

5

7

Grade 1

7 (87.5%)

5 (100.0%)

5 (71.4%)

16.1 (-24.5, 56.6)

28.6 (-4.9, 62.0)

Grade 2

5 (62.5%)

5 (100.0%)

2 (28.6%)

33.9 (-13.5, 81.3)

71.4 (38.0, 100.0)

Grade 3

2 (25.0%)

2 (40.0%)

0

25.0 (-5.0, 55.0)

40.0 (-2.9, 82.9)

Leukocytosis

N

8

5

7

Grade 3

0

0

0

0.0 (0.0, 0.0)

0.0 (0.0, 0.0)

Metabolism and nutritional
 disorders

Hyperkalemia

N

8

5

7

Grade 1

0

0

0

0.0 (0.0, 0.0)

0.0 (0.0, 0.0)

Grade 2

0

0

0

0.0 (0.0, 0.0)

0.0 (0.0, 0.0)

Grade 3

0

0

0

0.0 (0.0, 0.0)

0.0 (0.0, 0.0)

Grade 4

0

0

0

0.0 (0.0, 0.0)

0.0 (0.0, 0.0)

Hypernatremia

N

8

5

7

Grade 1

0

0

1 (14.3%)

-14.3 (-40.2, 11.6)

-14.3 (-40.2, 11.6)

Grade 2

0

0

0

0.0 (0.0, 0.0)

0.0 (0.0, 0.0)

Grade 3

0

0

0

0.0 (0.0, 0.0)

0.0 (0.0, 0.0)

Grade 4

0

0

0

0.0 (0.0, 0.0)

0.0 (0.0, 0.0)

Hypoalbuminemia

N

8

5

7

Grade 1

8 (100.0%)

4 (80.0%)

6 (85.7%)

14.3 (-11.6, 40.2)

-5.7 (-49.3, 37.9)

Grade 2

7 (87.5%)

4 (80.0%)

6 (85.7%)

1.8 (-32.8, 36.4)

-5.7 (-49.3, 37.9)

Grade 3

2 (25.0%)

0

3 (42.9%)

-17.9 (-65.2, 29.5)

-42.9 (-79.5, -6.2)

Hypoglycemia

N

8

5

7

Grade 1

4 (50.0%)

3 (60.0%)

7 (100.0%)

-50.0 (-84.6, -15.4)

-40.0 (-82.9, 2.9)

Grade 2

6 (75.0%)

2 (40.0%)

6 (85.7%)

-10.7 (-50.4, 28.9)

-45.7 (-95.9, 4.4)

Grade 3

5 (62.5%)

3 (60.0%)

3 (42.9%)

19.6 (-30.0, 69.3)

17.1 (-39.3, 73.6)

Grade 4

2 (25.0%)

0

1 (14.3%)

10.7 (-28.9, 50.4)

-14.3 (-40.2, 11.6)

Hypokalemia

N

8

5

7

Grade 2

4 (50.0%)

5 (100.0%)

5 (71.4%)

-21.4 (-69.6, 26.7)

28.6 (-4.9, 62.0)

Grade 3

2 (25.0%)

2 (40.0%)

3 (42.9%)

-17.9 (-65.2, 29.5)

-2.9 (-59.3, 53.6)

Grade 4

1 (12.5%)

0

0

12.5 (-10.4, 35.4)

0.0 (0.0, 0.0)

Hyponatremia

N

8

5

7

Grade 1

7 (87.5%)

4 (80.0%)

5 (71.4%)

16.1 (-24.5, 56.6)

8.6 (-39.9, 57.0)

Grade 3

3 (37.5%)

1 (20.0%)

3 (42.9%)

-5.4 (-55.0, 44.3)

-22.9 (-73.6, 27.9)

Grade 4

0

0

0

0.0 (0.0, 0.0)

0.0 (0.0, 0.0)

Age: ≥65 to <75 years

16

17

19

Blood and lymphatic system
 disorders

Anemia

N

16

17

19

Grade 1

11 (68.8%)

10 (58.8%)

17 (89.5%)

-20.7 (-47.3, 5.9)

-30.7 (-57.8, -3.5)

Grade 2

11 (68.8%)

8 (47.1%)

13 (68.4%)

0.3 (-30.5, 31.2)

-21.4 (-53.0, 10.3)

Grade 3

9 (56.2%)

5 (29.4%)

9 (47.4%)

8.9 (-24.2, 42.0)

-18.0 (-49.2, 13.2)

Leukocytosis

N

16

17

19

Grade 3

0

0

0

0.0 (0.0, 0.0)

0.0 (0.0, 0.0)

Metabolism and nutritional
 disorders

Hyperkalemia

N

16

17

19

Grade 1

0

0

0

0.0 (0.0, 0.0)

0.0 (0.0, 0.0)

Grade 2

1 (6.2%)

0

0

6.2 (-5.6, 18.1)

0.0 (0.0, 0.0)

Grade 3

0

0

0

0.0 (0.0, 0.0)

0.0 (0.0, 0.0)

Grade 4

0

0

0

0.0 (0.0, 0.0)

0.0 (0.0, 0.0)

Hypernatremia

N

16

17

19

Grade 1

2 (12.5%)

2 (11.8%)

5 (26.3%)

-13.8 (-39.4, 11.8)

-14.6 (-39.6, 10.5)

Grade 2

1 (6.2%)

0

0

6.2 (-5.6, 18.1)

0.0 (0.0, 0.0)

Grade 3

0

0

0

0.0 (0.0, 0.0)

0.0 (0.0, 0.0)

Grade 4

0

0

0

0.0 (0.0, 0.0)

0.0 (0.0, 0.0)

Hypoalbuminemia

N

16

17

19

Grade 1

15 (93.8%)

10 (58.8%)

18 (94.7%)

-1.0 (-16.5, 14.6)

-35.9 (-61.4, -10.5)

Grade 2

10 (62.5%)

6 (35.3%)

14 (73.7%)

-11.2 (-42.1, 19.7)

-38.4 (-68.5, -8.3)

Grade 3

7 (43.8%)

4 (23.5%)

6 (31.6%)

12.2 (-19.9, 44.2)

-8.0 (-37.1, 21.0)

Hypoglycemia

N

16

17

19

Grade 1

13 (81.2%)

11 (64.7%)

18 (94.7%)

-13.5 (-35.1, 8.1)

-30.0 (-54.9, -5.2)

Grade 2

11 (68.8%)

8 (47.1%)

10 (52.6%)

16.1 (-15.8, 48.1)

-5.6 (-38.2, 27.1)

Grade 3

7 (43.8%)

5 (29.4%)

6 (31.6%)

12.2 (-19.9, 44.2)

-2.2 (-32.3, 27.9)

Grade 4

1 (6.2%)

2 (11.8%)

0

6.2 (-5.6, 18.1)

11.8 (-3.6, 27.1)

Hypokalemia

N

16

16

19

Grade 2

12 (75.0%)

5 (31.2%)

11 (57.9%)

17.1 (-13.6, 47.8)

-26.6 (-58.4, 5.1)

Grade 3

6 (37.5%)

4 (25.0%)

10 (52.6%)

-15.1 (-47.8, 17.5)

-27.6 (-58.5, 3.3)

Grade 4

1 (6.2%)

1 (6.2%)

2 (10.5%)

-4.3 (-22.5, 13.9)

-4.3 (-22.5, 13.9)

Hyponatremia

N

16

15

19

Grade 1

14 (87.5%)

11 (73.3%)

17 (89.5%)

-2.0 (-23.3, 19.3)

-16.1 (-42.4, 10.2)

Grade 3

5 (31.2%)

8 (53.3%)

7 (36.8%)

-5.6 (-37.0, 25.8)

16.5 (-16.8, 49.8)

Grade 4

2 (12.5%)

1 (6.7%)

0

12.5 (-3.7, 28.7)

6.7 (-6.0, 19.3)

Age: ≥75 years

29

51

33

Blood and lymphatic system
 disorders

Anemia

N

29

51

33

Grade 1

24 (82.8%)

41 (80.4%)

29 (87.9%)

-5.1 (-22.8, 12.6)

-7.5 (-23.1, 8.1)

Grade 2

19 (65.5%)

25 (49.0%)

21 (63.6%)

1.9 (-22.0, 25.7)

-14.6 (-36.0, 6.8)

Grade 3

10 (34.5%)

23 (45.1%)

12 (36.4%)

-1.9 (-25.7, 22.0)

8.7 (-12.6, 30.1)

Leukocytosis

N

29

51

33

Grade 3

0

0

0

0.0 (0.0, 0.0)

0.0 (0.0, 0.0)

Metabolism and nutritional
 disorders

Hyperkalemia

N

29

51

33

Grade 1

1 (3.4%)

0

1 (3.0%)

0.4 (-8.4, 9.3)

-3.0 (-8.9, 2.8)

Grade 2

0

0

1 (3.0%)

-3.0 (-8.9, 2.8)

-3.0 (-8.9, 2.8)

Grade 3

0

0

0

0.0 (0.0, 0.0)

0.0 (0.0, 0.0)

Grade 4

0

0

0

0.0 (0.0, 0.0)

0.0 (0.0, 0.0)

Hypernatremia

N

29

51

33

Grade 1

5 (17.2%)

4 (7.8%)

4 (12.1%)

5.1 (-12.6, 22.8)

-4.3 (-17.6, 9.1)

Grade 2

1 (3.4%)

0

0

3.4 (-3.2, 10.1)

0.0 (0.0, 0.0)

Grade 3

0

0

0

0.0 (0.0, 0.0)

0.0 (0.0, 0.0)

Grade 4

0

0

0

0.0 (0.0, 0.0)

0.0 (0.0, 0.0)

Hypoalbuminemia

N

29

51

33

Grade 1

25 (86.2%)

38 (74.5%)

25 (75.8%)

10.4 (-8.8, 29.7)

-1.2 (-20.1, 17.6)

Grade 2

17 (58.6%)

31 (60.8%)

20 (60.6%)

-2.0 (-26.5, 22.5)

0.2 (-21.2, 21.6)

Grade 3

14 (48.3%)

15 (29.4%)

12 (36.4%)

11.9 (-12.6, 36.4)

-7.0 (-27.6, 13.7)

Hypoglycemia

N

29

50

33

Grade 1

24 (82.8%)

36 (72.0%)

30 (90.9%)

-8.2 (-25.0, 8.7)

-18.9 (-34.8, -3.1)

Grade 2

21 (72.4%)

25 (50.0%)

21 (63.6%)

8.8 (-14.3, 31.9)

-13.6 (-35.1, 7.8)

Grade 3

9 (31.0%)

17 (34.0%)

14 (42.4%)

-11.4 (-35.2, 12.4)

-8.4 (-29.8, 12.9)

Grade 4

2 (6.9%)

0

2 (6.1%)

0.8 (-11.5, 13.1)

-6.1 (-14.2, 2.1)

Hypokalemia

N

29

51

31

Grade 2

22 (75.9%)

28 (54.9%)

22 (71.0%)

4.9 (-17.4, 27.2)

-16.1 (-37.1, 5.0)

Grade 3

17 (58.6%)

17 (33.3%)

15 (48.4%)

10.2 (-14.9, 35.3)

-15.1 (-36.9, 6.8)

Grade 4

3 (10.3%)

5 (9.8%)

2 (6.5%)

3.9 (-10.2, 18.0)

3.4 (-8.5, 15.2)

Hyponatremia

N

29

51

33

Grade 1

26 (89.7%)

38 (74.5%)

29 (87.9%)

1.8 (-13.9, 17.5)

-13.4 (-29.7, 3.0)

Grade 3

13 (44.8%)

19 (37.3%)

15 (45.5%)

-0.6 (-25.5, 24.2)

-8.2 (-29.8, 13.4)

Grade 4

3 (10.3%)

0

0

10.3 (-0.7, 21.4)

0.0 (0.0, 0.0)

Note: On-treatment is defined as treatment-emergentlaboratory values obtained after the first dose and within [30 days] following treatment discontinuation. [Treatment-emergent values are those that worsened from baseline.]

Note: NCI-CTCAE grades (version 5.0.) are based on the laboratory result and do not take into account the clinical component, if applicable.

Download RTF file

TSFLAB03
TSFLAB04A
Source Code
---
title: TSFLAB03A
subtitle: Subjects With =1 Laboratory Values With Elevated or Low Values Based on Worst On-treatment Value Using NCI-CTCAE Criteria by Subgroup
---

------------------------------------------------------------------------

{{< include ../../_utils/envir_hook.qmd >}}

```{r setup, echo = FALSE, warning = FALSE, message = FALSE}
options(docx.add_datetime = FALSE, tidytlg.add_datetime = FALSE)
envsetup_config_name <- "default"

# Path to the combined config file
envsetup_file_path <- file.path("../..", "envsetup.yml")

Sys.setenv(ENVSETUP_ENVIRON = '')
library(envsetup)
loaded_config <- config::get(config = envsetup_config_name, file = envsetup_file_path)
envsetup::rprofile(loaded_config)


dpscomp <- compound
dpspdr <- paste(protocol,dbrelease,rpteff,sep="__")

aptcomp <- compound
aptpdr <- paste(protocol,dbrelease,rpteff,sep="__")

###### Study specific updates (formerly in envre)

dpscomp <- "standards"
dpspdr <- "jjcs__NULL__jjcs - core"

apt <- FALSE
library(junco)
default_str_map <- rbind(default_str_map, c("&ctcae", "5.0"))

```

## Output

:::: panel-tabset
## {{< fa regular file-lines sm fw >}} Preview

```{r variant1, results='hide', warning = FALSE, message = FALSE}

# Program Name:              tsflab03a

# Prep Environment

library(envsetup)
library(tern)
library(dplyr)
library(rtables)
library(junco)

# Define script level parameters:

tblid <- "TSFLAB03a"
fileid <- tblid
titles <- get_titles_from_file(input_path = '../../_data/', tblid)
string_map <- default_str_map

popfl <- "SAFFL"
trtvar <- "TRT01A"
ctrl_grp <- "Placebo"

subgrpvar <- "AGEGR1"
subgrplbl <- "Age: %s years"

page_by <- TRUE # Set page_by TRUE/FALSE if you (do not) wish to start a new page after a new subgroup
indent_adj <- -1L
if (page_by) {
  indent_adj <- 0L
}

## if the option TRTEMFL needs to be added to the TLF
trtemfl <- FALSE

## For analysis on SI units: use adlb dataset
## For analysis on Conventional units: use adlbc dataset -- shell is in conventional units

ad_domain <- "ADLB"

# Initial processing of data + check if table is valid for trial:

adlb_complete <- pharmaverseadamjnj::adlb


## parcat5 and 6 options :

availparcat56 <- c(
  "Investigations",
  "Metabolism and nutritional disorders",
  "Renal and urinary disorders",
  "Blood and lymphatic system disorders"
)

## resrict to some
selparcat56 <- availparcat56[c(1, 2, 4)]

## get all
selparcat56 <- availparcat56

lbtoxgrade_file <- file.path('../../_data', "lbtoxgrade.xlsx")
lbtoxgrade_sheets <- readxl::excel_sheets(path = lbtoxgrade_file)

### CTC5 or DAIDS21c : default CTC5

lbtoxgrade_defs <- readxl::read_excel(lbtoxgrade_file, sheet = "CTC5")

lbtoxgrade_defs <- unique(
  lbtoxgrade_defs %>%
    select(TOXTERM, TOXGRD, INDICATR)
) %>%
  mutate(
    ATOXDSCLH = TOXTERM,
    ATOXGRLH = paste("Grade", TOXGRD)
  ) %>%
  rename(ATOXDIR = INDICATR) %>%
  select(ATOXDSCLH, ATOXGRLH, ATOXDIR)

# Process Data:

adsl <- pharmaverseadamjnj::adsl %>%
  filter(.data[[popfl]] == "Y") %>%
  select(USUBJID, all_of(c(popfl, trtvar, subgrpvar)))

adsl$colspan_trt <- factor(
  ifelse(adsl[[trtvar]] == ctrl_grp, " ", "Active Study Agent"),
  levels = c("Active Study Agent", " ")
)

adsl$rrisk_header <- "Risk Difference (%) (95% CI)"
adsl$rrisk_label <- paste(adsl[[trtvar]], paste("vs", ctrl_grp))

colspan_trt_map <- create_colspan_map(
  adsl,
  non_active_grp = ctrl_grp,
  non_active_grp_span_lbl = " ",
  active_grp_span_lbl = "Active Study Agent",
  colspan_var = "colspan_trt",
  trt_var = trtvar
)

ref_path <- c("colspan_trt", " ", trtvar, ctrl_grp)


## for checking row_counts on AGEGR1 : should consist with counts from ADSL
adsl_agegr1 <- adsl %>%
  select(all_of(c(trtvar, subgrpvar))) %>%
  group_by(across(all_of(c(trtvar, subgrpvar)))) %>%
  summarise(n = n())

adlb00 <- adlb_complete %>%
  select(
    USUBJID,
    AVISITN,
    AVISIT,
    starts_with("PAR"),
    starts_with("ATOX"),
    starts_with("ANL"),
    ONTRTFL,
    TRTEMFL,
    AVAL,
    APOBLFL,
    ABLFL,
    LVOTFL
  ) %>%
  inner_join(adsl) %>%
  mutate(
    ATOXGRL = as.character(ATOXGRL),
    ATOXGRH = as.character(ATOXGRH)
  ) %>%
  relocate(
    .,
    USUBJID,
    all_of(subgrpvar),
    ANL04FL,
    ANL05FL,
    ONTRTFL,
    TRTEMFL,
    AVISIT,
    ATOXGRL,
    ATOXGRH,
    ATOXDSCL,
    ATOXDSCH,
    PARAMCD,
    AVISIT,
    AVAL,
    APOBLFL,
    ABLFL
  )


adlb00 <- adlb00 # %>%
## APT comment on PARCAT6 :
## HGB and WBC : Set to "Blood and lymphatic system disorders".
## HGB and WBC parameter are in 2 categories, one for the high and another one for the low direction grading.
## Anemia (HGB low) and Leukocytosis (WBC high) are in the category "Blood and lymphatic system disorders".
## The grading in the opposite directions are categorized under "Investigations".
## Therefor, both PARCAT5 and PARCAT6 are populated for HGB abd WBC.
## Deal with what is needed at later level, when we have splitted low and high
# mutate(PARCAT56 = coalesce(PARCAT6,PARCAT5)) %>%
# mutate(PARCAT56 = factor(PARCAT56,levels=unique(c(levels(adlb_complete$PARCAT6),levels(adlb_complete$PARCAT5)))))

# obj_label(adlb00$PARCAT56) <- "Combined PARCAT56"

### important: previous actions lost the label of variables

adlb00 <- var_relabel_list(adlb00, var_labels(adlb_complete, fill = T))

parcat <- unique(
  adlb00 %>%
    select(starts_with("PARCAT"), PARAMCD, PARAM, ATOXDSCL, ATOXDSCH) %>%
    filter(!(is.na(PARCAT5) & is.na(PARCAT6)))
)


### data preparation

if (all(selparcat56 != "")) {
  filtered_adlb <- adlb00 %>%
    filter((PARCAT5 %in% selparcat56) | (PARCAT6 %in% selparcat56))
}


### low grades : ATOXDSCL ATOXGRL ANL04FL
### Note on Worst On-treatment
### note: by filter ANL04FL/ANL05FL, this table is restricted to On-treatment values, per definition of ANL04FL/ANL05FL
### therefor, no need to add ONTRTFL in filter
### if derivation of ANL04FL/ANL05FL is not restricted to ONTRTFL records, adding ONTRTFL here will not give the correct answer either
### as mixing worst with other period is not giving the proper selection !!!

filtered_adlb_low <- filtered_adlb %>%
  filter(ANL04FL == "Y" & !is.na(ATOXDSCL) & !is.na(ATOXGRL)) %>%
  mutate(
    ATOXDSCLH = ATOXDSCL,
    ATOXGRLH = ATOXGRL,
    ATOXDIR = "LOW"
  ) %>%
  select(USUBJID, starts_with("PAR"), starts_with("ATOX"), TRTEMFL) %>%
  select(-c(ATOXGRL, ATOXGRH, ATOXDSCL, ATOXDSCH))

### high grades: ATOXDSCH ATOXGRH ANL05FL
filtered_adlb_high <- filtered_adlb %>%
  filter(ANL05FL == "Y" & !is.na(ATOXDSCH) & !is.na(ATOXGRH)) %>%
  mutate(
    ATOXDSCLH = ATOXDSCH,
    ATOXGRLH = ATOXGRH,
    ATOXDIR = "HIGH"
  ) %>%
  select(USUBJID, starts_with("PAR"), starts_with("ATOX"), TRTEMFL) %>%
  select(-c(ATOXGRL, ATOXGRH, ATOXDSCL, ATOXDSCH))

## combine Low and high into adlb_tox
filtered_adlb_tox <-
  bind_rows(
    filtered_adlb_low,
    filtered_adlb_high
  ) %>%
  select(-c(ATOXGR, ATOXGRN)) %>%
  inner_join(adsl)

### correction of proper category (PARCAT56) for HGB (LOW) and WBC (HIGH)
filtered_adlb_tox <-
  filtered_adlb_tox %>%
  mutate(
    PARCAT56 = case_when(
      PARAMCD == "HGB" & ATOXDIR == "LOW" ~ PARCAT6,
      PARAMCD == "WBC" & ATOXDIR == "HIGH" ~ PARCAT6,

      ### fix on synthetic data !!!!
      PARAMCD == "WBC" & ATOXDIR == "LOW" ~ "Investigations",
      TRUE ~ PARCAT5
    )
  ) %>%
  mutate(
    PARCAT56 = factor(
      PARCAT56,
      levels = unique(c(
        "Blood and lymphatic system disorders",
        levels(adlb_complete$PARCAT5)
      ))
    )
  )


#### DO NOT USE TRTEMFL = Y in filter, as this will remove subjects from both numerator and denominator
#### instead : set ATOXGRLH to a non-reportable value (ie Grade 0) and keep in dataset
if (trtemfl) {
  filtered_adlb_tox <- filtered_adlb_tox %>%
    mutate(
      ATOXGRLH = case_when(
        is.na(TRTEMFL) | TRTEMFL != "Y" ~ "0",
        TRUE ~ ATOXGRLH
      )
    )
}


## convert some to factors -- lty will fail if these are not factors
filtered_adlb_tox <-
  filtered_adlb_tox %>%
  mutate(
    ATOXGRLH = factor(paste("Grade", ATOXGRLH), levels = paste("Grade", 0:5)),
    ATOXDIR = factor(ATOXDIR, levels = c("LOW", "HIGH"))
  )


filtered_adlb_tox <- unique(
  filtered_adlb_tox
)

check_non_unique_subject <- filtered_adlb_tox %>%
  group_by(USUBJID, PARAMCD, ATOXDSCLH) %>%
  summarize(n_subject = n()) %>%
  filter(n_subject > 1)

if (nrow(check_non_unique_subject)) {
  message(
    "Please review your data selection process, subject has multiple records"
  )
}


params <- unique(
  filtered_adlb_tox %>% select(PARCAT56, PARAMCD, PARAM, ATOXDSCLH, ATOXDIR)
)

all_params <- unique(
  adlb_complete %>%
    filter(!(is.na(PARCAT5) & is.na(PARCAT6))) %>%
    select(PARCAT5, PARCAT6, PARAMCD, PARAM, ATOXDSCL, ATOXDSCH)
)

### add relevant extra vars to lbtoxgrade_defs, only restrict to those actually in trial
### Neutrophil Count Decreased (NEUTSG NEUT) is causing for the many-to-many warning
lbtoxgrade_defs <- lbtoxgrade_defs %>%
  inner_join(
    .,
    unique(
      filtered_adlb_tox %>%
        select(PARAMCD, PARAM, ATOXDIR, ATOXDSCLH, PARCAT5, PARCAT6, PARCAT56)
    )
  )


### Define param_map to be used in layout
param_map <- lbtoxgrade_defs %>%
  select(PARCAT56, PARAM, PARAMCD, ATOXDIR, ATOXDSCLH, ATOXGRLH) %>%
  ### for proper sorting: add factor levels to PARAMCD, ATOXDIR
  mutate(
    PARAMCD = factor(PARAMCD, levels = levels(adlb00$PARAMCD)),
    ATOXDIR = factor(ATOXDIR, levels = c("LOW", "HIGH"))
  ) %>%
  # ### actual sorting
  #   arrange(PARCAT56,PARAMCD,ATOXDIR,ATOXGRLH) %>%
  ### actual sorting -- all alphabetic on output
  arrange(PARCAT56, ATOXDSCLH) %>%
  ### !!!! no factors are allowed in this split_fun map definition
  mutate(
    PARCAT56 = as.character(PARCAT56),
    PARAMCD = as.character(PARAMCD),
    PARAM = as.character(PARAM),
    ATOXDIR = as.character(ATOXDIR),
    ATOXDSCLH = as.character(ATOXDSCLH)
  ) # %>%
### !!!! do not remove Grade 0 here, as this would lead to incorrect N and % derivation
### filter(ATOXGRLH != "Grade 0")
### Grade 0 will be removed as a post-processing step

# Define layout and build table:

extra_args_rr <- list(
  method = "wald",
  denom = "n_df",
  ref_path = ref_path,
  .stats = c("denom", "count_unique_fraction"),
  denom_by = subgrpvar
)
extra_args_rr2 <- list(
  method = "wald",
  denom = "n_df",
  ref_path = ref_path,
  .stats = c("denom", "count_unique_denom_fraction"),
  denom_by = subgrpvar
)


lyt0 <- basic_table(show_colcounts = TRUE, colcount_format = "N=xx") %>%
  ### first columns
  split_cols_by(
    "colspan_trt",
    split_fun = trim_levels_to_map(map = colspan_trt_map)
  ) %>%
  split_cols_by(trtvar) %>%
  split_cols_by("rrisk_header", nested = FALSE) %>%
  split_cols_by(
    trtvar,
    labels_var = "rrisk_label",
    split_fun = remove_split_levels(ctrl_grp)
  ) %>%
  split_rows_by(
    subgrpvar,
    label_pos = "hidden",
    section_div = " ",
    split_fun = drop_split_levels,
    page_by = page_by
  ) %>%
  ###
  summarize_row_groups(
    var = subgrpvar,
    cfun = a_freq_j,
    extra_args = list(
      label_fstr = subgrplbl,
      denom = "n_altdf",
      denom_by = subgrpvar,
      riskdiff = FALSE,
      extrablankline = TRUE,
      .stats = c("n_altdf")
    )
  ) %>%
  split_rows_by(
    "PARCAT56",
    label_pos = "topleft",
    child_labels = "visible",
    split_label = "NCI-CTCAE Category",
    ### trim_levels_to_map needs to be applied at ALL split_rows_by levels
    split_fun = trim_levels_to_map(param_map),
    section_div = " ",
    indent_mod = indent_adj,
  ) %>%
  split_rows_by(
    "ATOXDSCLH",
    label_pos = "topleft",
    child_labels = "visible",
    split_label = "Laboratory Test",
    ### trim_levels_to_map needs to be applied at ALL split_rows_by levels
    split_fun = trim_levels_to_map(param_map),
    section_div = " "
  ) %>%
  append_topleft("    Grade, n (%)")

# version without explicit denominator (as in shell)
lyt <- lyt0 %>%
  # for testing, it is sometimes convenient to explicitely show the used denominator
  analyze(
    "ATOXGRLH",
    a_freq_j,
    extra_args = extra_args_rr,
    show_labels = "hidden",
    indent_mod = 0L
  )

result <- build_table(lyt, filtered_adlb_tox, alt_counts_df = adsl)

# version with explicit denominator (for verification)
lyt2 <- lyt0 %>%
  # for testing, it is sometimes convenient to explicitely show the used denominator
  analyze(
    "ATOXGRLH",
    a_freq_j,
    extra_args = extra_args_rr2,
    show_labels = "visible",
    indent_mod = 0L
  )

### apply layout
result2 <- build_table(lyt2, filtered_adlb_tox, alt_counts_df = adsl)

# Post-Processing:

remove_grade0 <- function(tr) {
  if (is(tr, "DataRow") & (tr@label == "Grade 0")) {
    return(FALSE)
  } else {
    return(TRUE)
  }
}

result <- result %>% prune_table(prune_func = keep_rows(remove_grade0))
result2 <- result2 %>% prune_table(prune_func = keep_rows(remove_grade0))

# Remove colcount from rrisk_header:

result <- remove_col_count(result)
result2 <- remove_col_count(result2)

# Add titles and footnotes:

result <- set_titles(result, titles)

# Convert to tbl file and output table

tt_to_tlgrtf(string_map = string_map, tt = result, file = fileid, orientation = "landscape")
```
```{r result1, echo=FALSE, message=FALSE, warning=FALSE, test = list(result_v1 = "result")}
tt_to_flextable_j(result, tblid, string_map = string_map) 
```

[Download RTF file](`r paste0(tolower(tblid), '.rtf')`)
::::

Made with ❤️ by the J&J Team

  • Edit this page
  • Report an issue
Cookie Preferences