In: Statistics and Probability
This is the code in R for the Central Limit theorem question. This is Exponential distribution with mean beta. How can I modify this code to
Bernoulli(0.1), Uniform (0,4), and Normal distribution (2,1)
plot.z <- function(n, m=1e5, beta = 1) {
mu <- beta
sigma <- beta
zs <- rep(0,m)
for(i in 1:m) {
Y.sample <- rexp(n, 1/beta)
Ybar <- mean(Y.sample)
zs[i] <- (Ybar - mu) / (sigma / sqrt(n))
}
p <- hist(zs, xlim=c(-4,4), freq = F,
main = paste("Distribution of Z_n when n=",n, sep=""))
points(seq(-4,4,0.01), dnorm(seq(-4,4,0.01),0,1), type = ’l’)
}
par(mfrow = c(2,2)) # Put four plots in a 2 by 2 grid.
for (n in c(2, 10, 50, 200)) {
plot.z(n)
}