TL Catalog
  1. Tables
  2. Exposure
  3. TSIEX01
  • 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. Exposure
  3. TSIEX01

TSIEX01

Duration of Treatment


Output

  • Preview
Code
# Program Name:              tsiex01.R

# Prep Environment

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

# Define script level parameters:

# - Define output ID and file location

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


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

comp_btw_group <- TRUE
ancova <- TRUE

trtdur <- "TRTDURM"
daysconv <- 30.4375
catlevels <- c(
  "0 to <3 months",
  "3 to <6 months",
  "6 to <9 months",
  "9 to <12 months",
  "12 to <15 months",
  "15 to <18 months",
  "18 to <21 months",
  "21 to <24 months",
  "24 to <27 months",
  "27 to <30 months",
  "30 to <33 months",
  "33 to <36 months",
  "36 to <39 months"
)

combined_colspan_trt <- TRUE

if (combined_colspan_trt == TRUE) {
  # Set up levels and label for the required combined columns
  add_combo <- add_combo_facet(
    "Combined",
    label = "Combined",
    levels = c("Xanomeline High Dose", "Xanomeline Low Dose")
  )

  # choose if any facets need to be removed - e.g remove the combined column for placebo
  rm_combo_from_placebo <- cond_rm_facets(
    facets = "Combined",
    ancestor_pos = NA,
    value = " ",
    split = "colspan_trt"
  )

  mysplit <- make_split_fun(post = list(add_combo, rm_combo_from_placebo))
}

# Process Data:

# Read in required data
adsl <- pharmaverseadamjnj::adsl %>%
  filter(!!rlang::sym(popfl) == "Y") %>%
  select(STUDYID, USUBJID, all_of(trtvar), all_of(popfl))

# If AVISIT is not present in ADEXSUM than create 'Overall' as the Visit, which is used
# for the filtering AVISIT records if it does exist
adexsum <- pharmaverseadamjnj::adexsum %>%
  mutate(VISIT = if (exists("AVISIT")) AVISIT else "Overall") %>%
  filter(PARAMCD == trtdur & !is.na(AVAL) & VISIT == "Overall") %>%
  mutate(
    CRIT0FL = "Y",
    CRIT0 = as.factor("Any duration (at least 1 dose)")
  ) %>%
  select(USUBJID, PARAMCD, AVAL, AVALCAT1, starts_with("CRIT"))

adexsum$CRIT0FL <- factor(adexsum$CRIT0FL, levels = c("Y", "N"))

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

adsl$diff_header <- "Difference in Means (95% CI)"
adsl$diff_label <- paste(adsl[[trtvar]], paste("vs", ctrl_grp))

# join data together
ex <- adexsum %>% inner_join(., adsl, by = c("USUBJID"))

# Keep only columns with some data in which will remove any unwanted CRITy variables
ex <- ex[, colSums(is.na(ex)) < nrow(ex)]

# Work out how many CRITy vars (ignoring CRIT0 we created) we have left
excritvars <- ex %>%
  select(num_range("CRIT", 1:99))

countcritvars <- length(names(excritvars))

# Drop unwanted levels for all CRITy variables you have remaining in ex and also for AVALCAT1

for (i in 1:countcritvars) {
  variable_name <- paste0("CRIT", i)
  ex[[variable_name]] <- droplevels(ex[[variable_name]])
}

# drop unwanted levels from AVALCAT1 and assign levels from specified section at the top of script
ex$AVALCAT1 <- droplevels(ex$AVALCAT1)
ex$AVALCAT1 <- factor(ex$AVALCAT1, levels = catlevels)

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)

# Create label_map to be utilized in the Criterion variables (CRIT)

ex_lblmap <- ex %>%
  select(-CRIT0, -CRIT0FL) %>%
  tidyr::pivot_longer(
    cols = starts_with("CRIT") & ends_with("FL"),
    names_to = "value",
    values_to = "CF_value"
  ) %>%
  # Create the label by selecting the corresponding values from the CRIT columns
  mutate(
    label = case_when(
      value == "CRIT1FL" ~ CRIT1,
      value == "CRIT2FL" ~ CRIT2,
      value == "CRIT3FL" ~ CRIT3,
      value == "CRIT4FL" ~ CRIT4,
      value == "CRIT5FL" ~ CRIT5,
      value == "CRIT6FL" ~ CRIT6,
      value == "CRIT7FL" ~ CRIT7
    )
  ) %>%
  select(value, label) %>%
  distinct()

# Define layout and build table:

