I want to generate a summary table of cumulative incidence estimates for several variables at once in a competing risks scenario using the tidycmprk
package. It is possible to produce such a table for one single variable using tbl_cuminc
from the tidycmprk
package. But how is it possible to get a similar table with tidycmprk
without stacking multiple tables?
Here is an example code for the table I am looking for one variable:
tbl_cr<-
cuminc(Surv(ttdeath, death_cr) ~ trt, trial) %>%
tbl_cuminc(times = c(24), outcomes = c("death from cancer"),
label_header = "**Month {time}**")
For comparison, in the gtsummary
package, which is developed by the same author, I usually run the following code to get Kaplan Meier survival estimates for multiple variables at once.
tbl_KM <- select(trial, ttdeath, death, trt, grade) %>%
tbl_survfit(y = "Surv(ttdeath, death)", times = c(24))
And here is how my table look like. I would like to have similar result from the cumulative incidence estimates.
Here's how you can stack the tables.
The competing risks variant of the tbl_survfit()
function doesn't have the data.frame
method that is often used in the Kaplan-Meier method. The CR model is more complex and requires more inputs for the outcome select than KM methods do, and the structure of what is returned can become complex when showing results for multiple outcomes. Therefore, I have chosen not to create it.
library(gtsummary)
library(tidycmprsk)
#>
#> Attaching package: 'tidycmprsk'
#> The following object is masked from 'package:gtsummary':
#>
#> trial
c("trt", "grade") |>
purrr::map(
~ # buld formula
glue::glue("Surv(ttdeath, death_cr) ~ {.x}") |>
as.formula() |>
# build cuminc model
cuminc(data = trial) |>
# model in table
tbl_cuminc(
times = c(24),
outcomes = c("death from cancer"),
label_header = "**Month {time}**"
) |>
bold_labels()
) |>
# stack results
tbl_stack() |>
# convert to markdown to display on SO
as_kable()
Characteristic | Month 24 |
---|---|
Chemotherapy Treatment | |
Drug A | 24% (16%, 33%) |
Drug B | 32% (23%, 42%) |
Grade | |
I | 26% (17%, 37%) |
II | 25% (15%, 36%) |
III | 34% (23%, 46%) |
Created on 2025-06-02 with reprex v2.1.1