simdata {rolr} | R Documentation |
Simulating Survival Times as Functions of a Single Covariate
Description
simdata
is used to simulate survival data from an
exponential distribution.
When the hazard function is a step function, we assume 3 underlying groups
obtained by applying two cutpoints x1 and x2 to the covariate so that group
1 is x < x1
, group 2 is x >= x1
and x < x2
, and group 3
is x >= x2
.
The hazard is a function of the covariate x simulated
from a uniform distribution from [0, 2]; it can be either
a linear function, a step function (with three groups), or a constant (in
which case no association exists between the covariate and survival).
Usage
simdata(nn = 300, const = 365, hr = c(1, 2, 3), hr.linear = 3,
props = c(1/3, 1/3, 1/3), hazard.func = "step", censoring.rate = 0,
seed = 1)
Arguments
nn |
Sample size. |
const |
A constant that all of the hazard functions will be divided by. The bigger it is, the longer the survival times will be. Default is 365. |
hr |
A three-element vector representing the hazards for each of the
groups 1 to 3 when the |
hr.linear |
A scalar representing the hazard ratio when the covariate
increases by one unit. This is used with |
props |
A three-element vector representing the proportions of groups
1 to 3 when |
hazard.func |
A character that can take either |
censoring.rate |
The amount of censoring desired. Default = 0. |
seed |
The random seed used to generate the data. Default = 1. |
Value
A data frame with survival times (times), censoring indicator
(status), covariate (x), three groups obtained by cutting the covariate
if hazard.func = "step"
(x3), and censoring rate (censoring.rate).
Examples
library(rolr)
#simulate survival with a step hazard function
d1=simdata(nn = 150, hr = c(1, 2, 3), props = c(1/3, 1/3, 1/3),
hazard.func = "step", censoring.rate = 0)
head(d1)
#simulate survival with a linear hazard function
d2=simdata(nn = 150, hr.linear = 2, hazard.func = "linear", censoring.rate = 0)
head(d2)
#simulate survival with no association with the covariate
d3=simdata(nn = 150, hazard.func = "none", censoring.rate = 0)
head(d3)