rpwexp | R Documentation |
The piecewise exponential distribution allows a simple method to specify a distribtuion
where the hazard rate changes over time. It is likely to be useful for conditions where
failure rates change, but also for simulations where there may be a delayed treatment
effect or a treatment effect that that is otherwise changing (e.g., decreasing) over time.
rpwexp()
is to support simulation of both the Lachin and Foulkes (1986) sample size
method for (fixed trial duration) as well as the Kim and Tsiatis(1990) method
(fixed enrollment rates and either fixed enrollment duration or fixed minimum follow-up);
see gsDesign
.
rpwexp(n = 100, fail_rate = tibble(duration = c(1, 1), rate = c(10, 20)))
n |
Number of observations to be generated. |
fail_rate |
A tibble containing |
Using the cumulative=TRUE
option, enrollment times that piecewise constant over
time can be generated.
library(tibble)
# example 1
# exponential failure times
x <- rpwexp(n = 10000,
fail_rate = tibble(rate = 5, duration = 1))
plot(sort(x),(10000:1)/10001,
log = "y", main = "Exponential simulated survival curve",
xlab = "Time",ylab = "P{Survival}")
# example 2
# get 10k piecewise exponential failure times
# failure rates are 1 for time 0-.5, 3 for time .5 - 1 and 10 for >1.
# intervals specifies duration of each failure rate interval
# with the final interval running to infinity
x <- rpwexp(n = 1e4,
fail_rate = tibble(rate = c(1, 3, 10), duration = c(.5, .5, 1)))
plot(sort(x), (1e4:1)/10001,
log = "y", main = "PW Exponential simulated survival curve",
xlab = "Time", ylab = "P{Survival}")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.