/* An example of using bootstrap sampling to estimate the MSE for several sample statistics (mean, standard deviation, coefficient of variation) */ data table811 ; input y @@ ; obs = _n_ ; bootid = obs ; title ' ' ; cards ; 7 11 15 16 20 22 24 25 29 33 34 37 41 42 49 57 66 71 84 90 ; proc print ; * calculate sample statistics ; proc means n mean stddev cv ; run ; * set the bootstrap sample size ; %let bootsampsz = 500 ; * create the bootstrap sample of ids ; data one ; do iter = 1 to &bootsampsz ; do samp = 1 to 20 ; bootid = ceil(20*ranuni(0)) ; output ; end ; end ; *proc print ; run ; proc sort data = table811 ; by bootid ; proc sort data = one ; by bootid ; * merge bootstrap ids with the data, creating the bootstrap sample ; data both ; merge table811 one ; by bootid ; proc sort data = both ; by iter ; *proc print ; run ; * calculate the sample statistics from each bootstrap sample ; proc means data = both noprint ; var y ; output out = meansout mean = mny stddev = stdy cv = cvy ; by iter ; run ; proc print noobs data = meansout ; var iter mny stdy cvy ; title 'Bootstrap samples' ; run ; proc univariate data= meansout noprint; histogram mny stdy cvy / cfill = blue cframe = ligr; title 'Bootstrap sampling distributions ' ; run; * this output can be used to calculate bootstrap bias and variance ; proc means data = meansout mean var css ; var mny stdy cvy ; run ; * the DATA step and Proc MEANS are used to calculate bootstrap estimate of MSE ; data msecalc ; set meansout ; mseimean = (mny - 38.65)**2/&bootsampsz ; mseistd = (stdy - 24.02)**2/&bootsampsz ; mseicv = (cvy - 62.15)**2/&bootsampsz ; title 'Bootstrap MSE calculations' ; proc means data = msecalc sum ; var mseimean mseistd mseicv ; run ;