#' Central Limit Theorem Simulation for Uniform Distributions
#'
#' @param n size of sample
#' @param iter number of iterations the simulation will run using n
#' @param a lower limit of uniform distribution
#' @param b upper limit of uniform distribution
#'
#' @return Histogram of sample mean for the uniform distribution with a theoretical normal curve added.
#' @export
#'
#' @examples mycltu(n=20, iter=10000, a=0, b=10)
mycltu=function(n,iter,a=0,b=10){
y=runif(n*iter,a,b)
data=matrix(y,nr=n,nc=iter,byrow=TRUE)
w=apply(data,2,mean)
param=hist(w,plot=FALSE)
ymax=max(param$density)
ymax=1.1*ymax
hist(w,freq=FALSE, ylim=c(0,ymax), main=paste("Histogram of sample mean",
"\n", "sample size= ",n,sep=""),xlab="Sample mean")
lines(density(w),col="Blue",lwd=3)
curve(dnorm(x,mean=(a+b)/2,sd=(b-a)/(sqrt(12*n))),add=TRUE,col="Red",lty=2,lwd=3)
curve(dunif(x,a,b),add=TRUE,lwd=4)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.