Package {tm.ttni}


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:

See Also

Useful links:


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 prepped is supplied.

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 TRUE for multi-arm designs and FALSE for two-arm designs.

include_followup

Whether to include reverse KM follow-up time.

surv_stats

Time-to-event statistics from ttni_surv_time_choices(). NULL uses default_ttni_surv_stats(). mean_sd is a descriptive Mean (SD) of AVAL; the rest are tern::surv_time() statistics. Legacy median / median_ci requests are folded into one median_ci_3d row. The same selection is used for follow-up time when include_followup is TRUE.

landmark_style

"detailed" includes patients remaining at risk; "rate_only" shows rate (95% CI) only.

conf_type

KM CI type passed to tern::control_surv_time().

conf_level

Confidence level.

compute_hr

NULL to auto-detect (two-arm only), or a flag. A request of TRUE on a multi-arm data set is ignored with a warning.

title

Table title. NULL derives a title from paramcd.

footnotes

Optional method footnotes. NULL (default) omits them so the interactive table stays compact; definitions live in the README. Pass default_ttni_footnotes() when a TFL-style footer is required.

prepped

Optional list from prep_ttni_data(). When supplied, raw adsl / adtte are not re-prepared.

...

Passed to prep_ttni_data() when prepped is NULL.

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

logical(1) Whether inferential statistics are shown.

conf_type

character(1) KM confidence-interval 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 TRTSDT and either DTHDT / DTHFL or LSTALVDT.

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

character(1) Treatment / grouping variable name.

ref_arm

character(1) or NULL Reference arm. Defaults to the first factor level (or first unique value).

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

character(1) Either "two_arm" (randomized comparison) or "multi_arm" (three generic arms; no study-specific dose labels).

n_per_arm

integer(1) Subjects per arm.

seed

integer(1) Random 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. NULL uses default_ttni_surv_stats().

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 NULL, adsl is used as the TTE source.

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 (0 = event).

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 USUBJID.

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 USUBJID and a time-to-event value.

adsl

Optional standardized ADSL used to back-fill TRT01A.

default_avalu

Unit used when AVALU is missing. NULL infers DAYS when the maximum AVAL exceeds 60, otherwise MONTHS.

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

(picks or legacy choices_selected) PARAMCD selector. When NULL, a teal.picks::picks() object is built: datasets is tte_name, variables is fixed to PARAMCD with multiple = FALSE, and values selects paramcd with multiple = FALSE. A teal.transform::choices_selected object is still accepted, with a deprecation warning, and converted to that picks shape.

adsl_name

ADSL dataset name in teal_data.

tte_name

ADTTE dataset name.

paramcd

Default PARAMCD stored in values$selected when cat is NULL.

group_vars

(picks or legacy character) grouping column. When NULL, datasets is adsl_name and variables is TRT01A (multiple = FALSE). A character vector of column names is still accepted, with a deprecation warning. Names on that vector were display labels and are dropped.

population_var

(picks or legacy character) population-flag column. When NULL and population_choices is NULL, datasets is adsl_name and variables offers SAFFL and ITTFL, with SAFFL selected (multiple = FALSE).

population_value

Population flag value to keep.

population_choices

Legacy character vector of flag columns. Ignored when population_var is a picks object. Passing either this or a character population_var signals a deprecation warning.

timepoints

Default landmark months.

landmark_style

"detailed" or "rate_only".

surv_stats

Initial time-to-event statistics from ttni_surv_time_choices().

include_followup

Whether reverse KM follow-up is shown.

show_total

Initial Total-column setting. NULL follows design.

compute_hr

Leave NULL to auto-detect two-arm only.

conf_type

KM CI type.

title

Table title. NULL derives a title from the selected PARAMCD.

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).

mirror server hosted at Truenetwork, Russian Federation.