surv_time | R Documentation |
Clinical data often has separate columns for event dates and last follow-up dates. This function calculates the time variable to be used in time-to-event analysis (i.e. time to event or time to censor).
surv_time(
.data,
start_time,
event,
event_date,
fu_date,
surv_time = "surv_time",
surv_end_time = "surv_end_time"
)
.data |
A tbl |
start_time |
A column of dates or datetimes to use as the starting point. This will often be date of diagnosis. |
event |
A column of numeric indicators (0,1) where 1 represents occurrence of the event. |
event_date |
A column of dates or datetimes corresponding to the event. |
fu_date |
A column of dates or datetimes corresponding to the last known follow-up date. |
surv_time |
The name of the output column representing survival time |
surv_end_time |
The name of the output column representing the last date to be used in survival. This will either be event_date or fu_date. |
# Create some test data
set.seed(12215)
surv_data <- tibble::tibble(
diagnosis_dt = sample(seq(as.Date("1985/01/01"), as.Date("1990/01/01"), by = "day"), 10),
death = sample(c(0, 1), 10, replace = TRUE),
fu_dt = as.Date("2009/11/13")
)
surv_data <- surv_data %>%
dplyr::rowwise() %>%
dplyr::mutate(death_dt = dplyr::if_else(death == 1,
sample(seq(as.Date("2010/01/01"), as.Date("2019/01/01"), by = "day"), 1),
as.Date(NA))) %>%
dplyr::ungroup()
surv_data %>%
surv_time(diagnosis_dt, death, death_dt, fu_dt)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.