Function to generate a random sample of survival data from proportional hazards 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.
- 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 = rphreg(runif(n), ~ age+sex, beta = 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.20132441, -0.28838825, -1.20566309, -1.79280986, -1.09822670,…
#> $ sex <chr> "m", "f", "m", "m", "m", "m", "f", "m", "m", "f", "f", "m", "f"…
#> $ t <dbl> 0.23646815, 0.77732579, 0.09428336, 0.10775901, 0.86407215, 0.1…
#> $ c <dbl> 2.861600, 9.481602, 9.357638, 1.442198, 8.562252, 4.103321, 4.7…
#> $ time <dbl> 0.23646815, 0.77732579, 0.09428336, 0.10775901, 0.86407215, 0.1…
#> $ status <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, …