531f10RVG - # # STAT 531 RVG # Nsim <- 10^4 U <-...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
############################################################# # STAT 531 RVG ############################################################# Nsim <- 10^4 U <- runif (Nsim) X <- - log(U) Y <- rexp(Nsim) par(mfrow=c(1,2)) hist(X, freq=F, main= "Exp from Uniform") hist(Y, freq=F, main= "Exp from R") ############################################################# Nsim <- 3*10^4 U <- runif(Nsim) U <- matrix(data=U, nrow=3) X <- - log(U) X <- 2*apply(X, 2, sum) s <- seq(0,30, length=100) hist(X, freq =F, main= "Chi-square from Uniform") lines(s, dchisq(s,6), lwd=2, col="sienna") ############################################################# Nsim = 10^4 U1 =runif(Nsim) U2=runif(Nsim) X1=sqrt(-2*log(U1)) *cos(2*pi*U2) X2=sqrt(-2*log(U1)) *sin(2*pi*U2) par(mfrow=c(1,2)) hist(X1, freq =F, main= " Normal from Uniform") s <- seq(-4,4, length=100) lines(s, dnorm(s), lwd=2, col="sienna") hist(X2, freq =F, main= " Normal from Uniform") lines(s, dnorm(s), lwd=2, col="sienna") ############################################################# Nsim <- 10^4
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

531f10RVG - # # STAT 531 RVG # Nsim &lt;- 10^4 U &lt;-...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online