We will use the cadtte data set from the random.cdisc.data package for the time-to-event summary table. We start by filtering the adtte data set for the overall survival observations, converting time of overall survival to months, creating new variables for event and non-event information and binarizing the ARM variable.
Code library (tern)
library (dplyr)
adtte <- random.cdisc.data:: cadtte %>%
df_explicit_na () %>%
filter (
PARAMCD == "OS"
) %>%
mutate (
AVAL = day2month (AVAL),
AVALU = "Months" ,
is_event = CNSR == 0 ,
is_not_event = CNSR == 1 ,
ARM_BIN = fct_collapse_only (
ARM,
CTRL = c ("B: Placebo" ),
TRT = c ("A: Drug X" , "C: Combination" )
)
)
We can add the summary of an analysis with Cox Proportional Hazards models stratified by SEX to the table above using coxph_pairwise().
Code lyt <- basic_table () %>%
split_cols_by (
var = "ARM_BIN" ,
ref_group = "CTRL"
) %>%
add_colcounts () %>%
analyze_vars (
vars = "is_event" ,
.stats = "count_fraction" ,
.labels = c (count_fraction = "Patients with event (%)" ),
nested = FALSE ,
show_labels = "hidden"
) %>%
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"
)
lyt2 <- lyt %>%
coxph_pairwise (
vars = "AVAL" ,
is_event = "is_event" ,
var_labels = c ("Stratified Analysis" ),
strat = "SEX" ,
control = control_coxph (pval_method = "log-rank" ),
table_names = "coxph_stratified"
)
build_table (lyt2, adtte)
CTRL TRT
(N=134) (N=266)
——————————————————————————————————————————————————————————————
Patients with event (%) 58 (43.3%) 127 (47.7%)
Patients without event (%) 76 (56.7%) 139 (52.3%)
Time to Event (months)
Median NA NA
95% CI (9.4, NA) (9.2, NA)
25% and 75%-ile 5.6, NA 5.4, NA
Range 0.9 to 16.3 {1} 0.5 to 16.4 {1}
Unstratified Analysis
p-value (log-rank) 0.4068
Hazard Ratio 1.14
95% CI (0.84, 1.56)
Stratified Analysis
p-value (log-rank) 0.4243
Hazard Ratio 1.13
95% CI (0.83, 1.55)
——————————————————————————————————————————————————————————————
{1} - Censored observation: range maximum
——————————————————————————————————————————————————————————————
Code
R version 4.5.2 (2025-10-31)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 24.04.4 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so; LAPACK version 3.12.0
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
time zone: Etc/UTC
tzcode source: system (glibc)
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] dplyr_1.2.1 tern_0.9.10 rtables_0.6.15 magrittr_2.0.5
[5] formatters_0.5.12
loaded via a namespace (and not attached):
[1] Matrix_1.7-5 gtable_0.3.6 jsonlite_2.0.0
[4] compiler_4.5.2 tidyselect_1.2.1 stringr_1.6.0
[7] dichromat_2.0-0.1 tidyr_1.3.2 splines_4.5.2
[10] scales_1.4.0 yaml_2.3.12 fastmap_1.2.0
[13] lattice_0.22-9 ggplot2_4.0.2 R6_2.6.1
[16] generics_0.1.4 knitr_1.51 forcats_1.0.1
[19] rbibutils_2.4.1 htmlwidgets_1.6.4 backports_1.5.1
[22] checkmate_2.3.4 tibble_3.3.1 pillar_1.11.1
[25] RColorBrewer_1.1-3 rlang_1.2.0 broom_1.0.12
[28] stringi_1.8.7 xfun_0.57 S7_0.2.1
[31] otel_0.2.0 cli_3.6.5 Rdpack_2.6.6
[34] digest_0.6.39 grid_4.5.2 lifecycle_1.0.5
[37] vctrs_0.7.2 evaluate_1.0.5 glue_1.8.0
[40] nestcolor_0.1.3 farver_2.1.2 codetools_0.2-20
[43] survival_3.8-6 random.cdisc.data_0.3.16 purrr_1.2.1
[46] rmarkdown_2.31 tools_4.5.2 pkgconfig_2.0.3
[49] htmltools_0.5.9