Skip to contents

Simulate right-censored survival data with sparsely and intermittently observed longitudinal covariates under a transformed hazards model.

Usage

sim_skmle_data(n, mu, mu_bar, alpha, beta, s, cen, nstep = 20)

Arguments

n

Number of subjects to simulate.

mu

Function giving the intensity of the observation-time process for the longitudinal covariates.

mu_bar

Numeric upper bound for mu on the follow-up interval.

alpha

Function giving the baseline component of the transformed hazards model.

beta

Numeric vector of true regression coefficients. The current simulator supports exactly two covariates, so length(beta) must equal 2.

s

Box-Cox transformation parameter. Use s = 0 for a proportional hazards model and s = 1 for an additive hazards model.

cen

Positive censoring parameter controlling the follow-up window.

nstep

Number of grid intervals used to generate the latent piecewise-constant time-varying covariate process.

Value

A tibble in long format with columns:

  • id: subject identifier.

  • X: observed event or censoring time.

  • delta: event indicator.

  • covariates: a two-column matrix of observed covariates at obs_times.

  • obs_times: longitudinal observation time.

  • censoring: subject-specific censoring time.

Details

The simulated data are returned in long format, with one row per subject-visit pair. Each row contains the observed event or censoring time, the event indicator, the observation time for the longitudinal covariate, and the covariate values observed at that visit.

The first covariate is generated as a latent step function over time. The second covariate is a binary subject-level indicator. Event times are generated by numerically inverting the cumulative transformed hazard, and observation times are generated from a non-homogeneous Poisson process.

Examples

set.seed(123)
sim_data <- sim_skmle_data(
  n = 50,
  mu = function(tt) 8 * (0.75 + (0.5 - tt)^2),
  mu_bar = 8,
  alpha = function(tt) 0.5 * 0.75 + 0.75 * (tt * (1 - sin(2 * pi * (tt - 0.25)))),
  beta = c(1, -0.5),
  s = 0,
  cen = 0.7
)

head(sim_data)
#> # A tibble: 6 × 6
#>   id        X delta covariates[,1]  [,2] obs_times censoring
#>   <chr> <dbl> <lgl>          <dbl> <dbl>     <dbl>     <dbl>
#> 1 1     0.550 TRUE         0.419       1     0.129     0.930
#> 2 1     0.550 TRUE         0.593       1     0.217     0.930
#> 3 1     0.550 TRUE         0.593       1     0.247     0.930
#> 4 1     0.550 TRUE         0.412       1     0.433     0.930
#> 5 1     0.550 TRUE         0.933       1     0.798     0.930
#> 6 2     0.747 TRUE        -0.00422     1     0.288     0.865
table(sim_data$delta)
#> 
#> FALSE  TRUE 
#>    43   274 

# The `covariates` column is a matrix; use it directly in model formulas
# or split it into explicit columns if preferred.
sim_data$Z1 <- sim_data$covariates[, 1]
sim_data$Z2 <- sim_data$covariates[, 2]
head(sim_data[, c("id", "X", "delta", "obs_times", "Z1", "Z2")])
#> # A tibble: 6 × 6
#>   id        X delta obs_times       Z1    Z2
#>   <chr> <dbl> <lgl>     <dbl>    <dbl> <dbl>
#> 1 1     0.550 TRUE      0.129  0.419       1
#> 2 1     0.550 TRUE      0.217  0.593       1
#> 3 1     0.550 TRUE      0.247  0.593       1
#> 4 1     0.550 TRUE      0.433  0.412       1
#> 5 1     0.550 TRUE      0.798  0.933       1
#> 6 2     0.747 TRUE      0.288 -0.00422     1