Prop If
Algorithm Inversion Sampling
To draw
- Draw
- Set
- Return
as iid samples from . e.g. Assume is an exponential random variable with rate parameter . Recall that the probability density function is for . First, we compute the CDF: Solving for the inverse CDF, we get that Using our algorithm above, we first generate , then set . We do this in the R code below and compare the histogram of our samples with the true density of :
# inverse transform sampling
num.samples <- 1000
U <- runif(num.samples)
X <- -log(1-U)/2
# plot
hist(X, freq=F, xlab='X', main='Generating Exponential R.V.')
curve(dexp(x, rate=2) , 0, 3, lwd=2, xlab = "", ylab = "", add = T)