Creating residual plots in SAS.
Step 1) Load the data: The data are provided below along with SAS scripts to perform steps 2 and 3.
Step 2) Step up the multiple regression in the analyist window:
Open the "analyst" window by clicking solutions/analysis/analyst and retrieve the dataset
by clicking file/open by SAS name/. Open the regression menu by clicking statistics/regression/simple.
Enter DVD as the dependent variable and Box, GenreC, GenreD, GenreF, and GenreR as the explanatory variables.
Step 3) Make the residual plots:
Click "plots" and than hit the "residual" tab. Check the boxes "Plot residuals vs variables",
"stanardized", "Predicted Y", and "independent variables". Then click "OK".
data dvd;
input DVD Box Genre $ Rating $;
sqrtbox = sqrt(Box);
GenreC=0;if Genre="C" then GenreC=1;
GenreD=0;if Genre="D" then GenreD=1;
GenreF=0;if Genre="F" then GenreF=1;
GenreR=0;if Genre="R" then GenreR=1;
datalines;
11.77 57.65 C C
11.64 88.72 R B
10.23 50.82 D B
9.99 48.75 A B
9.9 82.23 C C
9.89 88.51 A B
9.58 48.55 R C
9.47 62.32 A B
9.45 36.9 A B
9.43 70.51 A B
9.35 41.78 A B
9.15 54.1 A B
8.76 12.51 D C
8.47 42.65 D B
8.09 81.61 A B
7.92 35.43 C C
7.71 61.12 F C
7.7 60.06 R B
7.63 47.4 D B
7.56 25.88 A C
7.46 47.86 A C
7.34 12.59 C B
7.28 82.57 F C
7.18 18.5 A C
6.88 33.74 C B
6.42 38.4 C B
6.23 17.13 A C
5.92 63.26 C C
5.8 5.85 D D
5.7 19.4 C B
5.66 70.17 C C
5.54 43 R C
5.33 12.71 D B
5.13 6.86 A B
5.12 14.73 R B
5 23.15 A B
4.94 18.6 F B
4.47 11.3 C B
4.39 21.17 D D
4.38 15.68 C C
4.35 9.02 C B
4.35 10.28 R B
4.34 11.75 A B
4.27 51.39 F B
2.87 4.24 C B
2.83 5.03 A B
2.54 6.09 C C
2.3 1.17 D B
2.28 47.14 F B
2.26 1.5 A B
2.25 4.84 D B
1.92 0.67 R B
1.83 2.08 D B
1.37 7.42 F C
1.34 2.91 F B
1.3 0.44 D C
1.29 11.47 R B
1.23 2.41 A D
1.1 0.11 D C
1.05 3.65 D B
1.03 0.74 R C
0.94 0.35 C C
0.84 1.67 D B
0.76 1.32 C C
0.73 5.13 D B
0.68 2.48 D B
0.63 11.72 C C
0.62 1.25 C B
0.6 1.44 D B
0.58 0.87 F B
0.55 0.67 C C
;;;;
proc reg data=dvd;
model DVD = BOX GenreC GenreD GenreF GenreR;
OUTPUT OUT=dvd_resids residual=resids;
run;
data dvd_resids;
set dvd_resids;
partialresids = resids + 0.09925*box;
run;
title `Plot of residuals vs Box'';
proc gplot data = dvd_resids;
plot resids*Box;
run;
title `Plot of partial residuals vs Box'';
proc gplot data = dvd_resids;
plot partialresids*Box;
run;
proc reg data=dvd;
model DVD = sqrtbox GenreC GenreD GenreF GenreR;
OUTPUT OUT=dvd_resids2 residual=resids;
run;
title `Plot of residuals vs Sqrt(Box)'';
proc gplot data = dvd_resids2;
plot resids*sqrtbox;
run;