# epage 74 # # 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^4 # small/large values for lambda (the value of 1/mean) # lambda = 2 X = NULL for( ii in 1:Nsim ){ k = 0 v = rexp(1,rate=lambda) while( v < 1 ){ v = v + rexp(1,rate=lambda) k = k+1 } X[ii]=k } xRng = seq(min(X),max(X),1) brks = c( xRng[1] - 0.5, xRng + 0.5 ) hist(X,freq=F,breaks=brks,main="Poisson from Exponential") lines( xRng, dpois(xRng,lambda), col="Blue" )