Skip to content
Prev 68277 / 398502 Next

Using R to illustrate the Central Limit Theorem

Hi Paul

This is one of many ways to do it

hist(runif(30))#histogram from 30 random samples from a uniform(0,1)
mm=c(NULL)#creates null vector
for(i in 1:100){mm[i]=mean(runif(30))}#100 sample means of 30 samples each 
from a uniform(0,1)
hist(mm)#the distribution of the sample mean looks normal!

You can even nest this loop within another loop so your student can see 
several histograms showing a "normal" behaviour.

I hope this helps

Francisco