# # 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. # #----- median_smoothed_bootstrap = function(data, B=100, h=1){ # # Code derived from pseudocode on Page 90 from Good's book. # # h is a kernel smoothing parameter. # # This is my best estimate of what that code should be given that # it seems like there are typos in the books discussion of this algorithm. # n = length(data) # the number of data points in the original sample boot_medians = rep( NA, B ) for( bi in 1:B ){ xb = sample( data, length(data), replace=TRUE ) xb_mean = mean( xb ) xb_std = sd( xb ) boot_sample = xb_mean + ( xb - xb_mean + h * rnorm(n) ) / sqrt( 1 + (h / xb_std)^2 ) boot_medians[bi] = median( boot_sample ) } return( boot_medians ) }