extra_args_rr <- list(.stats = c("count_unique_fraction"), riskdiff = FALSE)

lyt <- rtables::basic_table(
  top_level_section_div = " ",
  show_colcounts = TRUE,
  colcount_format = "N=xx"
) %>%
  split_cols_by(
    "colspan_trt",
    split_fun = trim_levels_to_map(map = colspan_trt_map)
  )

if (combined_colspan_trt == TRUE) {
  lyt <- lyt %>%
    split_cols_by(trtvar, split_fun = mysplit)
} else {
  lyt <- lyt %>%
    split_cols_by(trtvar)
}

lyt <- lyt %>%
  split_cols_by("diff_header", nested = FALSE) %>%
  split_cols_by(
    trtvar,
    split_fun = remove_split_levels(ctrl_grp),
    labels_var = "diff_label"
  ) %>%
  analyze(
    "AVAL",
    afun = a_summarize_ex_j,
    var_labels = "Duration~[super a], ([unit])", #TODO FIX THIS
    show_labels = "visible",
    indent_mod = 0L,
    extra_args = list(
      daysconv = daysconv,
      ref_path = ref_path,
      ancova = ancova,
      comp_btw_group = comp_btw_group,
      variables = list(arm = trtvar, covariates = NULL),
      .formats = c(
        range = jjcsformat_xx("xx.x, xx.x"),
        "diff_mean_est_ci" = jjcsformat_xx("xx.xx (xx.xx, xx.xx)")
      )
    )
  ) %>%
  analyze(
    "AVALCAT1",
    var_labels = "Duration of treatment, n (%)",
    afun = a_freq_j,
    extra_args = extra_args_rr,
    indent_mod = 1L,
    show_labels = "visible",
    nested = FALSE
  ) %>%
  analyze(
    paste0("CRIT", 1, "FL"),
    var_labels = "Duration~[super b], n (%)", #TODO FIX THIS
    afun = a_freq_j,
    extra_args = append(
      extra_args_rr,
      list(label = as.character(ex_lblmap$label[1]), val = "Y")
    ),
    indent_mod = 1L,
    show_labels = "visible",
    nested = FALSE
  )

# Add in analyze for all others CRIT variables contained in ex
for (i in 2:countcritvars) {
  lyt <- lyt %>%
    analyze(
      paste0("CRIT", i, "FL"),
      afun = a_freq_j,
      extra_args = append(
        extra_args_rr,
        list(label = as.character(ex_lblmap$label[i]), val = "Y")
      ),
      indent_mod = 2L,
      show_labels = "hidden"
    )
}

lyt <- lyt %>%
  append_topleft("Parameter")

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

## Remove the N=xx column headers for the Difference (95% CI) columns
result <- remove_col_count(result, span_label_var = "diff_header")

# Add titles and footnotes:

result <- set_titles(result, tab_titles)

# Convert to tbl file and output table

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

TSIEX01: Duration of Treatment; Safety Analysis Set (Study jjcs - core)

Active Study Agent

Difference in Means (95% CI)

Xanomeline High Dose

Xanomeline Low Dose

Combined

Placebo

Xanomeline High Dose vs Placebo

Xanomeline Low Dose vs Placebo

Parameter

N=53

N=73

N=126

N=59

Durationa, ([unit])

Mean (SD)

17.41 (11.408)

20.46 (10.198)

19.18 (10.786)

18.64 (10.656)

-1.23 (-5.23, 2.77)

1.82 (-1.88, 5.52)

Median

16.10

21.20

18.90

18.60

Min, max

0.2, 35.4

0.1, 37.9

0.1, 37.9

0.9, 37.2

Interquartile range

8.30, 27.80

14.70, 28.10

11.30, 28.00

9.30, 26.30

Total treatment (subject
 years)

922.9 (76.9)

1493.8 (124.5)

2416.7 (201.4)

1099.9 (91.7)

Duration of treatment, n (%)

0 to <3 months

7 (13.2%)

4 (5.5%)

11 (8.7%)

2 (3.4%)

3 to <6 months

5 (9.4%)

5 (6.8%)

10 (7.9%)

5 (8.5%)

6 to <9 months

3 (5.7%)

3 (4.1%)

6 (4.8%)

7 (11.9%)

9 to <12 months

4 (7.5%)

2 (2.7%)

6 (4.8%)

7 (11.9%)

12 to <15 months

6 (11.3%)

8 (11.0%)

14 (11.1%)

5 (8.5%)

15 to <18 months

3 (5.7%)

