TL Catalog
  1. Tables
  2. Disposition of Subjects
  3. TSIDS02
  • 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. Disposition of Subjects
  3. TSIDS02

TSIDS02

Subject Disposition


Output

  • Preview
Code
# Program Name:              tsids02

# Prep environment:

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

# Define script level parameters:

tblid <- "TSIDS02"
fileid <- tblid
popfl <- "FASFL"
trtvar <- "TRT01P"
tab_titles <- get_titles_from_file(input_path = '../../_data/', tblid)
string_map <- default_str_map

# Process data:

adsl <- pharmaverseadamjnj::adsl

no_data_to_report <- function(df, var) {
  if (sum(is.na(df[[var]])) == length(df[[var]])) {
    df[[var]] <- factor(NA_character_, levels = "No data to report")
  }
  return(df)
}

adsl <- no_data_to_report(df = adsl, var = "DCTREAS")
adsl <- no_data_to_report(df = adsl, var = "DCSREAS")

adsl <- adsl %>%
  filter(!!rlang::sym(popfl) == "Y") %>%
  select(
    USUBJID,
    !!rlang::sym(trtvar),
    !!rlang::sym(popfl),
    SAFFL,
    PPROTFL,
    EOTSTT,
    DCTREAS,
    EOSSTT,
    DCSREAS,
    RACE
  ) %>%
  create_colspan_var(
    non_active_grp = "Placebo",
    non_active_grp_span_lbl = " ",
    active_grp_span_lbl = "Active Study Agent",
    colspan_var = "colspan_trt",
    trt_var = trtvar
  ) %>%
  mutate(
    rrisk_header = "Risk Difference (%) 95% CI",
    rrisk_label = paste(!!rlang::sym(trtvar), "vs Placebo")
  )

# Define layout and build table:

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

totdf <- tribble(
  ~valname , ~label  , ~levelcombo                                                 , ~exargs ,
  "Total"  , "Total" , c("Xanomeline High Dose", "Xanomeline Low Dose", "Placebo") , list()
)

rr_method <- "wald"
ref_path <- c("colspan_trt", " ", trtvar, "Placebo")
extra_args_rr <- list(
  method = rr_method,
  ref_path = ref_path,
  .stats = c("count_unique_fraction")
)


lyt <- basic_table(
  show_colcounts = TRUE,
  colcount_format = "N=xx",
  top_level_section_div = " "
) %>%
  split_cols_by(
    "colspan_trt",
    split_fun = trim_levels_to_map(map = colspan_trt_map)
  ) %>%
  split_cols_by(trtvar) %>%
  split_cols_by(
    trtvar,
    split_fun = add_combo_levels(totdf, keep_levels = "Total"),
    nested = FALSE
  ) %>%
  split_cols_by("rrisk_header", nested = FALSE) %>%
  split_cols_by(
    trtvar,
    labels_var = "rrisk_label",
    split_fun = remove_split_levels("Placebo")
  ) %>%
  # Analysis sets
  analyze(
    popfl,
    var_labels = "Analysis set",
    afun = a_freq_j,
    extra_args = append(
      extra_args_rr,
      list(label = "Full", val = "Y", riskdiff = FALSE, NULL)
    ),
    show_labels = "visible"
  ) %>%
  analyze(
    "SAFFL",
    afun = a_freq_j,
    extra_args = append(
      extra_args_rr,
      list(label = "Safety", val = "Y", riskdiff = FALSE, NULL)
    ),
    show_labels = "hidden",
    indent_mod = 1
  ) %>%
  analyze(
    "PPROTFL",
    afun = a_freq_j,
    extra_args = append(
      extra_args_rr,
      list(
        label = "Per protocol",
        val = "Y",
        riskdiff = FALSE,
        extrablankline = TRUE,
        NULL
      )
    ),
    show_labels = "hidden",
    indent_mod = 1,
    na_str = " "
  ) %>%
  # Ongoing
  analyze(
    "EOSSTT",
    show_labels = "hidden",
    afun = a_freq_j,
    extra_args = append(
      extra_args_rr,
      list(
        label = "Subjects ongoing",
        val = "ONGOING",
        riskdiff = FALSE,
        extrablankline = TRUE,
        NULL
      )
    ),
    na_str = " "
  ) %>%
  # Treatment disposition
  analyze(
    "EOTSTT",
    table_names = "Compl_Trt",
    show_labels = "hidden",
    afun = a_freq_j,
    extra_args = append(
      extra_args_rr,
      list(label = "Completed treatment", val = "COMPLETED", NULL)
    )
  ) %>%
  analyze(
    "EOTSTT",
    table_names = "DC_Trt",
    show_labels = "hidden",
    afun = a_freq_j,
    extra_args = append(
      extra_args_rr,
      list(label = "Discontinued treatment", val = "DISCONTINUED", NULL)
    )
  ) %>%
  analyze(
    "DCTREAS",
    show_labels = "hidden",
    indent_mod = 1,
    afun = a_freq_j,
    na_str = " ",
    extra_args = append(extra_args_rr, list(extrablankline = TRUE))
  ) %>%
  # Study disposition
  analyze(
    "EOSSTT",
    table_names = "Compl_Study",
    show_labels = "hidden",
    afun = a_freq_j,
    extra_args = append(
      extra_args_rr,
      list(label = "Completed study", val = "COMPLETED", NULL)
    )
  ) %>%
  analyze(
    "EOSSTT",
    show_labels = "hidden",
    table_names = "DC_Study",
    afun = a_freq_j,
    extra_args = append(
      extra_args_rr,
      list(label = "Discontinued study", val = "DISCONTINUED", NULL)
    )
  ) %>%
  analyze(
    "DCSREAS",
    show_labels = "hidden",
    indent_mod = 1,
    afun = a_freq_j,
    extra_args = append(extra_args_rr, NULL)
  )

