### Central Limit Theorem # Take samples from a normal population. Plot a histogram of the sampling # distribution of x.bar. m <- 50 sd <- 10 par(mfrow=c(2,2)) x <- (0:100) p.norm <- dnorm(x,m,sd) plot(x,p.norm,main="normal density",type="l",xlim=c(0,100)) x <- matrix(rnorm(3000,m,sd),nrow=30) x.bar <- apply(x,2,mean) hist(x.bar,main="sampling distribution of x.bar",xlim=c(40,60)) plot(density(x.bar,width=5),main="sampling distribution of x.bar",type="l",xlim=c(0,100)) # Take samples from a beta population. Plot a histogram of the sampling # distribution of x.bar. beta1 <- 5 beta2 <- 1 par(mfrow=c(2,2)) x <- (1:99)/100 p.beta <- dbeta(x,beta1,beta2) plot(x,p.beta,main="beta density",type="l") x <- matrix(rbeta(3000,50,10),nrow=30) x.bar <- apply(x,2,mean) hist(x.bar,main="sampling distribution of x.bar",xlim=c(0.6,1)) plot(density(x.bar,width=0.2),main="sampling distribution of x.bar",type="l",xlim=c(0,1))