10 (13.7%)

13 (10.3%)

3 (5.1%)

18 to <21 months

5 (9.4%)

4 (5.5%)

9 (7.1%)

5 (8.5%)

21 to <24 months

1 (1.9%)

7 (9.6%)

8 (6.3%)

5 (8.5%)

24 to <27 months

3 (5.7%)

6 (8.2%)

9 (7.1%)

6 (10.2%)

27 to <30 months

6 (11.3%)

9 (12.3%)

15 (11.9%)

2 (3.4%)

30 to <33 months

5 (9.4%)

4 (5.5%)

9 (7.1%)

3 (5.1%)

33 to <36 months

5 (9.4%)

9 (12.3%)

14 (11.1%)

5 (8.5%)

36 to <39 months

0

2 (2.7%)

2 (1.6%)

4 (6.8%)

Durationb, n (%)

<1 month

4 (7.5%)

1 (1.4%)

5 (4.0%)

1 (1.7%)

≥1 month

49 (92.5%)

72 (98.6%)

121 (96.0%)

58 (98.3%)

≥2 months

46 (86.8%)

71 (97.3%)

117 (92.9%)

58 (98.3%)

≥3 months

46 (86.8%)

69 (94.5%)

115 (91.3%)

57 (96.6%)

≥6 months

41 (77.4%)

64 (87.7%)

105 (83.3%)

52 (88.1%)

≥12 months

34 (64.2%)

59 (80.8%)

93 (73.8%)

38 (64.4%)

≥24 months

19 (35.8%)

30 (41.1%)

49 (38.9%)

20 (33.9%)

a Duration of treatment is defined as [(date of last dose of study treatment – date of first dose of study treatment) +1].

b Subjects are summarized in all applicable duration categories.

Download RTF file

TSFECG05
TSIEX02
Source Code
---
title: TSIEX01
subtitle: Duration of Treatment
---

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

