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

TSFECG04

Shift From Baseline to Maximum On-treatment Corrected QT Interval


Output

  • Preview
Code
# Program Name:              tsfecg04

# Prep Environment

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

# Define script level parameters:

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

popfl <- "SAFFL"
trtvar <- "TRT01A"
ctrl_grp <- "Placebo"
demogvars <- c("SEX", "AGEGR1", "RACE", "ETHNIC", "AGE")

ad_domain <- "ADEG"

## selection of QTC parameters
selparamcd <- c("QTCFAG", "QTCBAG", "QTCS", "QTCLAG")

# initial read of data

adeg_complete <- pharmaverseadamjnj::adeg

### available QTC parameters in study
selparamcd <- intersect(selparamcd, unique(adeg_complete$PARAMCD))

catvar <- "AVALCAT1"

# Process Data:

adsl <- pharmaverseadamjnj::adsl %>%
  filter(!!sym(popfl) == "Y") %>%
  select(STUDYID, USUBJID, all_of(c(trtvar, popfl, demogvars)))

adsl <- adsl %>%
  mutate(
    colspan_trt = factor(
      ifelse(!!sym(trtvar) == ctrl_grp, " ", "Active Study Agent"),
      levels = c("Active Study Agent", " ")
    )
  )
## to ensure the same order as on other outputs
trt_order <- as.character((unique(
  adsl %>% select("colspan_trt", all_of(trtvar))
) %>%
  arrange(colspan_trt, !!sym(trtvar)))[[trtvar]])
adsl[[trtvar]] <- factor(as.character(adsl[[trtvar]]), levels = trt_order)

adeg <- adeg_complete %>%
  filter(PARAMCD %in% selparamcd) %>%
  ### Maximum On-treatment
  ### note: by filter ANL03FL, this table is restricted to On-treatment values, per definition of ANL03FL
  ### therefor, no need to add ONTRTFL in filter
  ### if derivation of ANL03FL 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 !!!
  filter(ANL03FL == "Y") %>%
  select(
    USUBJID,
    ONTRTFL,
    TRTEMFL,
    PARAM,
    PARAMCD,
    AVISITN,
    AVISIT,
    AVAL,
    BASE,
    CHG,
    AVALCAT1,
    BASECAT1,
    ONTRTFL,
    TRTEMFL,
    ANL01FL,
    ANL02FL,
    ANL03FL
  ) %>%
  inner_join(., adsl)

adeg$AVISIT <- factor("Maximum Corrected QT Interval")

## if also over time is needed, append these to above dataset
## see ecg05 as example

check1 <- adeg %>%
  group_by(TRT01A, PARAMCD, AVISIT) %>%
  summarize(n = n_distinct(USUBJID))


## add variable for column split header
adeg$BASECAT1_header <- "Baseline Corrected QT Interval"
adeg$BASECAT1_header2 <- " " ## first column N should not appear under Baseline column span

adeg$BASECAT1_header3 <- " " ## extra to allow for additional topleft material

###
AVALCAT1_levels <- levels(adeg$AVALCAT1)


## add extra level N to Basecat1
adeg <- adeg %>%
  mutate(
    BASECAT1 = factor(as.character(BASECAT1), levels = c("N", AVALCAT1_levels))
  )


## trick for alt_counts_df to work with col splitting
# add BASECAT1 to adsl, all assign to extra level N (column will be used for N counts)
adslx <- adsl %>%
  mutate(BASECAT1 = "N") %>%
  mutate(BASECAT1 = factor(BASECAT1, levels = c("N", AVALCAT1_levels)))


adslx$BASECAT1_header <- "Baseline Corrected QT Interval"
adslx$BASECAT1_header2 <- " "
adslx$BASECAT1_header3 <- " " ## extra to allow for additional topleft material

# Define layout and build table:

