# File "Rboot". B = 1000 # Some data (same as in file "Rjack"). x = c(0.417123602237552, 0.357405868126079, 0.711339075583965, 0.946056608809158, 0.173700894461945, 0.105324893025681, 0.310572318034247, 0.120300267590210, 0.80332009983249, 0.347110137576237) n = length(x) thetahatlist = NULL # Run the bootstrap, with B resamplings of n resamples each. for (b in 1:B) { # Do n bootstrap resamples. resampled = rep(0,n) for (i in 1:n) { j = floor( runif(1,1,n+1) ) # uniform on {1,2,...,n} resampled[i] = x[j] } # Compute thetahat for this resample. thetahat = mean(resampled) thetahatlist = c(thetahatlist, thetahat) } # Compute the bootstrap estimate of mean, thetastar. thetastar = sum(thetahatlist) / B # Compute the bootstrap estimate of variance. sqsum = 0 for (i in 1:B) { sqsum = sqsum + (thetahatlist[i] - thetastar)^2 } varest = sqsum / (B-1) print(varest)