Here we show how histograms of n normalized sums of m independent random variables approach the standard normal.
clt <- function(n, m) {
s <- sqrt(12 * m)
x <- NULL
for (i in 1:n) {
x <- c(x, s * (mean(runif(m)) - 0.5))
hist(x, xlim = c(-4, 4), ylim = c(0, 0.4), freq = FALSE, density = 20,
col = "GREEN", border = "BLUE")
lines(z <- seq(-4, 4, length = 100), dnorm(z), col = "RED", lwd = 3)
}
}
set.seed(12345)
opts_knit$set(animation.fun = hook_r2swf)
par(bg = "white")
clt(100, 12)