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

Arguments

dtName

Name of data set

survDefs

Definitions of survival

digits

Number of digits for rounding

timeName

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.

censorName

The name of a time to event variable that is the censoring variable. Will be ignored if timeName is NULL.

eventName

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.

typeName

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.

keepEvents

Indicator to retain original "events" columns. Defaults to FALSE.

idName

Name of id field in existing data set.

Value

Original data table with survival time

Examples

# 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
#>       varname formula               scale               shape transition
#> 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)
#>    id x1 x2 grp censorTime survTime
#> 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