Re: [R] Using R to illustrate the Central Limit Theorem

From: Kevin E. Thorpe <kevin.thorpe_at_utoronto.ca>
Date: Fri 13 May 2005 - 22:28:05 EST

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@utoronto.ca  Tel: 416.946.8081  Fax: 416.971.2462

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Fri May 13 22:33:04 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:45 EST