library(boot) y <- c(33,33,30,34,39,27,32,36,35,42) y N = 400 Brep = 10000 # Bootstrap the sample mean sampmean <- function(y,i) mean(y[i]) bootmean <- boot(data=y,statistic=sampmean,R=Brep) bootmean boot.ci(bootmean,conf=.95) #boot.ci(bootmean,conf=.95,type=c("norm")) #boot.ci(bootmean,conf=.95,type=c("perc")) #boot.ci(bootmean,conf=.95,type=c("basic")) #boot.ci(bootmean,conf=.95,type=c("bca")) 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,R=Brep) boottotal boot.ci(boottotal,conf=.95) #boot.ci(boottotal,conf=.95,type=c("norm")) #boot.ci(boottotal,conf=.95,type=c("perc")) #boot.ci(boottotal,conf=.95,type=c("basic")) #boot.ci(boottotal,conf=.95,type=c("bca")) par(mfrow=c(2,1)) hist(boottotal$t,main="Bootstrap Population Total Estimates") plot(ecdf(boottotal$t),main="Empirical CDF of Bootstrap Total Estimates")