[R] Using R to illustrate the Central Limit Theorem

Lucke, Joseph F LUCKE at uthscsa.edu
Thu Apr 21 20:53:39 CEST 2005


I just did this last night for a class. It's very simplistic and could
be improve, but it did the job.  First I did the normal. Of course means
of increasing large samples from a normal stay normal.  This setup the
students.  Then I did means from an exponential.  For n=1 you get the
exponential again, and they of course expected the means with larger n's
to also follow the exponential! Got 'em!
Joe

#Central Limit Theorem
oldpar = par(mfrow=c(2,2))
#Normal
n=64    #Do it repeatedly for n=1 4, 16, 64, 100
d=numeric(1000)
for (k in 1:1000){d[k]=mean(rnorm(n,mean=5,sd=16))}
c(mean=mean(d),sd=sd(d))
plot(density(d),col='blue')
curve(dnorm(x,mean=5,sd=16/sqrt(n)),add=T,col='red')


#Exponential
n=64    #1, 4, 16, 64, 100
d=numeric(1000)
for (k in 1:1000){d[k]=mean(rexp(n,rate=1/4))}
c(mean=mean(d),sd=sd(d))
plot(density(d),col='blue')
curve(dnorm(x,mean=4,sd=4/sqrt(n)),add=T,col='red')

par(oldpar)



-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Paul Smith
Sent: Thursday, April 21, 2005 12:07 PM
To: r-help at stat.math.ethz.ch
Subject: [R] Using R to illustrate the Central Limit Theorem


Dear All

I am totally new to R and I would like to know whether R is able and
appropriate to illustrate to my students the Central Limit Theorem,
using for instance 100 independent variables with uniform distribution
and showing that their sum is a variable with an approximated normal
distribution.

Thanks in advance,

Paul

______________________________________________
R-help at 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




More information about the R-help mailing list