library(boot) y <- c(25,30,18,28,23,30,26,35,34,33,38,27,30,44,33,36,41,53,47,46) stratum <- c(rep(1,5), rep(2,5), rep(3,5), rep(4,5)) Brep = 20000 N=400 # Bootstrap the sample mean from a stratified SRS sampmean <- function(y,i) mean(y[i]) bootmean <- boot(data=y,statistic=sampmean,strata=stratum,R=Brep) bootmean boot.ci(bootmean,conf=.95) par(mfrow=c(2,1)) hist(bootmean$t,main="Bootstrap Sample Means") plot(ecdf(bootmean$t),main="Empirical CDF of Bootstrap Means") # Bootstrap the estimates of the population total samptotal <- function(y,i) N*mean(y[i]) boottotal <- boot(data=y,statistic=samptotal,strata=stratum,R=Brep) boottotal boot.ci(boottotal,conf=.95) par(mfrow=c(2,1)) hist(boottotal$t,main="Bootstrap Population Total Estimates") plot(ecdf(boottotal$t),main="Empirical CDF of Bootstrap Total Estimates")