* Example SAS code for conducting bootstrap tests for multiple regression models ; data table871 ; input cs ss wt @@ ; id = _n_ ; bootid = _n_ ; title ' ' ; cards ; 14.5 9.5 140 15.5 9.5 155 15.5 10.5 153 15 10.5 150 16.5 11 180 16.5 8.5 160 15.5 8.5 155 14.5 9.5 145 15 10 163 15 9 150 15 8.5 140 15.5 9.5 170 15.5 11 180 15.5 11 175 15.5 10.5 155 15.5 8.5 150 15.5 10 160 15 9 145 16 12 190 16.5 13 228 15 8.5 150 15 8.5 180 15 11 165 15 9 145 ; *proc print ; proc reg data = table871 outest = origregres tableout ; model wt = cs ss ; output out = datares p = pred r = res ; run ; proc print data = origregres ; run ; * comparing the GLM output to the REG output ; proc glm data = table871 outstat = origregaov ; class ; model wt = cs ss ; run ; proc print data = origregaov ; run ; * checking assumptions ; proc plot data = datares vpercent = 80 ; plot res*pred ; proc capability noprint data = datares lineprinter ; var res ; qqplot res /normal(mu = est sigma = est symbol='.') square ; run ; proc print data = datares (obs = 24) ; title 'Residuals from regression on original data' ; run ; * Now resample e's and place with x's ; %let bootsampsz = 5000 ; * create the bootstrap sample of ids ; data one ; do iter = 1 to &bootsampsz ; do samp = 1 to 24 ; bootid = ceil(24*ranuni(0)) ; output ; end ; end ; *proc print ; run ; proc sort data = datares ; by bootid ; proc sort data = one ; by bootid ; * merge bootstrap ids with the residuals, creating the sample of bootstrap residuals ; data bootres ; merge datares (drop=id) one ; by bootid ; id = samp ; keep id res iter ; run ; proc sort data = bootres ; by iter id ; proc print data = bootres (obs = 24) ; title 'Bootstrap residuals' ; run ; proc sort data = bootres ; by id ; * merge the bootstrap residuals with the covariates to create fixed-X bootstrap samples ; data bootreg ; merge table871 bootres ; by id ; proc sort data = bootreg ; by iter id ; proc print data = bootreg (obs = 24) ; title 'Fixed-X bootstrap samples' ; run ; /* proc reg data = bootreg outest = bootregres tableout outsscp = bootregss ; model res = cs ss ; by iter ; run ; proc print data = bootregres ; run ; proc print data = bootregss ; run ; */ * perform the regression analyses for each bootstrap sample ; proc glm data = bootreg outstat = bootregaov noprint ; class ; model res = cs ss ; by iter ; run ; proc print data = bootregaov (obs = 25) ; title 'Bootstrap analysis results' ; run ; /* Information is collected from the ANOVA analyses to put together the overall F test and the individual variable F tests. */ data bootmse ; set bootregaov ; if _type_ = 'ERROR' ; mse = ss/df ; keep iter mse ; data bootcsss ; set bootregaov ; if _type_ = 'SS1' and _source_ = 'cs' ; csss = ss ; keep iter csss ; data bootssss ; set bootregaov ; if _type_ = 'SS1' and _source_ = 'ss' ; ssss = ss ; keep iter ssss ; data bootfcs ; set bootregaov ; if _type_ = 'SS3' and _source_ = 'cs' ; fcs = f ; keep iter fcs ; data bootfss ; set bootregaov ; if _type_ = 'SS3' and _source_ = 'ss' ; fss = f ; keep iter fss ; proc sort data = bootmse ; by iter ; proc sort data = bootcsss ; by iter ; proc sort data = bootssss ; by iter ; proc sort data = bootfcs ; by iter ; proc sort data = bootfss ; by iter ; data allfinfo ; merge bootmse bootcsss bootssss bootfcs bootfss ; by iter ; foverall = (csss + ssss)/2 /mse ; proc print data = allfinfo (obs = 30) noobs ; var iter fcs fss foverall ; run ; * calculate percentiles of the bootstrap distributions ; proc univariate data = allfinfo noprint ; var fcs fss foverall ; output out = pctiles p90 = fcsp90 fssp90 foverallp90 p95 = fcsp95 fssp95 foverallp95 p99 = fcsp99 fssp99 foverallp99 pctlpts = 97.5 pctlpre = fcs fss foverall pctlname = p97_5 ; run ; proc print data = pctiles ; var fcsp90 fssp90 foverallp90 fcsp95 fssp95 foverallp95 fcsp97_5 fssp97_5 foverallp97_5 fcsp99 fssp99 foverallp99 ; title 'Bootstrap distribution of F values' ; run ; * calculate bootstrap p values ; data bootpvals ; set allfinfo ; rejoverall = (foverall ge 22.96) ; rejcs = (fcs ge 9.61) ; rejss = (fss ge 15.92) ; title 'Bootstrap p values' ; proc means mean ; var rejoverall rejcs rejss ; run ;