lab3_linreg_diagnostics.doc

advertisement
Things we will done in Lab:
1. Correlation test for normality
2. Modified Levene’s test
3. Breusch Pagan Test
4. Lack of fit test for linear model
5. Durbin Watson Test
6. Box-Cox Transformation
options ls=90 ps=55;
data tree;
input diameter height;
newvar=_n_;
cards;
18.9
20.0
15.5
16.8
19.4
20.2
20.0
20.0
29.8
20.2
19.8
18.0
20.3
17.8
20.0
19.2
22.0
22.3
23.6
18.9
14.8
13.3
22.7
20.6
18.5
19.0
21.5
19.2
14.8
16.1
17.7
19.9
21.0
20.4
15.9
17.6
27.5
21.4
20.3
19.2
22.9
19.8
14.1
18.5
10.1
12.1
5.8
8.0
20.7
17.4
17.8
18.4
11.4
17.3
14.4
16.6
13.4
12.9
17.8
17.5
20.7
19.4
13.3
15.5
22.9
19.2
16.6
18.8
15.5
16.9
13.7
16.3
;
/* plotting the data*/
proc gplot data=tree;
plot height*diameter;
run;
/* regression of y on x with test for non-constant variance*/
proc reg data=tree;
model height=diameter/clm cli dw;
/* getting the residual and predicted values as a different data set*/
output out=new r=resid p=pred;
run;
/* residual analysis*/
proc univariate normaltest plot data=new;
var resid;
run;
/* residual analysis another way*/
proc capability normaltest data=new;
var resid;
histogram;
cdfplot;
qqplot;
run;
/*diagnostic plots for equal equality of variance 1*/
proc gplot data=new;
plot resid*pred;
run;
/*diagnostic plots for equal equality of variance 2*/
data new1;
set new;
sqres=resid*resid;
proc gplot;
plot sqres*pred;
run;
/*Normal probability plot directly*/
proc rank normal=blom data=new out=data2;
ranks residr;
var resid;
proc gplot data=data2;
plot resid*residr;
run;
/* correlation test for normality*/
proc corr ;
var resid residr;
run;
proc sort data=new;
by diameter;
run;
/* for Breusch-pagan test*/
proc model data=tree;
parms b0 b1;
height=b0+b1*diameter;
fit height/white breusch=(1 diameter);
run;
/* modeified levene's test */
data levnew;
set new;
newvar1=_n_;
if newvar1 < 19 then grp =1;
else grp=2;
run;
proc glm data=levnew;
class grp;
model resid=grp;
means grp/hovtest=bf;
run;
/* To find SSPE for lack of fit test, don’t use SSLF just use SSPE*/
proc sort data=tree;
by diameter;
run;
proc rsreg;
model height=diameter/lackfit;
run;
ods graphics on;
proc transreg details data=tree ss2
plots=(transformation(dependent) obp);
model BoxCox(height / convenient lambda=-2 to 2 by 0.05) =
qpoint(diameter);
run;
ods graphics off;
%boxcoxar(tree,height,lambdahi=5,lambdalo=-5,nlambda=55);
run;
Download