construct_surv_var: construct_surv_var

View source: R/fan_util_fun.R

construct_surv_varR Documentation

construct_surv_var

Description

construct_surv_var

Usage

construct_surv_var(
  df,
  patid,
  idx_dt,
  evt_dt,
  end_dt,
  surv_varname = NULL,
  append = FALSE
)

Arguments

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.

Details

The function creates time-to-event variables for a binary (survival) process.

Value

A data frame with patid, evt_time and evt.

Examples

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"))

fanstev1/fanetc documentation built on April 17, 2025, 10:58 a.m.