lyt <- basic_table(show_colcounts = FALSE) %>%
  split_cols_by("BASECAT1_header3") %>%
  ## to ensure N column is not under the Baseline column span header
  split_cols_by("BASECAT1_header2") %>%
  split_cols_by("BASECAT1", split_fun = keep_split_levels("N")) %>%
  ## restart column split (Nested = False)
  ## Combined levels will be made, and the N column should not appear
  split_cols_by("BASECAT1_header", nested = FALSE) %>%
  split_cols_by(
    "BASECAT1",
    split_fun = make_split_fun(
      pre = list(rm_levels(excl = "N")),
      post = list(
        add_overall_facet("TOTAL", "Total")
      )
    )
  ) %>%
  #### replace split_rows and summarize by single analyze call
  ### a_freq_j only works due to
  ### special arguments can do the trick : denomf = adslx & .stats = count_unique
  ### we want counts of treatment group coming from adsl, not from input dataset, therefor, countsource = altdf
  analyze(
    vars = trtvar,
    afun = a_freq_j,
    extra_args = list(
      restr_columns = "N",
      .stats = "count_unique",
      countsource = "altdf",
      extrablankline = TRUE
    ),
    indent_mod = -1L
  ) %>%
  # ## main part of table
  split_rows_by(
    "PARAM",
    nested = FALSE,
    label_pos = "topleft",
    child_labels = "visible",
    split_label = "QTc Interval",
    split_fun = drop_split_levels,
    section_div = " "
  ) %>%
  split_rows_by(
    trtvar,
    label_pos = "topleft",
    indent_mod = -1L,
    child_labels = "hidden",
    split_label = "Treatment Group",
    section_div = " "
  ) %>%
  ### a_freq_j
  ### the special statistic "n_rowdf" option does the trick here of getting the proper value for the N column
  summarize_row_groups(
    trtvar,
    cfun = a_freq_j,
    extra_args = list(
      .stats = "n_rowdf",
      restr_columns = c("N")
    )
  ) %>%
  split_rows_by(
    "AVISIT",
    label_pos = "hidden",
    indent_mod = 1L,
    split_label = " ",
    child_labels = "visible",
    section_div = " "
  ) %>%
  ## add extra level TOTAL using new_levels, rather than earlier technique
  ## advantage for denominator derivation -- n_rowdf can be used, if we'd like to present fraction as well
  ## switch .stats to count_unique_denom_fraction or count_unique_fraction
  analyze(
    "AVALCAT1",
    afun = a_freq_j,
    extra_args = list(
      .stats = "count_unique",
      denom = "n_rowdf",
      new_levels = list(c("Total"), list(AVALCAT1_levels)),
      new_levels_after = TRUE,
      .indent_mods = 1L,
      restr_columns = c(
        toupper(AVALCAT1_levels),
        "TOTAL"
      )
    )
  ) %>%
  append_topleft("    Criteria, n")

result <- build_table(lyt, adeg, alt_counts_df = adslx)

# Add titles and footnotes:

result <- set_titles(result, titles)

# Convert to tbl file and output table

# the default column-widths had issues with 2 columns appear too close
# retrieve the default column widths and update the latter columns
fontspec <- font_spec("Times", 9L, 1.2)
col_gap <- 7L
label_width_ins <- 2

colwidths <- def_colwidths(
  result,
  fontspec,
  col_gap = col_gap,
  label_width_ins = label_width_ins
)

# adjust the column-widths to have the same length for columns 3 - 7 (<= 450, ...., Total)
acolwidths <- colwidths
acolwidths[3:length(acolwidths)] <- 12

tt_to_tlgrtf(string_map = string_map, tt = result, file = fileid, colwidths = acolwidths)

TSFECG04: Shift From Baseline to Maximum On-treatment Corrected QT Interval; Safety Analysis Set (Study jjcs - core)

QTc Interval

Treatment Group

Baseline Corrected QT Interval

Criteria, n

N

≤450

>450 to ≤480

>480 to ≤500

>500

Total

Xanomeline High Dose

53

Xanomeline Low Dose

73

Placebo

59

QTcB Interval, Aggregate
 (msec)

Xanomeline High Dose

53

Maximum Corrected QT
 Interval

≤450

31

2

3

5

41

>450 to ≤480

4

0

2

0

6

>480 to ≤500

1

0

0

1

2

>500

1

2

0

1

4

Total

37

4

5

7

53

Xanomeline Low Dose

53

Maximum Corrected QT
 Interval

≤450

31

3

2

2

38

>450 to ≤480

2

1

0

1

4

>480 to ≤500

4

1

0

1

6

>500

5

0

0

0

5

Total

42

5

2

4

53

Placebo

56

Maximum Corrected QT
 Interval

≤450

40

4

1

2

47

>450 to ≤480

2

0

1

1

4

>480 to ≤500

2

0

0

0

2

>500

