Learn R Programming

hesim (version 0.5.5)

rpwexp: Random generation for piecewise exponential distribution

Description

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

Usage

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

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.

Arguments

n

Number of random observations to draw.

rate

A matrix of rates where rows correspond to observations and columns correspond to rates during specified time intervals.

time

A vector equal to the number of columns in rate giving the times at which the rate changes

Examples

Run this code
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