hist(age,50) N mu = mean(age) v = var(age) std = sqrt(v) m v std x = sample(age,25) x mean(x) nsamp = 1000 n=100 xbar = rep(0,nsamp) for (i in 1:nsamp){ xbar[i] = mean(sample(age,n)) } mean(xbar) mean(age) sd(xbar) sd(age)/sqrt(n) p = mean(sex) sdp = sqrt(p*(1-p)) phat = rep(0,nsamp) for (i in 1:nsamp){ phat[i] = mean(sample(sex,n)) } hist(phat) mean(phat) sd(phat) sdp/sqrt(n) #normal approx hist(xbar, 20, prob=T) z = seq(35,60, length=100) f = dnorm(z, mean(age), sd(age)/sqrt(n)) lines(z,f) hist(numpers) xbars = replicate(1000,mean(sample(numpers,100))) mean(numpers) mean(xbars) sd(numpers) sd(xbars) hist(xbars, 20, prob=T) z = seq(2.25,3.05,length.out=100) f = dnorm(z,mean(xbars),sd(xbars)) lines(z,f)