| pa_sim_cox_weibull | R Documentation |
Generates survival data under a Cox proportional hazards model with a Weibull
baseline cumulative hazard H_0(t) = (0.5 t)^v. Event times are sampled via
inverse transform:
Y = H_0^{-1}(-\log U \cdot \exp(-\beta^\top Z)), \quad U \sim \mathrm{Unif}(0,1),
where H_0^{-1}(s) = 2 s^{1/v}.
Covariates are simulated from a standard normal distribution.
When interact = FALSE, the design matrix Z contains only main effects.
When interact = TRUE, the function automatically detects whether length(beta)
equals 3 or 7:
If length(beta) = 3, two covariates (x_1, x_2) and their
two-way interaction (x_1 x_2) are included.
If length(beta) = 7, three covariates (x_1, x_2, x_3),
their three two-way interactions (x_1 x_2, x_1 x_3, x_2 x_3),
and their three-way interaction (x_1 x_2 x_3) are included.
Right-censoring times are generated as C_i = \exp(\mu + r_i) with
r_i \sim \mathcal{N}(0, \mathrm{sd}^2). By default, sd is set to
\mathrm{sd}(\log Y), and mu is calibrated so that the expected censoring
proportion equals pi_c. If mu and/or sd are supplied, calibration
is skipped accordingly:
mu and sd provided: use them directly (no calibration).
sd only: solve for mu using the given sd.
mu only: use the given mu and estimate \mathrm{sd}(\log Y).
neither: estimate both \mathrm{sd}(\log Y) and mu.
pa_sim_cox_weibull(
n,
pi_c,
v,
beta,
mu = NULL,
sd = NULL,
seed = NULL,
interact = FALSE,
nonlinear = FALSE
)
n |
Integer. Sample size. |
pi_c |
Numeric in |
v |
Positive numeric. Weibull shape in |
beta |
Numeric vector of regression coefficients.
If |
mu |
Optional numeric. Mean of |
sd |
Optional positive numeric. Standard deviation used in
|
seed |
Optional integer seed for reproducibility. |
interact |
Logical (default |
nonlinear |
Logical. If 'TRUE', generates two covariates plus their interaction and a quadratic term; 'beta' must then have length 4. |
A data.frame with columns:
time: observed time T_i = \min(Y_i, C_i).
status: event indicator 1\{Y_i \le C_i\}.
x1, x2, ...: simulated covariates.
x1:x2, x1:x3, ...: interaction terms (if interact = TRUE).
y_true: latent event time Y_i.
cens_time: censoring time C_i.
Attributes include:
mu: censoring shift used.
sd_log: standard deviation used in \log C.
sd_logY: \mathrm{sd}(\log Y) from the generated events.
pi_c_target: requested censoring rate.
pi_c_observed: realized censoring rate.
v, beta: model parameters.
interact: logical flag indicating whether interactions were included.
nonlinear: logical flag indicating whether polynomial and interactions term were included.
# (1) Main effects only
set.seed(1)
d0 <- pa_sim_cox_weibull(500, 0.3, v = 1.2, beta = c(0.4, -0.2))
# (2) Two covariates + their interaction
d1 <- pa_sim_cox_weibull(500, 0.3, v = 1.2,
beta = c(0.5, -0.3, 0.2),
interact = TRUE)
# (3) Three covariates + all two-way and three-way interactions
b <- c(0.4, -0.2, 0.1, 0.15, -0.05, 0.08, 0.02)
d2 <- pa_sim_cox_weibull(500, 0.3, v = 1.0, beta = b, interact = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.