******************************
** drug.sas (for lab 5) *****
******************************;
options nodate formdlim='*' pageno=1;
ods graphics on;
ods listing gpath="c:\temp"; * files containing plots produced by ODS graphics will be written
to this folder. Change to someplace else (e.g., your flash
drive) if you prefer;
*ods pdf file="mypath/myfile.pdf"; * uncomment this line and change the path and filename
if you want your output redirected to a pdf file. Be sure
to also uncomment the last line in the program which
closes the pdf file that you are creating;
data drug;
input y batch;
cards;
3.2 1
2.6 2
3.4 3
4.2 4
1.8 5
3.8 1
2.9 2
3.9 3
4.4 4
2.3 5
3.5 1
2.8 2
3.3 3
4.3 4
1.9 5
3.0 1
2.0 2
3.1 3
4.2 4
2.1 5
;
run;
title 'One-way random effects model fit with PROC GLM';
proc glm data=drug;
class batch;
model y=batch;
output out=out1 h=leverage p=pred r=rawres rstudent=exstdres
student=instdres; *This statement outputs leverages, predicted values, raw residuals,
externally studentized residuals and internally studentized resids
to a new data set which I called out1;
means batch /hovtest=bf; *Does modified Levene's test. SAS calls this the Brown-Forsyth test;
run;
title 'One-way random effects model fit with PROC MIXED';
proc mixed data=drug cl ratio; * the cl option asks for confidence intervals (CL for confidence limits) for variance and covariance;
class batch; * parameters. The ratio option asks for the ratio of each var component to the error var.;
model y= ; * no fixed effects other than the constant term (mu);
random batch; * batch effects are random effects, not fixed efffects;
run;
title 'Output data set from PROC GLM with residuals';
proc print data=out1;
run;
goptions reset=all;
title 'Plot of the internally studentized residuals vs fitted values';
proc gplot data=out1;
plot instdres*pred;
run;quit;
title 'Q-Q plot and normality tests for internally Studentized residuals';
proc univariate data=out1 normaltest;
var instdres;
qqplot instdres /normal(mu=est sigma=est) square; *The options here ask
for 1) a straight line to be added to the plot that corresponds to what would be
expected if the data followed a normal distribution perfectly, and 2) a square
plotting region;
run;
quit;
ods pdf close;