construct_surv_var | R Documentation |
construct_surv_var
construct_surv_var(
df,
patid,
idx_dt,
evt_dt,
end_dt,
surv_varname = NULL,
append = FALSE
)
df |
input data |
patid |
the variable indicating subject/patient id |
idx_dt |
the index date |
evt_dt |
the date of the event occurrence. Its value should be NA for non-event subjects. |
end_dt |
the date of the last follow-up |
surv_varname |
an option of character vector of length 2, the 1st of which is the name of the time variable; the other is the name of the event indicator. |
The function creates time-to-event variables for a binary (survival) process.
A data frame with patid, evt_time and evt.
set.seed(0)
nn<- 100
test<- data.frame(idx_dt= as.Date("1970-01-01"),
evt_dt= c(sample((-30:70), nn-1, replace= TRUE), 0) + as.Date("1970-01-01"),
end_dt= sample((0:99), nn, replace= TRUE) + as.Date("1970-01-01")) %>%
mutate(flag= evt_dt > end_dt,
evt_dt= replace(evt_dt, flag, NA),
end_dt= replace(end_dt, !flag, NA),
patid= 1:n())
test %>% construct_surv_var(idx_dt, evt_dt, end_dt, patid)
test %>% construct_surv_var(idx_dt, evt_dt, end_dt, patid, surv_varname= c("day_dth", "dth"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.