# File "Rboot5". 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 bias. biasest = thetastar - max(x) print(biasest) # OR, TO COMPUTE THE BIAS NUMERICALLY: # n=100 # densofmax = function(y) { n * y^(n-1) } # integr = function(y) { y * densofmax(y) } # meanofmax = integrate(integr, 0, 1)$value # bias = meanofmax - 1 # bias