#theta is the sample statistic theta <- function(x) { sum(x)/length(x) } #x is the original sample #lognormal mean=1.65 var=4.67 n <- 100 x <- rlnorm(n) B <- 500 #draw B bootstrap samples bx <- list() for( i in 1:B ) { bx[[i]] <- sample(x, size=n, replace=TRUE) } #compute theta for each bootstrap sample btheta <- sapply(bx, theta) #plot a histogram of btheta hist(btheta) #approximate variance of theta bthetaVar <- var(btheta) #compute an equal-tail 95% CI for theta bthetaCI <- quantile(btheta, probs=c(0.025,0.975))