| Title: | 'teal' Module for Time-to-Next-Intervention and Time-to-Event Tables |
| Version: | 0.1.0 |
| 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'. |
| License: | MIT + file LICENSE |
| URL: | https://github.com/ygma-bitc/tm.ttni, https://ygma-bitc.github.io/tm.ttni/ |
| BugReports: | https://github.com/ygma-bitc/tm.ttni/issues |
| Depends: | R (≥ 4.1) |
| Imports: | checkmate (≥ 2.1.0), lifecycle (≥ 0.2.0), rlang (≥ 1.0.0), rtables (≥ 0.6.0), shiny (≥ 1.7.0), shinyjs (≥ 2.0.0), shinyvalidate (≥ 0.1.0), stats, teal (≥ 1.2.0), teal.picks (≥ 0.1.0), teal.widgets (≥ 0.4.0), tern (≥ 0.9.0) |
| Suggests: | haven, knitr, pkgdown, pkgload, random.cdisc.data, rmarkdown, teal.data (≥ 0.8.0), teal.transform (≥ 0.5.0), testthat (≥ 3.2.0), withr |
| Config/testthat/edition: | 3 |
| Encoding: | UTF-8 |
| Language: | en-US |
| Config/roxygen2/version: | 8.1.1 |
| NeedsCompilation: | no |
| Packaged: | 2026-11-03 14:23:43 UTC; ubuntu |
| Author: | Yaoguang Ma [aut, cre] |
| Maintainer: | Yaoguang Ma <ygma0929@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-11-23 15:10:02 UTC |
tm.ttni: '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'.
Author(s)
Maintainer: Yaoguang Ma ygma0929@gmail.com
Authors:
Yaoguang Ma ygma0929@gmail.com
See Also
Useful links:
Report bugs at https://github.com/ygma-bitc/tm.ttni/issues
Build a TTE / TTNI summary table
Description
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.
Usage
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,
...
)
Arguments
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 |
Details
Pass either raw adsl / adtte or a list returned by prep_ttni_data()
via prepped so the teal server can prepare data once.
Value
An rtables VTableTree.
Examples
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
Description
Default TTE censor-reason labels
Usage
default_ttni_censor_levels()
Value
Character vector of preferred censoring descriptions.
Default TTE event-reason labels
Description
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.
Usage
default_ttni_event_levels()
Value
Character vector of preferred event descriptions.
Default TTE footnotes
Description
Default TTE footnotes
Usage
default_ttni_footnotes(compute_hr = FALSE, conf_type = "log-log")
Arguments
compute_hr |
|
conf_type |
|
Value
Character vector of footer notes.
Default time-to-event statistics shown in the module
Description
Includes descriptive Mean (SD) of AVAL plus Kaplan-Meier median (95% CI),
quartiles, and range.
Usage
default_ttni_surv_stats()
Value
Character vector of statistic names from ttni_surv_time_choices().
Derive a simple OS-style ADTTE from ADSL death / last-alive dates
Description
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.
Usage
derive_mock_adtte(adsl, paramcd = "OS", param = "Overall Survival")
Arguments
adsl |
Standardized ADSL with |
paramcd |
Parameter code to assign. |
param |
Parameter label. |
Value
An ADTTE-like data frame.
Detect whether a TTE table should use two-arm inferential statistics
Description
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.
Usage
detect_arm_design(data, arm_var, ref_arm = NULL)
Arguments
data |
A data frame containing the treatment variable. |
arm_var |
|
ref_arm |
|
Value
A list with n_arms, arms, ref_arm, comp_arms, design
(single_arm, two_arm, or multi_arm), and compute_hr.
Examples
detect_arm_design(
data.frame(TRT01A = c("Placebo", "Drug")),
arm_var = "TRT01A",
ref_arm = "Placebo"
)
Build synthetic ADSL / ADTTE fixtures for TTE demos and tests
Description
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.
Usage
make_synthetic_ttni_data(
design = c("two_arm", "multi_arm"),
n_per_arm = 40L,
seed = 20260823L
)
Arguments
design |
|
n_per_arm |
|
seed |
|
Value
A list with ADSL and ADTTE.
Examples
data <- make_synthetic_ttni_data(design = "two_arm", seed = 1L)
names(data)
unique(data$ADTTE$PARAMCD)
Keep requested statistics in catalog order
Description
Legacy median / median_ci requests are folded into median_ci_3d.
Usage
normalize_surv_time_stats(stats = NULL)
Arguments
stats |
Character vector of statistic names. |
Value
Character vector subset of ttni_surv_time_choices().
Prepare ADSL / ADTTE records for a TTE table
Description
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.
Usage
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"
)
Arguments
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. |
Value
A list with analysis data, design metadata, description levels, and
empty (TRUE when no records remain).
Standardize an ADSL-like data frame for TTE tables
Description
Harmonizes common CDISC Pilot / random.cdisc.data column variants so
prep_ttni_data() can join treatment and population flags.
Usage
standardize_adsl(adsl)
Arguments
adsl |
A data frame with at least |
Value
A standardized ADSL data frame.
Standardize an ADTTE-like data frame
Description
Ensures PARAMCD / PARAM / AVAL / CNSR exist and converts day-valued
AVAL to months when AVALU is DAYS.
Usage
standardize_adtte(adtte, adsl = NULL, default_avalu = NULL)
Arguments
adtte |
A data frame with at least |
adsl |
Optional standardized ADSL used to back-fill |
default_avalu |
Unit used when |
Value
A standardized ADTTE data frame.
teal Module: Time to Next Intervention and related TTE tables
Description
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.
Usage
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
)
Arguments
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. |
Value
A teal module object.
Examples
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)
}
Time-to-event statistics offered in the module
Description
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.
Usage
ttni_surv_time_choices()
Value
A named character vector (label = stat).