# # # Written by: # -- # John L. Weatherwax 2009-04-21 # # email: wax@alum.mit.edu # # Please send comments and especially bug reports to the # above email address. # #----- Nsim = 10^6; alpha = 1 M = sqrt( 2/pi ) * exp(1/2) randg = function(Nsim,alpha){ # a function to generate Nsim random variable from a double exponential using the inverse transform # X = double(Nsim) U = runif(Nsim) X[ U <= 1/2 ] = log(2* U[ U <= 1/2 ])/alpha X[ U > 1/2 ] = -log(2*(1-U[ U > 1/2 ]))/alpha X } # draw samples from g(y) using the known probability of acceptance # x = NULL while( length(x)