# Example 1
# Exponential failure times
x <- rpwexp(
n = 10000,
fail_rate = data.frame(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 to 0.5, 3 for time 0.5 to 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 = data.frame(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}"
)
Run the code above in your browser using DataLab