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@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.

______________________________________________
R-help@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.

Reply via email to