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

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Fri 22 Apr 2005 - 06:21:39 EST

(Ted Harding) <Ted.Harding@nessie.mcc.ac.uk> writes:

> On 21-Apr-05 Paul Smith wrote:
> > 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.
> >
> >
> > Paul
>
> Similar to Francisco's suggestion:
>
> m<-numeric(10000);
> for(k in (1:20)){
> for(i in(1:10000)){m[i]<-(mean(runif(k))-0.5)*sqrt(12*k)}
> hist(m,breaks=0.3*(-15:15),xlim=c(-4,4),main=sprintf("%d",k))
> }

Ted, you and several others in this thread may want to notice the existence of a little function called replicate():

...

m <- replicate(10000, (mean(runif(k))-0.5)*sqrt(12*k)) ...

```--
O__  ---- Peter Dalgaard             Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics     2200 Cph. N
(*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help