Learn R Programming

survMisc (version 0.4.6)

genSurv: Generate survival data

Description

Generate survival data

Usage

genSurvDf(b = 2L, f = 2L, c = 1L, n = 100L, pb = 0.5, nlf = 3L,
  rc = 0.8, pe = 0.5, t0 = 1L, tMax = 100L, asFactor = TRUE,
  model = FALSE, timelim = 5)

genSurvDt(b = 2L, f = 2L, c = 1L, n = 100L, pb = 0.5, nlf = 3L, rc = 0.8, pe = 0.5, t0 = 1L, tMax = 100L, asFactor = TRUE, model = TRUE, timelim = 5)

Arguments

b
binomial predictors, the number of predictors which are binary, i.e. limited to $0$ or $1$
f
factors, the number of predictors which are factors
c
continuous predictors, the number of predictors which are continuous
n
number of observations (rows) in the data
nlf
the number of levels in a factor
pb
probability for binomnial predictors: the probability of binomial predictors being $=1$ e.g. if pb=0.3, $30%$ will be $1$s, $70%$ will be $0$s
rc
ratio for continuous variables: the ratio of levels of continuous variables to the total number of observations n e.g. if rc=0.8 and n=100, it will be in the range $1-80$
pe
probability of event the probability of events (typically death/failure) occurring, i.e. $P(e=1)$. e.g. if pe=0.6, $60%$ will be $1$s, $40%$ will be $0$s
t0
Lowest (starting) time
tMax
Highest (final) time
asFactor
if asFactor=TRUE (the default), predictors given as factors will be converted to factors in the data frame before the model is fit
timelim
function will timeout after timelim secs. This is present to prevent duplication of rows.
model
If model=TRUE will also return a model fitted with survival::coxph.

Value

  • If model=FALSE (the default) a data.frame or data.table as above. If model=TRUE: a list with the following values:
  • df or dtA data.frame (for genSurvDf) or data.table (for genSurvDt). Predictors are labelled $x1, x2, ..., xn$. Outcome is $t1$ (time) and $e$ event (e.g. death). Rows represent to $n$ observations
  • modelA model fit with survival::coxph

Examples

Run this code
set.seed(1)
genSurvDf(model=TRUE)
genSurvDf(b=0, c=2, n=100, pe=0.7)
genSurvDf(b=1, c=0, n=1000)
genSurvDf(f=1, nlf=4, b=1, c=0, asFactor=FALSE)
set.seed(1)
genSurvDt()
genSurvDt(b=0, f=0, c=1, n=20L, pe=0.7)

Run the code above in your browser using DataLab