Survival data is added to an existing data set.
genSurv(
dtName,
survDefs,
digits = 3,
timeName = NULL,
censorName = NULL,
eventName = "event",
typeName = "type",
keepEvents = FALSE,
idName = "id",
envir = parent.frame()
)
Name of data set
Definitions of survival
Number of digits for rounding
A string to indicate the name of a combined competing risk time-to-event outcome that reflects the minimum observed value of all time-to-event outcomes. Defaults to NULL, indicating that each time-to-event outcome will be included in dataset.
The name of a time to event variable that is the censoring variable. Will be ignored if timeName is NULL.
The name of the new numeric/integer column representing the competing event outcomes. If censorName is specified, the integer value for that event will be 0. Defaults to "event", but will be ignored if timeName is NULL.
The name of the new character column that will indicate the event type. The type will be the unique variable names in survDefs. Defaults to "type", but will be ignored if timeName is NULL.
Indicator to retain original "events" columns. Defaults to FALSE.
Name of id field in existing data set.
Optional environment, defaults to current calling environment.
Original data table with survival time
# Baseline data definitions
def <- defData(varname = "x1", formula = .5, dist = "binary")
def <- defData(def, varname = "x2", formula = .5, dist = "binary")
def <- defData(def, varname = "grp", formula = .5, dist = "binary")
# Survival data definitions
sdef <- defSurv(
varname = "survTime", formula = "1.5*x1",
scale = "grp*50 + (1-grp)*25", shape = "grp*1 + (1-grp)*1.5"
)
sdef <- defSurv(sdef, varname = "censorTime", scale = 80, shape = 1)
sdef
#> Key: <varname>
#> varname formula scale shape transition
#> <char> <char> <char> <char> <num>
#> 1: censorTime 0 80 1 0
#> 2: survTime 1.5*x1 grp*50 + (1-grp)*25 grp*1 + (1-grp)*1.5 0
# Baseline data definitions
dtSurv <- genData(300, def)
# Add survival times
dtSurv <- genSurv(dtSurv, sdef)
head(dtSurv)
#> Key: <id>
#> id x1 x2 grp censorTime survTime
#> <int> <int> <int> <int> <num> <num>
#> 1: 1 0 1 0 15.698 146.589
#> 2: 2 1 1 1 432.049 6.873
#> 3: 3 1 0 0 41.984 8.365
#> 4: 4 0 0 0 33.613 0.068
#> 5: 5 0 0 1 16.175 63.289
#> 6: 6 1 1 0 336.267 14.453