/* Bootstrap confidence intervals from a location-scale family using the t-pivot and chi-squared-pivot methods */ 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 noobs ; * calculate sample statistics ; proc means n mean stddev ; run ; * set the bootstrap sample size ; %let bootsampsz = 2000 ; * 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 ; by iter ; run ; * calculate bootstrap pivotal quantities ; data pivotcalc ; set meansout ; vary = stdy**2 ; tpivot = sqrt(20)*(mny - 38.65)/stdy ; chisqpivot = (19)*vary/576 ; * calculate percentiles of the bootstrap distributions ; proc univariate data = pivotcalc noprint ; var tpivot chisqpivot ; output out = pivotpctiles p5 = tp5 chisqp5 p95 = tp95 chisqp95 pctlpts = 2.5 97.5 pctlpre = t chisq pctlname = p2_5 p97_5 ; run ; proc print data = pivotpctiles ; var tp2_5 tp5 tp95 tp97_5 chisqp2_5 chisqp5 chisqp95 chisqp97_5 ; run ; proc univariate data= pivotcalc noprint; histogram tpivot chisqpivot / cfill = blue cframe = ligr; title 'Bootstrap pivot sampling distributions ' ; run; * Calculate confidence intervals for mu, sigma**2, and sigma ; data cicalc ; set pivotpctiles ; lower95cimu = 38.65 - tp97_5*(24/sqrt(20)) ; upper95cimu = 38.65 - tp2_5*(24/sqrt(20)) ; lower95cisig2 = (19)*576/chisqp97_5 ; upper95cisig2 = (19)*576/chisqp2_5 ; lower95cisig = sqrt((19)*576/chisqp97_5) ; upper95cisig = sqrt((19)*576/chisqp2_5) ; proc print data = cicalc ; var lower95cimu upper95cimu lower95cisig2 upper95cisig2 lower95cisig upper95cisig ; run ;