0

0

2

1

3

Total

44

4

4

4

56

QTcF Interval, Aggregate
 (msec)

Xanomeline High Dose

53

Maximum Corrected QT
 Interval

≤450

33

2

4

3

42

>450 to ≤480

3

0

0

0

3

>480 to ≤500

6

0

0

0

6

>500

2

0

0

0

2

Total

44

2

4

3

53

Xanomeline Low Dose

53

Maximum Corrected QT
 Interval

≤450

34

2

0

4

40

>450 to ≤480

3

0

0

1

4

>480 to ≤500

4

0

0

0

4

>500

4

0

1

0

5

Total

45

2

1

5

53

Placebo

56

Maximum Corrected QT
 Interval

≤450

29

6

5

3

43

>450 to ≤480

2

0

0

0

2

>480 to ≤500

4

1

0

0

5

>500

5

1

0

0

6

Total

40

8

5

3

56

Note: On-treatment is defined as QTc interval values obtained after the first dose and within [30 days] following treatment discontinuation.

Note: N is the number of subjects with non-missing values for the ECG parameter at baseline and at least 1 postbaseline visit.

Download RTF file

TSFECG03
TSFECG05
Source Code
---
title: TSFECG04
subtitle: Shift From Baseline to Maximum On-treatment Corrected QT Interval
---

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

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

# Prep Environment

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

# Define script level parameters:

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

popfl <- "SAFFL"
trtvar <- "TRT01A"
ctrl_grp <- "Placebo"
demogvars <- c("SEX", "AGEGR1", "RACE", "ETHNIC", "AGE")

ad_domain <- "ADEG"

## selection of QTC parameters
selparamcd <- c("QTCFAG", "QTCBAG", "QTCS", "QTCLAG")

# initial read of data

adeg_complete <- pharmaverseadamjnj::adeg

### available QTC parameters in study
selparamcd <- intersect(selparamcd, unique(adeg_complete$PARAMCD))

catvar <- "AVALCAT1"

# Process Data:

adsl <- pharmaverseadamjnj::adsl %>%
  filter(!!sym(popfl) == "Y") %>%
  select(STUDYID, USUBJID, all_of(c(trtvar, popfl, demogvars)))

adsl <- adsl %>%
  mutate(
    colspan_trt = factor(
      ifelse(!!sym(trtvar) == ctrl_grp, " ", "Active Study Agent"),
      levels = c("Active Study Agent", " ")
    )
  )
## to ensure the same order as on other outputs
trt_order <- as.character((unique(
  adsl %>% select("colspan_trt", all_of(trtvar))
) %>%
  arrange(colspan_trt, !!sym(trtvar)))[[trtvar]])
adsl[[trtvar]] <- factor(as.character(adsl[[trtvar]]), levels = trt_order)

adeg <- adeg_complete %>%
  filter(PARAMCD %in% selparamcd) %>%
  ### Maximum On-treatment
  ### note: by filter ANL03FL, this table is restricted to On-treatment values, per definition of ANL03FL
  ### therefor, no need to add ONTRTFL in filter
  ### if derivation of ANL03FL 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 !!!
  filter(ANL03FL == "Y") %>%
  select(
    USUBJID,
    ONTRTFL,
    TRTEMFL,
    PARAM,
    PARAMCD,
    AVISITN,
    AVISIT,
    AVAL,
    BASE,
    CHG,
    AVALCAT1,
    BASECAT1,
    ONTRTFL,
    TRTEMFL,
    ANL01FL,
    ANL02FL,
    ANL03FL
  ) %>%
  inner_join(., adsl)

adeg$AVISIT <- factor("Maximum Corrected QT Interval")

## if also over time is needed, append these to above dataset
## see ecg05 as example

check1 <- adeg %>%
  group_by(TRT01A, PARAMCD, AVISIT) %>%
  summarize(n = n_distinct(USUBJID))


## add variable for column split header
adeg$BASECAT1_header <- "Baseline Corrected QT Interval"
adeg$BASECAT1_header2 <- " " ## first column N should not appear under Baseline column span

adeg$BASECAT1_header3 <- " " ## extra to allow for additional topleft material

###
AVALCAT1_levels <- levels(adeg$AVALCAT1)


## add extra level N to Basecat1
adeg <- adeg %>%
  mutate(
    BASECAT1 = factor(as.character(BASECAT1), levels = c("N", AVALCAT1_levels))
  )


