# File "Rboot4". B = 1000 n = 100 # Generate some data. x = runif(n) 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 = max(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)