Skip to contents

Function to generate a random sample of survival data from Yang and Prentice models.

Usage

rypreg(u, formula, baseline, beta, phi, dist = NULL, package = NULL, data, ...)

Arguments

u

a numeric vector of quantiles.

formula

formula specifying the linear predictors.

baseline

the name of the baseline survival distribution.

beta

vector of short-term regression coefficients.

phi

vector of long-term 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.

Value

a numeric vector containing the generated random sample.

Examples

library(rsurv)
library(dplyr)
n <-  1000
simdata <- data.frame(
  age = rnorm(n),
  sex = sample(c("f", "m"), size = n, replace = TRUE)
) %>%
  mutate(
    t = rypreg(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.7372501, 0.3406855, 0.7693792, -0.5542765, 2.0108546, -1.4303…
#> $ sex    <chr> "m", "f", "f", "f", "m", "f", "m", "m", "m", "m", "m", "f", "f"…
#> $ t      <dbl> 0.12673149, 0.06144217, 1.24920636, 1.27452622, 0.03664846, 1.6…
#> $ c      <dbl> 9.1136589, 2.1135732, 5.2277696, 9.5475630, 4.7188359, 1.095158…
#> $ time   <dbl> 0.12673149, 0.06144217, 1.24920636, 1.27452622, 0.03664846, 1.0…
#> $ status <dbl> 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, …