CLT simulation with R I am trying to run a simple CLT simulation with R.
I want to create a vector with 10000 dice rolls, then take 100 means of samples of "n" size to see how when "n" increases, the distribution starts looking more normal.
population<-sample(1:6, 10000, replace=TRUE)
clt.example<-function(sample.size){
  sapply(1:100, function(y){ mean( sample(population,sample.size))} )
}

However, when I run:
hist(clt.example(5))
hist(clt.example(10))
hist(clt.example(50))
hist(clt.example(100))

I don't see much difference to be honest. Actually, the one using 100 looks less normal than the one using 50, so I guess I am doing something wrong.
 A: Two possible issues


*

*100 isn't that many realisations- try
hist(rnorm(100))
hist(rnorm(100))
hist(rnorm(100))

for an illustration.. you might have been unlucky with your run.

*The CLT applies to i.i.d samples from the population.  So really you should have replace = T.  Actually this doesn't matter much because the sample size is so small compared to the population.
I suggest you play with
clt.example<-function(sample.size){
    sapply(1:1000, function(y){ mean( sample(population,sample.size,replace=T))} )
}

A final comment is that, since you begin with a normal population, the sample mean is exactly normal.  Any departure from a normal-looking curve is due to chance, rather than the CLT not kicking in.
You can see the CLT kicking in with something like
population<-rexp(10000)
hist(clt.example(1))
hist(clt.example(5))
hist(clt.example(10))
hist(clt.example(15))
hist(clt.example(25))
hist(clt.example(50))

(I used 1000 samples, and no replacement, but I don't think the latter matters for these relative small sample sizes).
Edit: I notice you edited your question, making my final comment less relevant.  But I'll leave it there anyway.
