Function to generate a random sample of survival data from extended hazard models.
Arguments
- u
a numeric vector of quantiles.
- formula
formula specifying the linear predictors.
- baseline
the name of the baseline survival distribution.
- beta
vector of regression coefficients.
- phi
vector of regression coefficients.
- dist
an alternative way to specify the baseline survival distribution.
- package
the name of the package where the assumed quantile function is implemented.
- data
data frame containing the covariates used to generate the survival times.
- ...
further arguments passed to other methods.
Examples
library(rsurv)
library(dplyr)
n <- 1000
simdata <- data.frame(
age = rnorm(n),
sex = sample(c("f", "m"), size = n, replace = TRUE)
) %>%
mutate(
t = rehreg(runif(n), ~ age+sex, beta = c(1, 2), phi = c(-1, 2),
dist = "weibull", shape = 1.5, scale = 1),
c = runif(n, 0, 10)
) %>%
rowwise() %>%
mutate(
time = min(t, c),
status = as.numeric(time == t)
)
glimpse(simdata)
#> Rows: 1,000
#> Columns: 6
#> Rowwise:
#> $ age <dbl> -0.42360443, -0.58067213, -0.23117077, 0.03041929, 1.56862023, …
#> $ sex <chr> "f", "m", "m", "m", "f", "m", "f", "m", "m", "m", "m", "m", "m"…
#> $ t <dbl> 0.95834723, 0.22334794, 0.52202577, 0.11669206, 10.06096642, 1.…
#> $ c <dbl> 2.46284098, 1.34471139, 8.49836390, 0.09817416, 8.58252903, 7.7…
#> $ time <dbl> 0.95834723, 0.22334794, 0.52202577, 0.09817416, 8.58252903, 1.1…
#> $ status <dbl> 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, …