function (pdf = F) { if (pdf == T) pdf("clt7.pdf", width = 9, height = 6) par(mfrow = c(2, 2)) n = 10000 alpha = 1 beta = 2 mu = -2 x1 = rnorm(n) x2 = 20 * runif(n) x3 = exp(rnorm(n) + mu) x4 = alpha * (-log(1 - runif(n)))^(1/beta) hist(x1, main = "standard normal population", prob = T, ylim = c(0, 0.5), nclass = 50, xlab = expression(x[1])) t = (0:60)/10 - 3 yt = exp(-t^2/2)/sqrt(2 * pi) lines(t, yt) hist(x2, main = "uniform population on (0,1)", prob = T, ylim = c(0, 1.3/20), nclass = 50, xlab = expression(x[2])) segments(0, 0, 0, 1/20) segments(0, 1/20, 20, 1/20) segments(20, 1/20, 20, 0) hist(x3, main = "a log-normal population", prob = T, ylim = c(0, 5), nclass = 200, xlim = c(0, 1.5), xlab = expression(x[3])) lines(exp(t + mu), yt/exp(t + mu)) hist(x4, main = "Weibull population", prob = T, nclass = 50, xlab = expression(x[4])) t = (0:300)/100 yt = (t/alpha)^(beta - 1) * exp(-(t/alpha)^beta) * beta/alpha lines(t, yt) if (pdf == T) { dev.off() pdf("clt8.pdf", width = 9, height = 6) } par(mfrow = c(1, 1)) readline("hit return\n") xsum = x1 + x2 + x3 + x4 m = mean(xsum) s = sqrt(var(xsum)) hist(xsum, main = "Central Limit Theorem at Work (not so good)", prob = T, xlab = expression(x[1] + x[2] + x[3] + x[4]), nclass = 50, ylim = c(0, 0.08), xlim = c(-20, 40)) t = ((0:60)/10 - 3) * s + m ty = exp(-(t - m)^2/(2 * s^2))/(sqrt(2 * pi) * s) lines(t, ty) abline(h = 0) if (pdf == T) dev.off() }