| estimate_rmtl | R Documentation |
The method of Connor and Trinquart (Stat Med 2021) estimates the RMTL in the presence of competing risks. This function is a modification of their R code. Estimation functions are identical; input handling and output have been adapted.
estimate_rmtl(
data,
exposure = NULL,
time,
time2 = NULL,
event,
event_of_interest = 1,
weight = NULL,
tau = NULL,
reach_tau = c("warn", "stop", "ignore"),
conf.level = 0.95
)
data |
Data frame (tibble). |
exposure |
Optional. Name of exposure variable within the |
time |
Name of time variable within the |
time2 |
Optional. Name of the variable within the |
event |
Name of event variable within the |
event_of_interest |
Optional. Indicator for which of the non-censoring
events is of main interest. Others are treated as competing. Defaults to
|
weight |
Optional. Weights, such as inverse-probability weights or
survey weights. The default ( |
tau |
Optional. Time horizon to restrict event times. By default, the latest time in the group with the shortest follow-up. Prefer a user-defined, interpretable time horizon. |
reach_tau |
Optional. How to handle provided
If |
conf.level |
Optional. Confidence level. Defaults to |
Differences to the original function rmtl::rmtl():
Convert print for errors to stop or
warning.
Pass data as a data frame/tibble and select variables from it.
Allow for different variable types in the event variable.
Use Surv conventions for entry/exit times
(time, time2).
Allow for exposure groups where tau is not reached.
Return contrasts in restricted mean time lost as comparisons to the reference level instead of all pairwise comparisons.
Add origin (time 0, cumulative incidence 0) to the returned cumulative incidence function for proper plotting.
Return results as a list of tibbles. Do not print or plot.
List:
tau Time horizon.
rmtl Tibble with absolute estimates of RMTL, per exposure group if
given.
rmtdiff Tibble with contrasts of RMTL between exposure groups,
compared to a common reference (the first level). Empty tibble if no
exposure variable given.
cif Tibble with cumulative incidence function for the event of
interest:
exposure Exposure group.
time Event time.
estimate Aalen-Johansen estimate of cumulative incidence function
with se, conf.low, and conf.high.
Conner SC, Trinquart L. Estimation and modeling of the restricted mean time lost in the presence of competing risks. Stat Med 2021;40:2177–96. https://doi.org/10.1002/sim.8896.
data(cancer, package = "survival")
cancer <- cancer %>% dplyr::mutate(
status = status - 1, # make 0/1
sex = factor(sex, levels = 1:2, labels = c("Men", "Women")))
result <- estimate_rmtl(
data = cancer,
exposure = sex,
time = time,
event = status,
tau = 365.25) # time horizon: one year
result
# Make simple plot
library(ggplot2)
library(dplyr)
library(tidyr)
result$cif %>%
ggplot(mapping = aes(x = time, y = estimate, color = exposure)) +
geom_step() +
scale_x_continuous(breaks = seq(from = 0, to = 365, by = 60)) +
labs(x = "Time since start of follow-up in days",
y = "Cumulative incidence")
# Make fancier plot with a shaded area for the RMTL difference
df_ribbon <- result$cif %>%
select(exposure, time, estimate) %>%
pivot_wider(names_from = exposure,
values_from = estimate,
names_repair = ~c("time", "surv", "surv2")) %>%
filter(time < 365.25) %>% # tau for RMST
arrange(time) %>% # carry forward survival values per stratum
fill(surv) %>%
fill(surv2)
result$cif %>%
ggplot() +
geom_step(mapping = aes(x = time, y = estimate, color = exposure)) +
scale_x_continuous(breaks = seq(from = 0, to = 365, by = 60)) +
scale_y_continuous(expand = expansion()) +
labs(x = "Time since start of follow-up in days",
y = "Cumulative incidence") +
cowplot::theme_minimal_hgrid() +
geom_stepribbon(data = df_ribbon,
mapping = aes(x = time, ymin = surv, ymax = surv2),
fill = "gray80", alpha = 0.5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.