# # # 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. # #----- # fix the random.seed, so I'll always get the same answer: set.seed(10131985) mu = 1.0 beta = 2.0 Nsim = 10^4 U = runif(Nsim) X = mu - beta * log( 1/U - 1 ) Y = rlogis(Nsim,location=mu,scale=beta) ###postscript("../../WriteUp/Graphics/Chapter2/ex_2_2_logistic.eps", onefile=FALSE, horizontal=FALSE) par(mfrow=c(1,2)) hist(X,freq=F,main="Logistic from Uniform",breaks=100) hist(Y,freq=F,main="Logistic from R(rlogis)",breaks=100) ###dev.off() mu = 1 sigma = 2 Nsim = 10^6 U = runif(Nsim) X = mu + sigma * tan( pi * (U-0.5) ) Y = rcauchy(Nsim,location=mu,scale=sigma) range = as.double( quantile( c(X,Y), probs=c(0.05,0.95) ) ) allMin = min( min(X),min(Y) ) allMax = max( max(X),max(Y) ) brks = seq(range[1],range[2],length.out=100) par(mfrow=c(1,2)) hist(X,freq=F,main="Cauchy from Uniform") hist(Y,freq=F,main="Cauchy from R(rcauchy)")