| Title: | 'teal' Module for Time-to-Next-Intervention and Time-to-Event Tables |
|---|---|
| Description: | Provides an open-source 'teal' module and a reusable table builder for time to next intervention and related time-to-event endpoints. Kaplan-Meier summaries are produced with 'tern' and 'rtables' for both multi-arm (dose-level) and two-arm designs. Hazard ratio, Wald confidence interval, and log-rank p-value are calculated only when exactly two treatment arms are present. The builder can be called without launching 'shiny'. |
| Authors: | Yaoguang Ma [aut, cre] |
| Maintainer: | Yaoguang Ma <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-11-24 02:55:13 UTC |
| Source: | https://github.com/cran/tm.ttni |
Uses tern Kaplan-Meier layout functions for both multi-arm (dose-level)
and two-arm designs. Hazard ratio, 95% CI, and log-rank p-value are added
only when exactly two arms are present.
build_ttni_table( adsl = NULL, adtte = NULL, arm_var = "TRT01A", ref_arm = NULL, paramcd = "TTNI", timepoints = c(3, 6, 12, 18, 24), show_total = NULL, include_followup = TRUE, surv_stats = NULL, landmark_style = c("detailed", "rate_only"), conf_type = c("log-log", "log", "plain"), conf_level = 0.95, compute_hr = NULL, title = NULL, footnotes = NULL, prepped = NULL, ... )build_ttni_table( adsl = NULL, adtte = NULL, arm_var = "TRT01A", ref_arm = NULL, paramcd = "TTNI", timepoints = c(3, 6, 12, 18, 24), show_total = NULL, include_followup = TRUE, surv_stats = NULL, landmark_style = c("detailed", "rate_only"), conf_type = c("log-log", "log", "plain"), conf_level = 0.95, compute_hr = NULL, title = NULL, footnotes = NULL, prepped = NULL, ... )
adsl |
ADSL or combined TTE data. Ignored when |
adtte |
Optional ADTTE data frame. |
arm_var |
Treatment / grouping variable. |
ref_arm |
Reference arm used for two-arm HR calculations. |
paramcd |
Analysis parameter code. |
timepoints |
Landmark months. |
show_total |
Whether to add a Total column. Defaults to |
include_followup |
Whether to include reverse KM follow-up time. |
surv_stats |
Time-to-event statistics from |
landmark_style |
|
conf_type |
KM CI type passed to |
conf_level |
Confidence level. |
compute_hr |
|
title |
Table title. |
footnotes |
Optional method footnotes. |
prepped |
Optional list from |
... |
Passed to |
Pass either raw adsl / adtte or a list returned by prep_ttni_data()
via prepped so the teal server can prepare data once.
An rtables VTableTree.
two_arm <- make_synthetic_ttni_data("two_arm", seed = 1L) build_ttni_table(two_arm$ADSL, two_arm$ADTTE, ref_arm = "Placebo") multi <- make_synthetic_ttni_data("multi_arm", seed = 1L) build_ttni_table(multi$ADSL, multi$ADTTE, show_total = TRUE)two_arm <- make_synthetic_ttni_data("two_arm", seed = 1L) build_ttni_table(two_arm$ADSL, two_arm$ADTTE, ref_arm = "Placebo") multi <- make_synthetic_ttni_data("multi_arm", seed = 1L) build_ttni_table(multi$ADSL, multi$ADTTE, show_total = TRUE)
Default TTE censor-reason labels
default_ttni_censor_levels()default_ttni_censor_levels()
Character vector of preferred censoring descriptions.
Generic labels used when EVNTDESC is missing or to order known reasons.
Study-specific wording (for example a named investigational product) should
be supplied by the caller, not baked into the package defaults.
default_ttni_event_levels()default_ttni_event_levels()
Character vector of preferred event descriptions.
Default TTE footnotes
default_ttni_footnotes(compute_hr = FALSE, conf_type = "log-log")default_ttni_footnotes(compute_hr = FALSE, conf_type = "log-log")
compute_hr |
|
conf_type |
|
Character vector of footer notes.
Includes descriptive Mean (SD) of AVAL plus Kaplan-Meier median (95% CI),
quartiles, and range.
default_ttni_surv_stats()default_ttni_surv_stats()
Character vector of statistic names from ttni_surv_time_choices().
Used when a local CDISC Pilot checkout has ADSL but no ADTTE, or when a demo needs a second PARAMCD alongside a native TTE dataset.
derive_mock_adtte(adsl, paramcd = "OS", param = "Overall Survival")derive_mock_adtte(adsl, paramcd = "OS", param = "Overall Survival")
adsl |
Standardized ADSL with |
paramcd |
Parameter code to assign. |
param |
Parameter label. |
An ADTTE-like data frame.
TTNI can appear in a multi-dose Phase 1/2 study or a two-arm randomized trial. Hazard ratio, Wald CI, and log-rank p-value are only appropriate when exactly two treatment arms are present.
detect_arm_design(data, arm_var, ref_arm = NULL)detect_arm_design(data, arm_var, ref_arm = NULL)
data |
A data frame containing the treatment variable. |
arm_var |
|
ref_arm |
|
A list with n_arms, arms, ref_arm, comp_arms, design
(single_arm, two_arm, or multi_arm), and compute_hr.
detect_arm_design( data.frame(TRT01A = c("Placebo", "Drug")), arm_var = "TRT01A", ref_arm = "Placebo" )detect_arm_design( data.frame(TRT01A = c("Placebo", "Drug")), arm_var = "TRT01A", ref_arm = "Placebo" )
Returns a subject-level ADSL and a BDS-style ADTTE with two parameters:
TTNI (time to next intervention) and OS (overall survival). The two
data frames are distinct objects.
make_synthetic_ttni_data( design = c("two_arm", "multi_arm"), n_per_arm = 40L, seed = 20260823L )make_synthetic_ttni_data( design = c("two_arm", "multi_arm"), n_per_arm = 40L, seed = 20260823L )
design |
|
n_per_arm |
|
seed |
|
A list with ADSL and ADTTE.
data <- make_synthetic_ttni_data(design = "two_arm", seed = 1L) names(data) unique(data$ADTTE$PARAMCD)data <- make_synthetic_ttni_data(design = "two_arm", seed = 1L) names(data) unique(data$ADTTE$PARAMCD)
Accepts either a single ADSL-like data frame that already contains TTE
variables (PARAMCD, AVAL, CNSR, EVNTDESC) or a separate ADTTE
data frame joined to ADSL by subject. An empty result after filtering is
returned as a structured list (empty = TRUE) rather than an error so the
teal module can show a no-data message.
prep_ttni_data( adsl, adtte = NULL, arm_var = "TRT01A", ref_arm = NULL, paramcd = "TTNI", subject_var = "USUBJID", paramcd_var = "PARAMCD", aval_var = "AVAL", cnsr_var = "CNSR", evntdesc_var = "EVNTDESC", population_var = "SAFFL", population_value = "Y" )prep_ttni_data( adsl, adtte = NULL, arm_var = "TRT01A", ref_arm = NULL, paramcd = "TTNI", subject_var = "USUBJID", paramcd_var = "PARAMCD", aval_var = "AVAL", cnsr_var = "CNSR", evntdesc_var = "EVNTDESC", population_var = "SAFFL", population_value = "Y" )
adsl |
ADSL or combined subject-level TTE data. |
adtte |
Optional ADTTE data frame. If |
arm_var |
Treatment / grouping variable. |
ref_arm |
Optional reference arm for two-arm comparisons. |
paramcd |
Analysis parameter code. |
subject_var |
Subject identifier. |
paramcd_var |
PARAMCD variable name. |
aval_var |
Analysis value variable. |
cnsr_var |
Censor variable ( |
evntdesc_var |
Event / censor description variable. |
population_var |
Optional population flag variable. |
population_value |
Population flag value to keep. |
A list with analysis data, design metadata, description levels, and
empty (TRUE when no records remain).
Harmonizes common CDISC Pilot / random.cdisc.data column variants so
prep_ttni_data() can join treatment and population flags.
standardize_adsl(adsl)standardize_adsl(adsl)
adsl |
A data frame with at least |
A standardized ADSL data frame.
Ensures PARAMCD / PARAM / AVAL / CNSR exist and converts day-valued
AVAL to months when AVALU is DAYS.
standardize_adtte(adtte, adsl = NULL, default_avalu = NULL)standardize_adtte(adtte, adsl = NULL, default_avalu = NULL)
adtte |
A data frame with at least |
adsl |
Optional standardized ADSL used to back-fill |
default_avalu |
Unit used when |
A standardized ADTTE data frame.
Interactive TTE table. Kaplan-Meier summaries are always shown. Hazard
ratio, 95% CI, and log-rank p-value appear only when the selected grouping
variable has exactly two arms. PARAMCD, the grouping variable, and the
population flag are selected with teal.picks.
tm_t_ttni( label = "Time to Next Intervention (TTNI)", cat = NULL, adsl_name = "ADSL", tte_name = "ADTTE", paramcd = "TTNI", group_vars = NULL, population_var = NULL, population_value = "Y", population_choices = NULL, timepoints = c(3, 6, 12, 18, 24), landmark_style = c("detailed", "rate_only"), surv_stats = default_ttni_surv_stats(), include_followup = TRUE, show_total = NULL, compute_hr = NULL, conf_type = c("log-log", "log", "plain"), title = NULL )tm_t_ttni( label = "Time to Next Intervention (TTNI)", cat = NULL, adsl_name = "ADSL", tte_name = "ADTTE", paramcd = "TTNI", group_vars = NULL, population_var = NULL, population_value = "Y", population_choices = NULL, timepoints = c(3, 6, 12, 18, 24), landmark_style = c("detailed", "rate_only"), surv_stats = default_ttni_surv_stats(), include_followup = TRUE, show_total = NULL, compute_hr = NULL, conf_type = c("log-log", "log", "plain"), title = NULL )
label |
Module label. |
cat |
( |
adsl_name |
ADSL dataset name in |
tte_name |
ADTTE dataset name. |
paramcd |
Default PARAMCD stored in |
group_vars |
( |
population_var |
( |
population_value |
Population flag value to keep. |
population_choices |
Legacy character vector of flag columns. Ignored
when |
timepoints |
Default landmark months. |
landmark_style |
|
surv_stats |
Initial time-to-event statistics from
|
include_followup |
Whether reverse KM follow-up is shown. |
show_total |
Initial Total-column setting. |
compute_hr |
Leave |
conf_type |
KM CI type. |
title |
Table title. |
A teal module object.
if (interactive()) { data <- make_synthetic_ttni_data("two_arm") app_data <- teal.data::teal_data(ADSL = data$ADSL, ADTTE = data$ADTTE) paramcd_choices <- unique(as.character(data$ADTTE$PARAMCD)) app <- teal::init( data = app_data, modules = teal::modules( tm_t_ttni( label = "TTNI", cat = teal.picks::picks( teal.picks::datasets(choices = "ADTTE", selected = "ADTTE"), teal.picks::variables( choices = "PARAMCD", selected = "PARAMCD", multiple = FALSE, fixed = TRUE ), teal.picks::values( choices = paramcd_choices, selected = "TTNI", multiple = FALSE ) ), group_vars = teal.picks::picks( teal.picks::datasets(choices = "ADSL", selected = "ADSL"), teal.picks::variables( choices = c("TRT01A", "SEX"), selected = "TRT01A", multiple = FALSE ) ), population_var = teal.picks::picks( teal.picks::datasets(choices = "ADSL", selected = "ADSL"), teal.picks::variables( choices = c("SAFFL", "ITTFL"), selected = "SAFFL", multiple = FALSE ) ) ) ) ) shiny::shinyApp(app$ui, app$server) }if (interactive()) { data <- make_synthetic_ttni_data("two_arm") app_data <- teal.data::teal_data(ADSL = data$ADSL, ADTTE = data$ADTTE) paramcd_choices <- unique(as.character(data$ADTTE$PARAMCD)) app <- teal::init( data = app_data, modules = teal::modules( tm_t_ttni( label = "TTNI", cat = teal.picks::picks( teal.picks::datasets(choices = "ADTTE", selected = "ADTTE"), teal.picks::variables( choices = "PARAMCD", selected = "PARAMCD", multiple = FALSE, fixed = TRUE ), teal.picks::values( choices = paramcd_choices, selected = "TTNI", multiple = FALSE ) ), group_vars = teal.picks::picks( teal.picks::datasets(choices = "ADSL", selected = "ADSL"), teal.picks::variables( choices = c("TRT01A", "SEX"), selected = "TRT01A", multiple = FALSE ) ), population_var = teal.picks::picks( teal.picks::datasets(choices = "ADSL", selected = "ADSL"), teal.picks::variables( choices = c("SAFFL", "ITTFL"), selected = "SAFFL", multiple = FALSE ) ) ) ) ) shiny::shinyApp(app$ui, app$server) }
mean_sd is a descriptive summary of AVAL (one row). The remaining
names are tern::surv_time() statistics, shown in tern's native order.
quantiles and range are labeled Q1, Q3 and Min, Max. Separate
median / median_ci rows are not offered; use median_ci_3d so
median and 95% CI stay on one line.
ttni_surv_time_choices()ttni_surv_time_choices()
A named character vector (label = stat).