---
title: TTET01
subtitle: Time-To-Event Summary
---
------------------------------------------------------------------------
{{< include ../../test-utils/envir_hook.qmd >}}
::::: panel-tabset
## Data Setup
```{r setup, message = FALSE}
#| code-fold: show
library(tern)
library(scda)
library(dplyr)
adsl <- synthetic_cdisc_dataset("latest", "adsl")
adtte <- synthetic_cdisc_dataset("latest", "adtte")
# Ensure that character variables are converted to factors and empty strings and NAs are explicit missing levels.
adsl <- df_explicit_na(adsl)
adtte <- df_explicit_na(adtte)
adtte_f <- adtte %>%
dplyr::filter(PARAMCD == "OS") %>%
dplyr::mutate(
AVAL = day2month(AVAL),
is_event = CNSR == 0,
is_not_event = CNSR == 1,
EVNT1 = factor(
case_when(
is_event == TRUE ~ "Patients with event (%)",
is_event == FALSE ~ "Patients without event (%)"
),
levels = c("Patients with event (%)", "Patients without event (%)")
),
EVNTDESC = factor(EVNTDESC)
)
```
## Standard Table
```{r variant1, test = list(result_v1 = "result")}
lyt <- basic_table(show_colcounts = TRUE) %>%
split_cols_by(
var = "ARM", ref_group = "A: Drug X"
) %>%
analyze_vars(
vars = "is_event",
.stats = "count_fraction",
.labels = c(count_fraction = "Patients with event (%)")
) %>%
split_rows_by(
"EVNT1",
split_label = "Earliest contributing event",
split_fun = keep_split_levels("Patients with event (%)"),
label_pos = "visible",
child_labels = "hidden",
indent_mod = 1L,
) %>%
analyze("EVNTDESC") %>%
analyze_vars(
vars = "is_not_event",
.stats = "count_fraction",
.labels = c(count_fraction = "Patients without event (%)"),
nested = FALSE,
show_labels = "hidden"
) %>%
surv_time(
vars = "AVAL",
var_labels = "Time to Event (Months)",
is_event = "is_event",
table_names = "time_to_event"
) %>%
coxph_pairwise(
vars = "AVAL",
is_event = "is_event",
var_labels = c("Unstratified Analysis"),
control = control_coxph(pval_method = "log-rank"),
table_names = "coxph_unstratified"
) %>%
surv_timepoint(
vars = "AVAL",
var_labels = "Months",
time_point = c(6, 12),
is_event = "is_event",
method = "both",
control = control_surv_timepoint()
)
result <- build_table(lyt, df = adtte_f, alt_counts_df = adsl) %>%
prune_table()
result
```
## Table Selecting <br/> Sections to Display
```{r variant2, test = list(result_v2 = "result")}
lyt <- basic_table(show_colcounts = TRUE) %>%
split_cols_by("ARM", ref_group = "A: Drug X") %>%
analyze_vars(
vars = "is_event",
.stats = "count_fraction",
.labels = c(count_fraction = "Patients with event (%)")
) %>%
analyze_vars(
"is_not_event",
.stats = "count_fraction",
.labels = c(count_fraction = "Patients without event (%)"),
nested = FALSE,
show_labels = "hidden"
) %>%
surv_time(
vars = "AVAL",
var_labels = "Time to Event (Months)",
is_event = "is_event",
table_names = "time_to_event"
) %>%
coxph_pairwise(
vars = "AVAL",
is_event = "is_event",
var_labels = c("Unstratified Analysis"),
control = control_coxph(pval_method = "log-rank"),
table_names = "coxph_unstratified"
) %>%
surv_timepoint(
vars = "AVAL",
var_labels = "Months",
is_event = "is_event",
method = "surv",
time_point = c(6, 12)
)
result <- build_table(lyt, df = adtte_f, alt_counts_df = adsl)
result
```
## Table Modifying Analysis Details <br/> like Conf. Type, Ties, Alpha Level
```{r variant3, test = list(result_v3 = "result")}
lyt <- basic_table(show_colcounts = TRUE) %>%
split_cols_by("ARM", ref_group = "A: Drug X") %>%
analyze_vars(
vars = "is_event",
.stats = "count_fraction",
.labels = c(count_fraction = "Patients with event (%)")
) %>%
split_rows_by(
"EVNT1",
split_label = "Earliest contributing event",
split_fun = keep_split_levels("Patients with event (%)"),
label_pos = "visible",
child_labels = "hidden",
indent_mod = 1L,
) %>%
analyze("EVNTDESC") %>%
analyze_vars(
vars = "is_not_event",
.stats = "count_fraction",
.labels = c(count_fraction = "Patients without event (%)"),
nested = FALSE,
show_labels = "hidden"
) %>%
surv_time(
vars = "AVAL",
var_labels = "Time to Event (Months)",
is_event = "is_event",
control = control_surv_time(conf_level = 0.9, conf_type = "log-log"),
table_names = "time_to_event"
) %>%
coxph_pairwise(
vars = "AVAL",
is_event = "is_event",
var_labels = c("Unstratified Analysis"),
control = control_coxph(
pval_method = "log-rank",
conf_level = 0.95,
ties = "efron"
),
table_names = "coxph_unstratified"
) %>%
surv_timepoint(
vars = "AVAL",
var_labels = "Months",
is_event = "is_event",
time_point = 12,
control = control_surv_timepoint(conf_level = 0.9, conf_type = "log-log"),
table_names_suffix = "_log_log"
) %>%
surv_timepoint(
vars = "AVAL",
show_labels = "hidden",
is_event = "is_event",
time_point = 12,
method = "surv_diff",
control = control_surv_timepoint(conf_level = 0.975),
table_names_suffix = "_975_pct"
)
result <- build_table(lyt, df = adtte_f, alt_counts_df = adsl) %>%
prune_table()
result
```
## Table with <br/> Stratified Analysis
::: {.content-visible when-profile="stable"}
```{r variant4-stable}
lyt <- basic_table(show_colcounts = TRUE) %>%
split_cols_by("ARM", ref_group = "A: Drug X") %>%
analyze_vars(
vars = "is_event",
.stats = "count_fraction",
.labels = c(count_fraction = "Patients with event (%)")
) %>%
split_rows_by(
"EVNT1",
split_label = "Earliest contributing event",
split_fun = keep_split_levels("Patients with event (%)"),
label_pos = "visible",
child_labels = "hidden",
indent_mod = 1L,
) %>%
analyze("EVNTDESC") %>%
analyze_vars(
vars = "is_not_event",
.stats = "count_fraction",
.labels = c(count_fraction = "Patients without event (%)"),
nested = FALSE,
show_labels = "hidden"
) %>%
surv_time(
vars = "AVAL",
var_labels = "Time to Event (Months)",
is_event = "is_event",
table_names = "time_to_event"
) %>%
coxph_pairwise(
vars = "AVAL",
is_event = "is_event",
var_labels = "Unstratified Analysis",
table_names = "coxph_unstratified"
) %>%
coxph_pairwise(
vars = "AVAL",
is_event = "is_event",
var_labels = "Stratified Analysis",
strata = "SEX",
table_names = "coxph_stratified"
) %>%
surv_timepoint(
vars = "AVAL",
var_labels = "Months",
is_event = "is_event",
method = "both",
time_point = 12
)
result <- build_table(lyt, df = adtte_f, alt_counts_df = adsl) %>%
prune_table()
result
```
:::
::: {.content-visible when-profile="development"}
```{r variant4-devel, test = list(result_v4 = "result")}
lyt <- basic_table(show_colcounts = TRUE) %>%
split_cols_by("ARM", ref_group = "A: Drug X") %>%
analyze_vars(
vars = "is_event",
.stats = "count_fraction",
.labels = c(count_fraction = "Patients with event (%)")
) %>%
split_rows_by(
"EVNT1",
split_label = "Earliest contributing event",
split_fun = keep_split_levels("Patients with event (%)"),
label_pos = "visible",
child_labels = "hidden",
indent_mod = 1L,
) %>%
analyze("EVNTDESC") %>%
analyze_vars(
vars = "is_not_event",
.stats = "count_fraction",
.labels = c(count_fraction = "Patients without event (%)"),
nested = FALSE,
show_labels = "hidden"
) %>%
surv_time(
vars = "AVAL",
var_labels = "Time to Event (Months)",
is_event = "is_event",
table_names = "time_to_event"
) %>%
coxph_pairwise(
vars = "AVAL",
is_event = "is_event",
var_labels = "Unstratified Analysis",
table_names = "coxph_unstratified"
) %>%
coxph_pairwise(
vars = "AVAL",
is_event = "is_event",
var_labels = "Stratified Analysis",
strata = "SEX",
table_names = "coxph_stratified"
) %>%
surv_timepoint(
vars = "AVAL",
var_labels = "Months",
is_event = "is_event",
method = "both",
time_point = 12
)
result <- build_table(lyt, df = adtte_f, alt_counts_df = adsl) %>%
prune_table()
result
```
:::
## Table Modifying Time Point for <br/> the "XX Months" Analysis
```{r variant5, test = list(result_v5 = "result")}
lyt <- basic_table(show_colcounts = TRUE) %>%
split_cols_by("ARM", ref_group = "A: Drug X") %>%
analyze_vars(
vars = "is_event",
.stats = "count_fraction",
.labels = c(count_fraction = "Patients with event (%)")
) %>%
split_rows_by(
"EVNT1",
split_label = "Earliest contributing event",
split_fun = keep_split_levels("Patients with event (%)"),
label_pos = "visible",
child_labels = "hidden",
indent_mod = 1L,
) %>%
analyze("EVNTDESC") %>%
analyze_vars(
vars = "is_not_event",
.stats = "count_fraction",
.labels = c(count_fraction = "Patients without event (%)"),
nested = FALSE,
show_labels = "hidden"
) %>%
surv_time(
vars = "AVAL",
var_labels = "Time to Event (Months)",
is_event = "is_event",
table_names = "time_to_event"
) %>%
coxph_pairwise(
vars = "AVAL",
is_event = "is_event",
var_labels = c("Unstratified Analysis"),
control = control_coxph(pval_method = "log-rank"),
table_names = "coxph_unstratified"
) %>%
surv_timepoint(
vars = "AVAL",
var_labels = "Months",
is_event = "is_event",
time_point = 6,
method = "both"
)
result <- build_table(lyt, df = adtte_f, alt_counts_df = adsl) %>%
prune_table()
result
```
## Table Requesting <br/> \> 1 p-value
```{r variant6, test = list(result_v6 = "result")}
lyt <- basic_table(show_colcounts = TRUE) %>%
split_cols_by("ARM", ref_group = "A: Drug X") %>%
analyze_vars(
vars = "is_event",
.stats = "count_fraction",
.labels = c(count_fraction = "Patients with event (%)")
) %>%
split_rows_by(
"EVNT1",
split_label = "Earliest contributing event",
split_fun = keep_split_levels("Patients with event (%)"),
label_pos = "visible",
child_labels = "hidden",
indent_mod = 1L,
) %>%
analyze("EVNTDESC") %>%
analyze_vars(
vars = "is_not_event",
.stats = "count_fraction",
.labels = c(count_fraction = "Patients without event (%)"),
nested = FALSE,
show_labels = "hidden"
) %>%
surv_time(
vars = "AVAL",
var_labels = "Time to Event (Months)",
is_event = "is_event",
table_names = "time_to_event"
) %>%
coxph_pairwise(
vars = "AVAL",
is_event = "is_event",
var_labels = c("Unstratified Analysis"),
control = control_coxph(pval_method = "log-rank"),
.stats = "pvalue",
table_names = "coxph_unstratified"
) %>%
coxph_pairwise(
vars = "AVAL",
is_event = "is_event",
show_labels = "hidden",
control = control_coxph(pval_method = "wald"),
.stats = "pvalue",
.indent_mods = c(pvalue = 1L),
table_names = "coxph_wald_pvalue"
) %>%
coxph_pairwise(
vars = "AVAL",
is_event = "is_event",
show_labels = "hidden",
control = control_coxph(pval_method = "likelihood"),
.indent_mods = c(pvalue = 1L, hr = 2L, hr_ci = 3L),
table_names = "coxph_likelihood_pvalue"
) %>%
surv_timepoint(
vars = "AVAL",
var_labels = "Months",
is_event = "is_event",
time_point = 12,
method = "both"
)
result <- build_table(lyt, df = adtte_f, alt_counts_df = adsl) %>%
prune_table()
result
```
{{< include ../../test-utils/save_results.qmd >}}
## `teal` App
```{r teal, opts.label = c("skip_if_testing", "app")}
library(teal.modules.clinical)
## Data reproducible code
data <- teal_data()
data <- within(data, {
library(scda)
ADSL <- synthetic_cdisc_dataset("latest", "adsl")
ADTTE <- synthetic_cdisc_dataset("latest", "adtte")
# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels.
ADSL <- df_explicit_na(ADSL)
ADTTE <- df_explicit_na(ADTTE)
})
datanames <- c("ADSL", "ADTTE")
datanames(data) <- datanames
join_keys(data) <- default_cdisc_join_keys[datanames]
## Reusable Configuration For Modules
ADSL <- data[["ADSL"]]
ADTTE <- data[["ADTTE"]]
arm_ref_comp <- list(
ACTARMCD = list(
ref = "ARM B",
comp = c("ARM A", "ARM C")
),
ARM = list(
ref = "B: Placebo",
comp = c("A: Drug X", "C: Combination")
)
)
## Setup App
app <- init(
data = data,
modules = modules(
tm_t_tte(
label = "Time To Event Table",
dataname = "ADTTE",
arm_var = choices_selected(
variable_choices(ADSL, c("ARM", "ARMCD", "ACTARMCD")),
"ARM"
),
arm_ref_comp = arm_ref_comp,
paramcd = choices_selected(
value_choices(ADTTE, "PARAMCD", "PARAM"),
"OS"
),
strata_var = choices_selected(
variable_choices(ADSL, c("SEX", "BMRKR2")),
"SEX"
),
time_points = choices_selected(c(6, 8), 6),
event_desc_var = choices_selected(
variable_choices(ADTTE, "EVNTDESC"),
"EVNTDESC",
fixed = TRUE
)
)
)
)
shinyApp(app$ui, app$server)
```
{{< include ../../repro.qmd >}}
:::::