531f10RVG

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

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

############################################################# # 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

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 3

531f10RVG - STAT 531 RVG Nsim < 10^4 U < runif(Nsim X <...

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

View Full Document
Ask a homework question - tutors are online