function (pdf = F) { if (pdf == T) pdf("clt3.pdf", width = 9, height = 6) par(mfrow = c(3, 2)) n = 10000 alpha = 1 beta = 2 mu = -2 x1 = rnorm(n) x2 = runif(n) x3 = exp(rnorm(n) + mu) x4 = alpha * (-log(1 - runif(n)))^(1/beta) x5 = 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), nclass = 50, xlab = expression(x[2])) segments(0, 0, 0, 1) segments(0, 1, 1, 1) segments(1, 1, 1, 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) hist(x5, main = "Weibull population", prob = T, nclass = 50, xlab = expression(x[5])) t = (0:300)/100 yt = (t/alpha)^(beta - 1) * exp(-(t/alpha)^beta) * beta/alpha lines(t, yt) if (pdf == T) { dev.off() pdf("clt4.pdf", width = 9, height = 6) } readline("hit return\n") par(mfrow = c(2, 1)) xsum = x1 + x2 + x3 + x4 m = mean(xsum) s = sqrt(var(xsum)) hist(xsum, main = "Central Limit Theorem at Work", prob = T, nclass = 50, xlab = expression(x[1] + x[2] + x[3] + x[4])) t = ((0:60)/10 - 3) * s + m ty = exp(-(t - m)^2/(2 * s^2))/(sqrt(2 * pi) * s) lines(t, ty) xsum = x2 + x3 + x4 + x5 m = mean(xsum) s = sqrt(var(xsum)) hist(xsum, main = "Central Limit Theorem at Work", prob = T, nclass = 50, xlab = expression(x[2] + x[3] + x[4] + x[5])) t = ((0:60)/10 - 3) * s + m ty = exp(-(t - m)^2/(2 * s^2))/(sqrt(2 * pi) * s) lines(t, ty) if (pdf == T) dev.off() }