[R] Using R to illustrate the Central Limit Theorem

Kevin E. Thorpe kevin.thorpe at utoronto.ca
Fri May 13 14:28:05 CEST 2005


The variance of U[0,1] is 1/12. So the variance of the mean of uniforms 
is 1/12k.
Rather than dividing by 1/12k he multiplied by 12k.

Kevin

Bliese, Paul D LTC USAMH wrote:

>Interesting thread. The graphics are great, the only thing that might be
>worth doing for teaching purposes would be to illustrate the original
>distribution that is being averaged 1000 times.
>
>Below is one option based on Bill Venables code.  Note that to do this I
>had to start with a k of 2.
>
>N <- 10000
> for(k in 2:20) {
>    graphics.off()
>    par(mfrow = c(2,2), pty = "s")
>    hist(((runif(k))-0.5)*sqrt(12*k),main="Example Distribution 1")
>    hist(((runif(k))-0.5)*sqrt(12*k),main="Example Distribution 2")
>    m <- replicate(N, (mean(runif(k))-0.5)*sqrt(12*k))
>    hist(m, breaks = "FD", xlim = c(-4,4), main = k,
>            prob = TRUE, ylim = c(0,0.5), col = "lemonchiffon")
>    pu <- par("usr")[1:2]
>    x <- seq(pu[1], pu[2], len = 500)
>    lines(x, dnorm(x), col = "red")
>    qqnorm(m, ylim = c(-4,4), xlim = c(-4,4), pch = ".", col = "blue")
>    abline(0, 1, col = "red")
>    Sys.sleep(3)
>  }
>
>By the way, I should probably know this but what is the logic of the
>"sqrt(12*k)" part of the example?  Obviously as k increases the mean
>will approach .5 in a uniform distribution, so runif(k)-.5 will be close
>to zero, and sqrt(12*k) increases as k increases.  Why 12, though?
>
>PB
>  
>


-- 
Kevin E. Thorpe
Biostatistician/Trialist, Knowledge Translation Program
Assistant Professor, Department of Public Health Sciences
Faculty of Medicine, University of Toronto
email: kevin.thorpe at utoronto.ca  Tel: 416.946.8081  Fax: 416.971.2462




More information about the R-help mailing list