generate_pe {DTEBOP2} | R Documentation |
Generate event times from a piecewise exponential distribution.
Description
Generates random event times under a piecewise exponential distribution, where different constant hazard rates apply before and after a specified separation timepoint. This is commonly used for simulating survival data with delayed treatment effects.
Usage
generate_pe(n, t, lambda1, lambda2)
Arguments
n |
Integer. Number of event times to generate (i.e., sample size). |
t |
Numeric. Separation timepoint at which the hazard rate changes. |
lambda1 |
Numeric. Constant hazard rate before the separation timepoint. |
lambda2 |
Numeric. Constant hazard rate after the separation timepoint. |
Value
A numeric vector of length n
, representing simulated survival times
drawn from a piecewise exponential distribution with hazard rate lambda1
before time t
, and lambda2
after time t
.
Times are expressed in the same time unit as specified in the hazard rate (typically months)
Examples
set.seed(42)
generate_pe(1000, 1, 1, 0.5)