[R] plot - central limit theorem

Duncan Murdoch murdoch at stats.uwo.ca
Wed Oct 15 22:00:32 CEST 2008


On 10/15/2008 3:48 PM, Jörg Groß wrote:
> Hi,
> 
> 
> Is there a way to simulate a population with R and pull out m samples,  
> each with n values
> for calculating m means?
> 
> I need that kind of data to plot a graphic, demonstrating the central  
> limit theorem
> and I don't know how to begin.

The easiest way to do this is to put the simulations into a matrix, and 
calculate row means (or column means).  For example:

par(mfrow=c(2,2))

m <- 10000
for (n in c(1,2,4,8)) {
   sims <- matrix(runif(n*m), ncol=n)
   means <- rowMeans(sims)
   hist(means, main=paste("n = ", n), xlim=c(0,1))
}

Duncan Murdoch

> 
> So, perhaps someone can give me some tips and hints how to start and  
> which functions to use.
> 
> 
> 
> thanks for any help,
> joerg
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list