simSurv.Rd
Function simSurv()
and rSurvtime2()
simulate arbitrary (Cox-type) survival times
using the inversion method. Function simSurv()
is a simple wrapper that calls
rSurvtime2()
. The functions are based on the R package CoxFlexBoost implementation
rSurvtime()
and only slightly modify the code.
## Simulate a pre-specified survival times data set.
simSurv(n = 300)
## Simulate arbitrary survival times.
rSurvTime2(lambda, x, cens_fct, upper = 1000, ...,
file = NULL, subdivisions = 1000)
The number of individuals for which survival times should be simulated.
function. Baseline hazard \(\lambda(t, x)\) where time must be first argument.
matrix. (Sampled) values for covariates (without time).
function. Function to compute (random) censoring.
upper boundary of the interval the random survival times fall into.
further arguments to be passed to lambda
or cens_fct
.
character. name of the data file the generated data set should be stored into (e.g., "survtimes.RData") or NULL if the dataset should directly be returned in R.
The maximum number of subintervals for the integration.
This is basically a slight modification according the computation of the integral,
see the manual page of function rSurvtime()
of package CoxFlexBoost
for
details.
A data.frame
consisting of the observed survival time
(time
), the non-censoring indicator (event
) and further
covariates x
is returned. If file
is specified, the
data.frame is additionally stored on the disc.
Benjamin Hofner (2016). CoxFlexBoost: Boosting Flexible Cox Models (with Time-Varying Effects). R package version 0.7-0.
Ralph Bender and Thomas Augustin and Maria Blettner (2005), Generating Survival Times to Simulate Cox Proportional Hazards Models. Statistics in Medicine, 24, 1713-1723.
## The following shows the code of the
## wrapper function simSurv().
set.seed(111)
n <- 100
X <- matrix(NA, nrow = n, ncol = 3)
X[, 1] <- runif(n, -1, 1)
X[, 2] <- runif(n, -3, 3)
X[, 3] <- runif(n, -1, 1)
## Specify censoring function.
cens_fct <- function(time, mean_cens) {
## Censoring times are independent exponentially distributed.
censor_time <- rexp(n = length(time), rate = 1 / mean_cens)
event <- (time <= censor_time)
t_obs <- apply(cbind(time, censor_time), 1, min)
## Return matrix of observed survival times and event indicator.
return(cbind(t_obs, event))
}
## log(time) is the baseline hazard.
lambda <- function(time, x) {
exp(log(time) + 0.7 * x[1] + sin(x[2]) + sin(time * 2) * x[3])
}
## Simulate data with lambda() and cens_fct().
d <- rSurvTime2(lambda, X, cens_fct, mean_cens = 5)