result <- build_table(lyt, adsl)

# Post-Processing

## Remove the N=xx column headers for the risk difference columns
result <- remove_col_count(result, span_label_var = "rrisk_header")

result <- result %>%
  sort_at_path(
    path = c(
      "ma_FASFL_SAFFL_PPROTFL_EOSSTT_Compl_Trt_DC_Trt_DCTREAS_Compl_Study_DC_Study_DCSREAS",
      "DCTREAS"
    ),
    scorefun = jj_complex_scorefun(colpath = "Total", lastcat = "Other")
  ) %>%
  sort_at_path(
    path = c(
      "ma_FASFL_SAFFL_PPROTFL_EOSSTT_Compl_Trt_DC_Trt_DCTREAS_Compl_Study_DC_Study_DCSREAS",
      "DCSREAS"
    ),
    scorefun = jj_complex_scorefun(colpath = "Total", lastcat = "Other")
  )

# Prune data driven output.
result <- result %>%
  safe_prune_table(prune_func = keep_rows(keep_non_null_rows)) %>%
  safe_prune_table(
    prune_func = count_pruner(
      cols = c("colspan_trt"),
      cat_exclude = c(
        "Completed study",
        "Completed treatment",
        "Discontinued study",
        "Discontinued treatment"
      )
    )
  )

# Prune data driven output.
result <- result %>%
  safe_prune_table(prune_func = keep_rows(keep_non_null_rows)) %>%
  safe_prune_table(
    prune_func = count_pruner(
      cols = c("colspan_trt"),
      cat_exclude = c(
        "Completed study",
        "Completed treatment",
        "Discontinued study",
        "Discontinued treatment"
      )
    )
  )

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

TSIDS02: Subject Disposition; [Randomized/Enrolled] Analysis Set (Study jjcs - core)

Active Study Agent

Risk Difference (%) 95% CI

Xanomeline High Dose

Xanomeline Low Dose

Placebo

Total

Xanomeline High Dose vs Placebo

Xanomeline Low Dose vs Placebo

N=84

N=84

N=86

N=254

Analysis set

Full

84 (100.0%)

84 (100.0%)

86 (100.0%)

254 (100.0%)

Safety

64 (76.2%)

62 (73.8%)

59 (68.6%)

185 (72.8%)

Per protocol

64 (76.2%)

62 (73.8%)

59 (68.6%)

185 (72.8%)

Subjects ongoing

18 (21.4%)

15 (17.9%)

14 (16.3%)

47 (18.5%)

Completed treatment

19 (22.6%)

21 (25.0%)

49 (57.0%)

89 (35.0%)

