Draw random samples from an exponential distribution with piecewise rates. rpwexp is vectorized and written in C++ for speed.

rpwexp(n, rate = 1, time = 0)

## Arguments

n Number of random observations to draw. A matrix of rates where rows correspond to observations and columns correspond to rates during specified time intervals. A vector equal to the number of columns in rate giving the times at which the rate changes

## Value

A vector of random samples from the piecewise exponential distribution. The length of the sample is determined by n. The numerical arguments other than n are recycled so that the number of samples is equal to n.

## Examples

rate <- c(.6, 1.2, 1.3)
n <- 100000
ratemat <- matrix(rep(rate, n/2), nrow = n,
ncol = 3, byrow = TRUE)
t <- c(0, 10, 15)
ptm <- proc.time()
samp <- rpwexp(n, ratemat, t)
proc.time() - ptm
#>    user  system elapsed
#>   0.009   0.002   0.011 summary(samp)
#>    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
#>  0.0000  0.4793  1.1517  1.6597  2.3021 14.4929