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)
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.
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
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
summary(samp)
Run the code above in your browser using DataLab