{{< 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:              tsiex01.R

# Prep Environment

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

# Define script level parameters:

# - Define output ID and file location

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


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

comp_btw_group <- TRUE
ancova <- TRUE

trtdur <- "TRTDURM"
daysconv <- 30.4375
catlevels <- c(
  "0 to <3 months",
  "3 to <6 months",
  "6 to <9 months",
  "9 to <12 months",
  "12 to <15 months",
  "15 to <18 months",
  "18 to <21 months",
  "21 to <24 months",
  "24 to <27 months",
  "27 to <30 months",
  "30 to <33 months",
  "33 to <36 months",
  "36 to <39 months"
)

combined_colspan_trt <- TRUE

if (combined_colspan_trt == TRUE) {
  # Set up levels and label for the required combined columns
  add_combo <- add_combo_facet(
    "Combined",
    label = "Combined",
    levels = c("Xanomeline High Dose", "Xanomeline Low Dose")
  )

  # choose if any facets need to be removed - e.g remove the combined column for placebo
  rm_combo_from_placebo <- cond_rm_facets(
    facets = "Combined",
    ancestor_pos = NA,
    value = " ",
    split = "colspan_trt"
  )

  mysplit <- make_split_fun(post = list(add_combo, rm_combo_from_placebo))
}

# Process Data:

# Read in required data
adsl <- pharmaverseadamjnj::adsl %>%
  filter(!!rlang::sym(popfl) == "Y") %>%
  select(STUDYID, USUBJID, all_of(trtvar), all_of(popfl))

# If AVISIT is not present in ADEXSUM than create 'Overall' as the Visit, which is used
# for the filtering AVISIT records if it does exist
adexsum <- pharmaverseadamjnj::adexsum %>%
  mutate(VISIT = if (exists("AVISIT")) AVISIT else "Overall") %>%
  filter(PARAMCD == trtdur & !is.na(AVAL) & VISIT == "Overall") %>%
  mutate(
    CRIT0FL = "Y",
    CRIT0 = as.factor("Any duration (at least 1 dose)")
  ) %>%
  select(USUBJID, PARAMCD, AVAL, AVALCAT1, starts_with("CRIT"))

adexsum$CRIT0FL <- factor(adexsum$CRIT0FL, levels = c("Y", "N"))

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

adsl$diff_header <- "Difference in Means (95% CI)"
adsl$diff_label <- paste(adsl[[trtvar]], paste("vs", ctrl_grp))

# join data together
ex <- adexsum %>% inner_join(., adsl, by = c("USUBJID"))

# Keep only columns with some data in which will remove any unwanted CRITy variables
ex <- ex[, colSums(is.na(ex)) < nrow(ex)]

# Work out how many CRITy vars (ignoring CRIT0 we created) we have left
excritvars <- ex %>%
  select(num_range("CRIT", 1:99))

countcritvars <- length(names(excritvars))

# Drop unwanted levels for all CRITy variables you have remaining in ex and also for AVALCAT1

for (i in 1:countcritvars) {
  variable_name <- paste0("CRIT", i)
  ex[[variable_name]] <- droplevels(ex[[variable_name]])
}

# drop unwanted levels from AVALCAT1 and assign levels from specified section at the top of script
ex$AVALCAT1 <- droplevels(ex$AVALCAT1)
ex$AVALCAT1 <- factor(ex$AVALCAT1, levels = catlevels)

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)

# Create label_map to be utilized in the Criterion variables (CRIT)

ex_lblmap <- ex %>%
  select(-CRIT0, -CRIT0FL) %>%
  tidyr::pivot_longer(
    cols = starts_with("CRIT") & ends_with("FL"),
    names_to = "value",
    values_to = "CF_value"
  ) %>%
  # Create the label by selecting the corresponding values from the CRIT columns
  mutate(
    label = case_when(
      value == "CRIT1FL" ~ CRIT1,
      value == "CRIT2FL" ~ CRIT2,
      value == "CRIT3FL" ~ CRIT3,
      value == "CRIT4FL" ~ CRIT4,
      value == "CRIT5FL" ~ CRIT5,
      value == "CRIT6FL" ~ CRIT6,
      value == "CRIT7FL" ~ CRIT7
    )
  ) %>%
  select(value, label) %>%
  distinct()

# Define layout and build table:

extra_args_rr <- list(.stats = c("count_unique_fraction"), riskdiff = FALSE)

lyt <- rtables::basic_table(
  top_level_section_div = " ",
  show_colcounts = TRUE,
  colcount_format = "N=xx"
) %>%
  split_cols_by(
    "colspan_trt",
    split_fun = trim_levels_to_map(map = colspan_trt_map)
  )

if (combined_colspan_trt == TRUE) {
  lyt <- lyt %>%
    split_cols_by(trtvar, split_fun = mysplit)
} else {
  lyt <- lyt %>%
    split_cols_by(trtvar)
}

lyt <- lyt %>%
  split_cols_by("diff_header", nested = FALSE) %>%
  split_cols_by(
    trtvar,
    split_fun = remove_split_levels(ctrl_grp),
    labels_var = "diff_label"
  ) %>%
  analyze(
    "AVAL",
    afun = a_summarize_ex_j,
    var_labels = "Duration~[super a], ([unit])", #TODO FIX THIS
    show_labels = "visible",
    indent_mod = 0L,
    extra_args = list(
      daysconv = daysconv,
      ref_path = ref_path,
      ancova = ancova,
      comp_btw_group = comp_btw_group,
      variables = list(arm = trtvar, covariates = NULL),
      .formats = c(
        range = jjcsformat_xx("xx.x, xx.x"),
        "diff_mean_est_ci" = jjcsformat_xx("xx.xx (xx.xx, xx.xx)")
      )
    )
  ) %>%
  analyze(
    "AVALCAT1",
    var_labels = "Duration of treatment, n (%)",
    afun = a_freq_j,
    extra_args = extra_args_rr,
    indent_mod = 1L,
    show_labels = "visible",
    nested = FALSE
  ) %>%
  analyze(
    paste0("CRIT", 1, "FL"),
    var_labels = "Duration~[super b], n (%)", #TODO FIX THIS
    afun = a_freq_j,
    extra_args = append(
      extra_args_rr,
      list(label = as.character(ex_lblmap$label[1]), val = "Y")
    ),
    indent_mod = 1L,
    show_labels = "visible",
    nested = FALSE
  )

# Add in analyze for all others CRIT variables contained in ex
for (i in 2:countcritvars) {
  lyt <- lyt %>%
    analyze(
      paste0("CRIT", i, "FL"),
      afun = a_freq_j,
      extra_args = append(
        extra_args_rr,
        list(label = as.character(ex_lblmap$label[i]), val = "Y")
      ),
      indent_mod = 2L,
      show_labels = "hidden"
    )
}

lyt <- lyt %>%
  append_topleft("Parameter")

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

## Remove the N=xx column headers for the Difference (95% CI) columns
result <- remove_col_count(result, span_label_var = "diff_header")

# Add titles and footnotes:

result <- set_titles(result, tab_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