# # EPage 140 # # Written by: # -- # John L. Weatherwax 2009-04-21 # # email: wax@alum.mit.edu # # Please send comments and especially bug reports to the # above email address. # #----- library(DAAG) set.seed(0) stdErrorOfMedian = function(n_samples=100,exp_rate=1){ # Generate data from our exponential distribution: X = rexp(n_samples,rate=exp_rate) # The function we will want to compute bootstrap samples of: median.fn = function(data, indices){ median(data[indices]) } # Run the bootstrap: median.boot = boot( X, median.fn, R=99999 ) print( sprintf("rate= %5.2f; standard error of median (bootstrapped) %10.6f", exp_rate, sd( median.boot$t ) ) ) print( sprintf("rate= %5.2f; standard error of median (normal approximation) %10.6f", exp_rate, sqrt( pi / (2*n_samples) ) ) ) } # Run function once: stdErrorOfMedian()