This function generates simulated survival data following a piecewise exponential distribution with specified time intervals and hazard rates.
Arguments
- n
Sample size (number of subjects to simulate)
- time_points
Numeric vector of time points defining intervals
- hazard_rates
Numeric vector of hazard rates for each interval
- max_time
Maximum follow-up time (administrative censoring)
- censoring_prob
Probability of random censoring (default 0.1)
- seed
Random seed for reproducibility (default NULL)
Value
Data frame with columns:
- time
Observed time (either event time or censoring time)
- status
Event indicator (1 = event, 0 = censored)
Details
The function simulates survival times using inverse transform sampling for piecewise exponential distribution. Random censoring is applied uniformly between 0 and the simulated survival time.
Examples
# Simulate data with 4 intervals
time_points <- c(0, 6, 12, 18, 24)
hazard_rates <- c(0.05, 0.08, 0.12, 0.15)
sim_data <- simPE(
n = 200,
time_points = time_points,
hazard_rates = hazard_rates,
max_time = 24,
censoring_prob = 0.15,
seed = 123
)
# Check event rate
table(sim_data$status)
#>
#> 0 1
#> 15 185
# Reproducible results
sim_data1 <- simPE(n = 100, time_points, hazard_rates, 24, seed = 456)
sim_data2 <- simPE(n = 100, time_points, hazard_rates, 24, seed = 456)
identical(sim_data1, sim_data2) # Should be TRUE
#> [1] TRUE