Using R, how will I be able to generate an exponentially distributed random variable with rate 1 by only generating a uniformly distributed random variable(runif function in r).
Found in https://stephens999.github.io/fiveMinuteStats/inverse_transform_sampling.html:
# inverse transfrom 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)