## trick for alt_counts_df to work with col splitting
# add BASECAT1 to adsl, all assign to extra level N (column will be used for N counts)
adslx <- adsl %>%
  mutate(BASECAT1 = "N") %>%
  mutate(BASECAT1 = factor(BASECAT1, levels = c("N", AVALCAT1_levels)))


adslx$BASECAT1_header <- "Baseline Corrected QT Interval"
adslx$BASECAT1_header2 <- " "
adslx$BASECAT1_header3 <- " " ## extra to allow for additional topleft material

# Define layout and build table:

lyt <- basic_table(show_colcounts = FALSE) %>%
  split_cols_by("BASECAT1_header3") %>%
  ## to ensure N column is not under the Baseline column span header
  split_cols_by("BASECAT1_header2") %>%
  split_cols_by("BASECAT1", split_fun = keep_split_levels("N")) %>%
  ## restart column split (Nested = False)
  ## Combined levels will be made, and the N column should not appear
  split_cols_by("BASECAT1_header", nested = FALSE) %>%
  split_cols_by(
    "BASECAT1",
    split_fun = make_split_fun(
      pre = list(rm_levels(excl = "N")),
      post = list(
        add_overall_facet("TOTAL", "Total")
      )
    )
  ) %>%
  #### replace split_rows and summarize by single analyze call
  ### a_freq_j only works due to
  ### special arguments can do the trick : denomf = adslx & .stats = count_unique
  ### we want counts of treatment group coming from adsl, not from input dataset, therefor, countsource = altdf
  analyze(
    vars = trtvar,
    afun = a_freq_j,
    extra_args = list(
      restr_columns = "N",
      .stats = "count_unique",
      countsource = "altdf",
      extrablankline = TRUE
    ),
    indent_mod = -1L
  ) %>%
  # ## main part of table
  split_rows_by(
    "PARAM",
    nested = FALSE,
    label_pos = "topleft",
    child_labels = "visible",
    split_label = "QTc Interval",
    split_fun = drop_split_levels,
    section_div = " "
  ) %>%
  split_rows_by(
    trtvar,
    label_pos = "topleft",
    indent_mod = -1L,
    child_labels = "hidden",
    split_label = "Treatment Group",
    section_div = " "
  ) %>%
  ### a_freq_j
  ### the special statistic "n_rowdf" option does the trick here of getting the proper value for the N column
  summarize_row_groups(
    trtvar,
    cfun = a_freq_j,
    extra_args = list(
      .stats = "n_rowdf",
      restr_columns = c("N")
    )
  ) %>%
  split_rows_by(
    "AVISIT",
    label_pos = "hidden",
    indent_mod = 1L,
    split_label = " ",
    child_labels = "visible",
    section_div = " "
  ) %>%
  ## add extra level TOTAL using new_levels, rather than earlier technique
  ## advantage for denominator derivation -- n_rowdf can be used, if we'd like to present fraction as well
  ## switch .stats to count_unique_denom_fraction or count_unique_fraction
  analyze(
    "AVALCAT1",
    afun = a_freq_j,
    extra_args = list(
      .stats = "count_unique",
      denom = "n_rowdf",
      new_levels = list(c("Total"), list(AVALCAT1_levels)),
      new_levels_after = TRUE,
      .indent_mods = 1L,
      restr_columns = c(
        toupper(AVALCAT1_levels),
        "TOTAL"
      )
    )
  ) %>%
  append_topleft("    Criteria, n")

result <- build_table(lyt, adeg, alt_counts_df = adslx)

# Add titles and footnotes:

result <- set_titles(result, titles)

# Convert to tbl file and output table

# the default column-widths had issues with 2 columns appear too close
# retrieve the default column widths and update the latter columns
fontspec <- font_spec("Times", 9L, 1.2)
col_gap <- 7L
label_width_ins <- 2

colwidths <- def_colwidths(
  result,
  fontspec,
  col_gap = col_gap,
  label_width_ins = label_width_ins
)

# adjust the column-widths to have the same length for columns 3 - 7 (<= 450, ...., Total)
acolwidths <- colwidths
acolwidths[3:length(acolwidths)] <- 12

tt_to_tlgrtf(string_map = string_map, tt = result, file = fileid, colwidths = acolwidths)
```
```{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