d=read.table("http://www.stat.sc.edu/~hansont/stat205/height_2014.txt",header=F) d=c(70,70,72,63,60,60,72,67,65,67,68,62,64,69,65,63,66,69,66,72,64,69,63,73,68 68,68,65,64,65,76,76,66,63,65,66,67,68,67,73,72,71,62,63,69,72,63,60,61,75 72,68,72,64,64,60,72,68,61,71,64,68,69,64,67,65,76,75,68,66,67,65,62,71,67 63,66,66,69,70,62,67,68,67,62,72,62,61,68,69,63,62) h=d[,2]*12+d[,3] # height in inches m=length(h) # population size n=5 # sample size # compute one mean of size n=5 ybar=0 for(j in 1:n){ index=ceiling(runif(1)*m) cat("Student",index,"has height",h[index],"inches. \n") ybar=ybar+h[index]} cat("Mean of all",n,"is ybar =",ybar/n,"inches. \n") # make histogram of 1000 sample ybar's, each n=5 total=1000 mu=mean(h) means=rep(0,total) for(i in 1:total){ ybar=0 for(j in 1:n){ybar=ybar+h[ceiling(runif(1)*m)]} ybar=ybar/n means[i]=ybar } par(mfrow=c(2,1)) hist(h,freq=FALSE,xlim=c(min(h),max(h)),main="Population density") hist(means,freq=FALSE,xlim=c(min(h),max(h)),main="Density of ybar for n=5")