Created
September 29, 2021 18:38
-
-
Save MJacobs1985/df4b4a2e0bdf24ee9cb4bc06254a9fba to your computer and use it in GitHub Desktop.
Simulations in SAS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Significant effects where there are none */ | |
%let ErrorVariance=1000; | |
%let nrep=10; | |
%let nsim=100; | |
DATA CRD; | |
call streaminit(123); | |
do isim = 1 to ≁ | |
do rep=1 to &nrep; | |
do trt=1 to 5; | |
if trt=1 then y=791.5 + rand('Normal', 0, sqrt(&ErrorVariance)); | |
if trt=2 then y=791.5 + rand('Normal', 0, sqrt(&ErrorVariance)); | |
if trt=3 then y=791.5 + rand('Normal', 0, sqrt(&ErrorVariance)); | |
if trt=4 then y=791.5 + rand('Normal', 0, sqrt(&ErrorVariance)); | |
if trt=5 then y=791.5 + rand('Normal', 0, sqrt(&ErrorVariance)); | |
output; | |
end; | |
end; | |
end; | |
/* Show how due to randomness, treatment differences may seem to be present if though they are not */ | |
proc sgpanel data=CRD noautolegend; | |
where isim<11; | |
panelby isim / columns=5 novarname skipemptycells; | |
vbox y / category=trt group=trt; | |
refline 791.5 / axis=y lineattrs=(color=black pattern=2); | |
title 'Boxplot of BW by Treatment'; | |
title2 italic ' No treatment differences in population'; | |
run; | |
/* show how many differences are significant --> should be around 5% */ | |
proc mixed data=CRD; | |
by isim; | |
class trt; | |
model y = trt / s cl ddfm=kenwardroger ; | |
lsmeans trt / pdiff=all adjdfe=row adjust=tukey cl; | |
ods output diffs=differences lsmeans=mixmeans; | |
run; | |
data differences; | |
set differences; | |
Comparison=catx(' vs ',trt,_trt); | |
if probt<0.05 then Sign='Yes'; else Sign='No'; | |
run; | |
ods graphics / height=10in width=10in; | |
proc sgpanel data=differences noautolegend; | |
styleattrs datacontrastcolors=(red green); | |
panelby comparison / rows=2 columns=5 novarname skipemptycells; | |
scatter x=estimate y=isim / xerrorlower=lower xerrorupper=upper group=Sign groupdisplay=cluster; | |
refline 0 / axis=x lineattrs=(color=black) label='No Difference' labelpos=min; | |
rowaxis label='Simulation'; | |
colaxis label='Estimate of treatment difference'; | |
title 'We live in a random world'; | |
title2 italic 'Significant effects where there are none'; | |
run; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment