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
- data
data frame containing the covariates used to generate the survival times.
- ...
further arguments passed to other methods.
Examples
# \donttest{
library(rsurv)
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.68692169, -0.49881342, -0.73643002, 1.82220966, 0.71527182, …
#> $ sex <chr> "f", "m", "m", "m", "f", "m", "f", "f", "m", "f", "m", "f", "m"…
#> $ t <dbl> 1.36019806, 0.67495941, 0.25361211, 0.10387005, 0.77697637, 0.7…
#> $ c <dbl> 9.61688197, 6.76407993, 7.33013458, 9.99347166, 7.71608095, 6.6…
#> $ time <dbl> 1.36019806, 0.67495941, 0.25361211, 0.10387005, 0.77697637, 0.7…
#> $ status <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, …
# }