Skip to content

Instantly share code, notes, and snippets.

@chiral
Created October 8, 2011 18:58
Show Gist options
  • Save chiral/1272702 to your computer and use it in GitHub Desktop.
Save chiral/1272702 to your computer and use it in GitHub Desktop.
simulation of CLT-theorem applied to unform distribution
# resulting image is
# http://dl.dropbox.com/u/15259519/images/CLT_sim.png
sr <- function() source("CLT_test.R")
sim1 <- function(n,m=500,c=30) {
mat <- matrix(runif(m*n),c(m,n))
res <- (rowSums(mat)-n*0.5)/sqrt(n/12)
hist(res,nclass=c,main='',xlab=sprintf("N=%d, trial num=%d",n,m))
}
sim <- function(n=c(1,2,3,5,10),m=c(10,100,500,10000,100000)) {
ln <- length(n)
lm <- length(m)
layout(matrix(1:(ln*lm),lm,ln))
for (i in n) for (j in m) sim1(i,j)
}
sim()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment