rpwexp: The Piecewise Exponential Distribution

View source: R/rpwexp.R

rpwexpR Documentation

The Piecewise Exponential Distribution

Description

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.

Usage

rpwexp(n = 100, fail_rate = tibble(duration = c(1, 1), rate = c(10, 20)))

Arguments

n

Number of observations to be generated.

fail_rate

A tibble containing duration and rate variables. rate specifies failure rates during the corresponding interval duration specified in duration. The final interval is extended to be infinite to ensure all observations are generated.

Details

Using the cumulative=TRUE option, enrollment times that piecewise constant over time can be generated.

Examples

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}")


keaven/simtrial documentation built on April 17, 2023, 4:03 a.m.