-34.4 (-48.1, -20.6)

-32.0 (-45.9, -18.0)

Discontinued treatment

49 (58.3%)

43 (51.2%)

22 (25.6%)

114 (44.9%)

32.8 (18.7, 46.8)

25.6 (11.5, 39.7)

Other

49 (58.3%)

43 (51.2%)

22 (25.6%)

114 (44.9%)

0.0 (0.0, 0.0)

0.0 (0.0, 0.0)

Completed study

22 (26.2%)

21 (25.0%)

48 (55.8%)

91 (35.8%)

-29.6 (-43.7, -15.5)

-30.8 (-44.8, -16.8)

Discontinued study

44 (52.4%)

48 (57.1%)

24 (27.9%)

116 (45.7%)

24.5 (10.2, 38.8)

29.2 (15.0, 43.4)

Other

44 (52.4%)

48 (57.1%)

24 (27.9%)

116 (45.7%)

0.0 (0.0, 0.0)

0.0 (0.0, 0.0)

Download RTF file

TSIDS01
TSIDS02A
Source Code
---
title: TSIDS02
subtitle: Subject Disposition
---

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

{{< 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:              tsids02

# Prep environment:

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

# Define script level parameters:

tblid <- "TSIDS02"
fileid <- tblid
popfl <- "FASFL"
trtvar <- "TRT01P"
tab_titles <- get_titles_from_file(input_path = '../../_data/', tblid)
string_map <- default_str_map

# Process data:

adsl <- pharmaverseadamjnj::adsl

no_data_to_report <- function(df, var) {
  if (sum(is.na(df[[var]])) == length(df[[var]])) {
    df[[var]] <- factor(NA_character_, levels = "No data to report")
  }
  return(df)
}

adsl <- no_data_to_report(df = adsl, var = "DCTREAS")
adsl <- no_data_to_report(df = adsl, var = "DCSREAS")

adsl <- adsl %>%
  filter(!!rlang::sym(popfl) == "Y") %>%
  select(
    USUBJID,
    !!rlang::sym(trtvar),
    !!rlang::sym(popfl),
    SAFFL,
    PPROTFL,
    EOTSTT,
    DCTREAS,
    EOSSTT,
    DCSREAS,
    RACE
  ) %>%
  create_colspan_var(
    non_active_grp = "Placebo",
    non_active_grp_span_lbl = " ",
    active_grp_span_lbl = "Active Study Agent",
    colspan_var = "colspan_trt",
    trt_var = trtvar
  ) %>%
  mutate(
    rrisk_header = "Risk Difference (%) 95% CI",
    rrisk_label = paste(!!rlang::sym(trtvar), "vs Placebo")
  )

# Define layout and build table:

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

totdf <- tribble(
  ~valname , ~label  , ~levelcombo                                                 , ~exargs ,
  "Total"  , "Total" , c("Xanomeline High Dose", "Xanomeline Low Dose", "Placebo") , list()
)

rr_method <- "wald"
ref_path <- c("colspan_trt", " ", trtvar, "Placebo")
extra_args_rr <- list(
  method = rr_method,
  ref_path = ref_path,
  .stats = c("count_unique_fraction")
)


lyt <- basic_table(
  show_colcounts = TRUE,
  colcount_format = "N=xx",
  top_level_section_div = " "
) %>%
  split_cols_by(
    "colspan_trt",
    split_fun = trim_levels_to_map(map = colspan_trt_map)
  ) %>%
  split_cols_by(trtvar) %>%
  split_cols_by(
    trtvar,
    split_fun = add_combo_levels(totdf, keep_levels = "Total"),
    nested = FALSE
  ) %>%
  split_cols_by("rrisk_header", nested = FALSE) %>%
  split_cols_by(
    trtvar,
    labels_var = "rrisk_label",
    split_fun = remove_split_levels("Placebo")
  ) %>%
  # Analysis sets
  analyze(
    popfl,
    var_labels = "Analysis set",
    afun = a_freq_j,
    extra_args = append(
      extra_args_rr,
      list(label = "Full", val = "Y", riskdiff = FALSE, NULL)
    ),
    show_labels = "visible"
  ) %>%
  analyze(
    "SAFFL",
    afun = a_freq_j,
    extra_args = append(
      extra_args_rr,
      list(label = "Safety", val = "Y", riskdiff = FALSE, NULL)
    ),
    show_labels = "hidden",
    indent_mod = 1
  ) %>%
  analyze(
    "PPROTFL",
    afun = a_freq_j,
    extra_args = append(
      extra_args_rr,
      list(
        label = "Per protocol",
        val = "Y",
        riskdiff = FALSE,
        extrablankline = TRUE,
        NULL
      )
    ),
    show_labels = "hidden",
    indent_mod = 1,
    na_str = " "
  ) %>%
  # Ongoing
  analyze(
    "EOSSTT",
    show_labels = "hidden",
    afun = a_freq_j,
    extra_args = append(
      extra_args_rr,
      list(
        label = "Subjects ongoing",
        val = "ONGOING",
        riskdiff = FALSE,
        extrablankline = TRUE,
        NULL
      )
    ),
    na_str = " "
  ) %>%
  # Treatment disposition
  analyze(
    "EOTSTT",
    table_names = "Compl_Trt",
    show_labels = "hidden",
    afun = a_freq_j,
    extra_args = append(
      extra_args_rr,
      list(label = "Completed treatment", val = "COMPLETED", NULL)
    )
  ) %>%
  analyze(
    "EOTSTT",
    table_names = "DC_Trt",
    show_labels = "hidden",
    afun = a_freq_j,
    extra_args = append(
      extra_args_rr,
      list(label = "Discontinued treatment", val = "DISCONTINUED", NULL)
    )
  ) %>%
  analyze(
    "DCTREAS",
    show_labels = "hidden",
    indent_mod = 1,
    afun = a_freq_j,
    na_str = " ",
    extra_args = append(extra_args_rr, list(extrablankline = TRUE))
  ) %>%
  # Study disposition
  analyze(
    "EOSSTT",
    table_names = "Compl_Study",
    show_labels = "hidden",
    afun = a_freq_j,
    extra_args = append(
      extra_args_rr,
      list(label = "Completed study", val = "COMPLETED", NULL)
    )
  ) %>%
  analyze(
    "EOSSTT",
    show_labels = "hidden",
    table_names = "DC_Study",
    afun = a_freq_j,
    extra_args = append(
      extra_args_rr,
      list(label = "Discontinued study", val = "DISCONTINUED", NULL)
    )
  ) %>%
  analyze(
    "DCSREAS",
    show_labels = "hidden",
    indent_mod = 1,
    afun = a_freq_j,
    extra_args = append(extra_args_rr, NULL)
  )

result <- build_table(lyt, adsl)

# Post-Processing

## Remove the N=xx column headers for the risk difference columns
result <- remove_col_count(result, span_label_var = "rrisk_header")

result <- result %>%
  sort_at_path(
    path = c(
      "ma_FASFL_SAFFL_PPROTFL_EOSSTT_Compl_Trt_DC_Trt_DCTREAS_Compl_Study_DC_Study_DCSREAS",
      "DCTREAS"
    ),
    scorefun = jj_complex_scorefun(colpath = "Total", lastcat = "Other")
  ) %>%
  sort_at_path(
    path = c(
      "ma_FASFL_SAFFL_PPROTFL_EOSSTT_Compl_Trt_DC_Trt_DCTREAS_Compl_Study_DC_Study_DCSREAS",
      "DCSREAS"
    ),
    scorefun = jj_complex_scorefun(colpath = "Total", lastcat = "Other")
  )

# Prune data driven output.
result <- result %>%
  safe_prune_table(prune_func = keep_rows(keep_non_null_rows)) %>%
  safe_prune_table(
    prune_func = count_pruner(
      cols = c("colspan_trt"),
      cat_exclude = c(
        "Completed study",
        "Completed treatment",
        "Discontinued study",
        "Discontinued treatment"
      )
    )
  )

# Prune data driven output.
result <- result %>%
  safe_prune_table(prune_func = keep_rows(keep_non_null_rows)) %>%
  safe_prune_table(
    prune_func = count_pruner(
      cols = c("colspan_trt"),
      cat_exclude = c(
        "Completed study",
        "Completed treatment",
        "Discontinued study",
        "Discontinued treatment"
      )
    )
  )

# 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