View source: R/prediction_survival.R
| simulate_proportional_survival | R Documentation |
Draws independent covariates, multiplies the baseline cumulative hazard by
exp(x %*% coefficients), and inverts it to an event time, so the model is
proportional hazards and each coefficient is a log hazard ratio. The three
baselines are, for a unit with linear predictor eta,
Weibull H(t) = rate * exp(eta) * t^shape,
exponential H(t) = rate * exp(eta) * t, and
Gompertz H(t) = rate * exp(eta) * (exp(shape * t) - 1) / shape.
Censoring is random, not administrative: an independent exponential censoring
time is drawn for every unit, its rate solved so that the expected censored
fraction equals censoring.
simulate_proportional_survival(
n,
coefficients,
baseline = c("weibull", "exponential", "gompertz"),
rate = 0.1,
shape = 1,
censoring = 0.3,
covariate_distribution = c("normal", "binary"),
seed = NULL,
batch = NULL
)
n |
Sample size. A single whole number of at least 5. |
coefficients |
Covariate log-hazard coefficients, a numeric vector with
at least one element and one entry per covariate. Its names become the
covariate columns; unnamed vectors are named |
baseline |
Baseline hazard family, one of |
rate |
Positive scale factor of the baseline cumulative hazard. A single
positive number, defaulting to |
shape |
Positive shape of the Weibull or Gompertz baseline, in the
textbook parameterization of the formulas above (so the hazard rises with
time when |
censoring |
Target fraction of censored observations. A single number in
|
covariate_distribution |
Distribution the covariates are drawn from,
independently, one of |
seed |
Optional random seed. A single number, or |
batch |
Optional single positive whole number. When given, the
simulator runs |
A simulab_sim base data.frame with one row per unit and columns
id, time (the observed time, the smaller of the event and censoring
times), the integer status (1 for an event and 0 for a censored
observation), and one covariate column per entry of coefficients.
Components: parameters (one row per term, columns term and value,
holding the coefficients followed by baseline_rate, shape and the
solved censoring_rate) and diagnostics (one row, columns
target_censoring, realized_censoring and baseline).
result <- simulate_proportional_survival(
n = 200,
coefficients = c(x1 = 0.7),
shape = 1.5,
censoring = 0.2,
seed = 1
)
head(result)
as.data.frame(result, what = "parameters")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.