Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
The REG Procedure

Line Printer Scatter Plot Features

This section discusses the special options available with line printer scatter plots. Detailed examples of high resolution graphics plots and options are given in the "55.6" section.

Producing Scatter Plots

The interactive PLOT statement available in PROC REG enables you to look at scatter plots of data and diagnostic statistics. These plots can help you to evaluate the model and detect outliers in your data. Several options enable you to place multiple plots on a single page, superimpose plots, and collect plots to be overlaid by later plots. The PAINT statement can be used to highlight points on a plot. See the section "Painting Scatter Plots" for more information on painting.

The Class data set introduced in "Simple Linear Regression" is used in the following examples.

You can superimpose several plots with the OVERLAY option. With the following statements, a plot of Weight against Height is overlaid with plots of the predicted values and the 95% prediction intervals. The model on which the statistics are based is the full model including Height and Age. These statements produce Output 55.31:

   proc reg data=Class lineprinter;
      model Weight=Height Age / noprint;
      plot (ucl. lcl. p.)*Height='-' Weight*Height
           / overlay symbol='o';
   run;

 
The REG Procedure
Model: MODEL1
Dependent Variable: Weight

      ---+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+----
U U95 |                                                                        |
p     |                                                                        |
p 175 +                                                                        +
e     |                                                                        |
r     |                                                                    -   |
      |                                                                        |
B     |                                                                        |
o 150 +                                                           -        o   +
u     |                                                    --                  |
n     |                                                                    -   |
d     |                                             -- -    o                  |
      |                                        -  -  o                         |
o 125 +                                        -                  -            +
f     |                                                     -                  |
      |                               -        o           -      o            |
9     |                             -               -  -   o               -   |
5     |                     -- --              ?  ?  -                         |
% 100 +                             o          -       o          -            +
      |                                                     -                  |
C     |                               -             o      -                   |
.     |      -               o oo   - o        o    -  -                       |
I     |                      - --                 -  -                         |
.  75 +                     ?                  -                               +
(     |                                                                        |
I     |                               -                                        |
n     |                             -                                          |
d     |      -                 --                                              |
i  50 +      o              --                                                 +
v     |                                                                        |
i     |                                                                        |
d     |                                                                        |
u     |      -                                                                 |
a  25 +                                                                        +
l     |                                                                        |
      ---+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+----
P       50    52    54    56    58    60    62    64    66    68    70    72    
r                                                                               
                                        Height                                  
Figure 55.32: Scatter Plot Showing Data, Predicted Values, and Confidence Limits

In this plot, the data values are marked with the symbol 'o' and the predicted values and prediction interval limits are labeled with the symbol '-'. The plot is scaled to accommodate the points from all plots. This is an important difference from the COLLECT option, which does not rescale plots after the first plot or plots are collected. You could separate the overlaid plots by using the following statements:

   plot;
   run;

This places each of the four plots on a separate page, while the statements

   plot / overlay;
   run;
repeat the previous overlaid plot. In general, the statement

   plot;
is equivalent to respecifying the most recent PLOT statement without any options. However, the COLLECT, HPLOTS=, SYMBOL=, and VPLOTS= options apply across PLOT statements and remain in effect.

The next example shows how you can overlay plots of statistics before and after a change in the model. For the full model involving Height and Age, the ordinary residuals and the studentized residuals are plotted against the predicted values. The COLLECT option causes these plots to be collected or retained for re-display later. The option HPLOTS=2 allows the two plots to appear side by side on one page. The symbol 'f' is used on these plots to identify them as resulting from the full model. These statements produce Figure 55.32:

   plot r.*p. student.*p. / collect hplots=2 symbol='f';
   run;

 
The REG Procedure
Model: MODEL1

      -+-----+-----+-----+-----+-----+-      -+-----+-----+-----+-----+-----+-- 
      |                               |      |                                | 
   30 +                               +    3 +                                + 
      |                               |      |                                | 
      |                               |      |                                | 
      |                               |      |                                | 
      |                               |      |                                | 
      |                               |      |                                | 
      |                    f          |      |                    f           | 
   20 +                               +    2 +                                + 
      |                               |      |                                | 
      |                               |      |                                | 
      |                               |      |                                | 
      |                        f      |      |                                | 
      |              f                |      |                        f       | 
R     |                             f |      |              f              f  | 
E  10 +                   f           + S  1 +                   f            + 
S     |                               | T    |                                | 
I     |                               | U    |                                | 
D     |            f                  | D    |            f                   | 
U     |                               | E    |                                | 
A     |            f                  | N    |            f                   | 
L     |                               | T    |                                | 
    0 +           f       f           +    0 +           f       f            + 
      |                               |      |                                | 
      |                    f          |      |                    f           | 
      |               f               |      |               f       f        | 
      |                       f       |      |                                | 
      |     f                         |      |     f                          | 
      |                               |      |                                | 
  -10 +                               +   -1 +                                + 
      |                               |      |                     f   f      | 
      |                     f   f     |      |                                | 
      |                               |      |                  f             | 
      |                  f            |      |                    f           | 
      |                               |      |                                | 
      |                    f          |      |                                | 
  -20 +                               +   -2 +                                + 
      -+-----+-----+-----+-----+-----+-      -+-----+-----+-----+-----+-----+-- 
      40    60    80    100   120  140       40    60    80    100   120   140  
                                                                                
                    PRED                                    PRED                
Figure 55.33: Collecting Residual Plots for the Full Model

Note that these plots are not overlaid. The COLLECT option does not overlay the plots in one PLOT statement but retains them so that they can be overlaid by later plots. When the COLLECT option appears in a PLOT statement, the plots in that statement become the first plots in the collection.

Next, the model is reduced by deleting the Age variable. The PLOT statement requests the same plots as before but labels the points with the symbol 'r' denoting the reduced model. The following statements produce Figure 55.33:

   delete Age;
   plot r.*p. student.*p. / symbol='r';
   run;

 
The REG Procedure
Model: MODEL1.1

      -+-----+-----+-----+-----+-----+-      -+-----+-----+-----+-----+-----+-- 
      |                               |      |                                | 
   30 +                               +    3 +                                + 
      |                               |      |                                | 
      |                               |      |                                | 
      |                               |      |                                | 
      |                               |      |                                | 
      |                               |      |                                | 
      |                    f          |      |                    f           | 
   20 +                               +    2 +                                + 
      |                     r         |      |                                | 
      |                               |      |                     r          | 
      |                               |      |                                | 
      |                       rf      |      |                       r        | 
      |              ?              r |      |                        f    r  | 
R     |                  r          f |      |              ?   r          f  | 
E  10 +                   f           + S  1 +                   f            + 
S     |                               | T    |                                | 
I     |           r                   | U    |                                | 
D     |            f                  | D    |           rf                   | 
U     |            r                  | E    |            r                   | 
A     |            ?                  | N    |            ?                   | 
L     |                               | T    |                                | 
    0 +           ?       ?           +    0 +           ?       ?            + 
      |                   r           |      |                   r            | 
      |                    f          |      |                    f           | 
      |               f       r       |      |               f       ?        | 
      |               r       f       |      |               r                | 
      |     ?                         |      |     ?                          | 
      |                               |      |                                | 
  -10 +                               +   -1 +                                + 
      |                               |      |                     f   f      | 
      |                     f   fr    |      |                     r    r     | 
      |                     r         |      |                  f             | 
      |                  f            |      |                  r ?           | 
      |                  r r          |      |                                | 
      |                    f          |      |                                | 
  -20 +                               +   -2 +                                + 
      -+-----+-----+-----+-----+-----+-      -+-----+-----+-----+-----+-----+-- 
      40    60    80    100   120  140       40    60    80    100   120   140  
                                                                                
                    PRED                                    PRED                
Figure 55.34: Overlaid Residual Plots for Full and Reduced Models

Notice that the COLLECT option causes the corresponding plots to be overlaid. Also notice that the DELETE statement causes the model label to be changed from MODEL1 to MODEL1.1. The points labeled 'f' are from the full model, and points labeled 'r' are from the reduced model. Positions labeled '?' contain at least one point from each model. In this example, the OVERLAY option cannot be used because all of the plots to be overlaid cannot be specified in one PLOT statement. With the COLLECT option, any changes to the model or the data used to fit the model do not affect plots collected before the changes. Collected plots are always reproduced exactly as they first appear. (Similarly, a PAINT statement does not affect plots collected before the PAINT statement is issued.)

The previous example overlays the residual plots for two different models. You may prefer to see them side by side on the same page. This can also be done with the COLLECT option by using a blank plot. Continuing from the last example, the COLLECT, HPLOTS=2, and SYMBOL='r' options are still in effect. In the following PLOT statement, the CLEAR option deletes the collected plots and allows the specified plot to begin a new collection. The plot created is the residual plot for the reduced model. These statements produce Figure 55.34:

   plot r.*p. / clear;
   run;

 
The REG Procedure
Model: MODEL1.1

      -+-----+-----+-----+-----+-----+-                                         
      |                               |                                         
      |                               |                                         
      |                               |                                         
      |                               |                                         
   20 +                               +                                         
      |                     r         |                                         
      |                               |                                         
      |                               |                                         
      |                       r       |                                         
      |              r              r |                                         
      |                  r            |                                         
   10 +                               +                                         
      |                               |                                         
      |           r                   |                                         
R     |                               |                                         
E     |            r                  |                                         
S     |            r                  |                                         
I     |                               |                                         
D   0 +           r       r           +                                         
U     |                   r           |                                         
A     |                               |                                         
L     |                       r       |                                         
      |               r               |                                         
      |     r                         |                                         
      |                               |                                         
  -10 +                               +                                         
      |                               |                                         
      |                          r    |                                         
      |                     r         |                                         
      |                               |                                         
      |                  r r          |                                         
      |                               |                                         
  -20 +                               +                                         
      |                               |                                         
      |                               |                                         
      |                               |                                         
      |                               |                                         
      -+-----+-----+-----+-----+-----+-                                         
      40    60    80    100   120  140                                          
                                                                                
                    PRED                                                        
Figure 55.35: Residual Plot for Reduced Model Only

The next statements add the variable AGE to the model and place the residual plot for the full model next to the plot for the reduced model. Notice that a blank plot is created in the first plot request by placing nothing between the quotes. Since the COLLECT option is in effect, this plot is superimposed on the residual plot for the reduced model. The residual plot for the full model is created by the second request. The result is the desired side-by-side plots. The NOCOLLECT option turns off the collection process after the specified plots are added and displayed. Any PLOT statements that follow show only the newly specified plots. These statements produce Figure 55.35:

   add Age;
   plot r.*p.='' r.*p.='f' / nocollect;
   run;

 
The REG Procedure
Model: MODEL1.2

      -+-----+-----+-----+-----+-----+-       -+-----+-----+-----+-----+-----+- 
      |                               |       |                               | 
      |                               |    30 +                               + 
      |                               |       |                               | 
      |                               |       |                               | 
   20 +                               +       |                               | 
      |                     r         |       |                               | 
      |                               |       |                               | 
      |                               |       |                    f          | 
      |                       r       |    20 +                               + 
      |              r              r |       |                               | 
      |                  r            |       |                               | 
   10 +                               +       |                               | 
      |                               |       |                        f      | 
      |           r                   |       |              f                | 
R     |                               | R     |                             f | 
E     |            r                  | E  10 +                   f           + 
S     |            r                  | S     |                               | 
I     |                               | I     |                               | 
D   0 +           r       r           + D     |            f                  | 
U     |                   r           | U     |                               | 
A     |                               | A     |            f                  | 
L     |                       r       | L     |                               | 
      |               r               |     0 +           f       f           + 
      |     r                         |       |                               | 
      |                               |       |                    f          | 
  -10 +                               +       |               f               | 
      |                               |       |                       f       | 
      |                          r    |       |     f                         | 
      |                     r         |       |                               | 
      |                               |   -10 +                               + 
      |                  r r          |       |                               | 
      |                               |       |                     f   f     | 
  -20 +                               +       |                               | 
      |                               |       |                  f            | 
      |                               |       |                               | 
      |                               |       |                    f          | 
      |                               |   -20 +                               + 
      -+-----+-----+-----+-----+-----+-       -+-----+-----+-----+-----+-----+- 
      40    60    80    100   120  140        40    60    80    100   120  140  
                                                                                
                    PRED                                    PRED                
Figure 55.36: Side-by-Side Residual Plots for the Full and Reduced Models

Frequently, when the COLLECT option is in effect, you want the current and following PLOT statements to show only the specified plots. To do this, use both the CLEAR and NOCOLLECT options in the current PLOT statement.

Painting Scatter Plots

Painting scatter plots is a useful interactive tool that enables you to mark points of interest in scatter plots. Painting can be used to identify extreme points in scatter plots or to reveal the relationship between two scatter plots. The CLASS data (from the "Simple Linear Regression" section) is used to illustrate some of these applications. First, a scatter plot of the studentized residuals against the predicted values is generated. This plot is shown in Figure 55.36.

   proc reg data=Class lineprinter;
      model Weight=Age Height / noprint;
      plot student.*p.;
   run;

 
The REG Procedure
Model: MODEL1
Dependent Variable: Weight

          ---+------+------+------+------+------+------+------+------+------+---
  STUDENT |                                                                    |
          |                                                                    |
        3 +                                                                    +
          |                                                                    |
          |                                                                    |
          |                                                                    |
          |                                                                    |
S         |                                          1                         |
t       2 +                                                                    +
u         |                                                                    |
d         |                                                                    |
e         |                                                                    |
n         |                                                  1                 |
t         |                           1                                    1   |
i       1 +                                       1                            +
z         |                                                                    |
e         |                                                                    |
d         |                      11                                            |
          |                       1                                            |
R         |                                                                    |
e       0 +                     1                 1                            +
s         |                                         1                          |
i         |                                                                    |
d         |                             1                   2                  |
u         |       1                                                            |
a         |                                                                    |
l      -1 +                                                                    +
          |                                            1         1             |
          |                                                                    |
          |                                     1                              |
          |                                           1                        |
          |                                                                    |
       -2 +                                                                    +
          |                                                                    |
          ---+------+------+------+------+------+------+------+------+------+---
            50     60     70     80     90     100    110    120    130    140  
                                                                                
                           Predicted Value of Weight      PRED                  
Figure 55.37: Plotting Studentized Residuals Against Predicted Values

Then, the following statements identify the observation 'Henry' in the scatter plot and produce Figure 55.37:

   paint Name='Henry' / symbol = 'H';
   plot;
   run;

 
The REG Procedure
Model: MODEL1
Dependent Variable: Weight

          ---+------+------+------+------+------+------+------+------+------+---
  STUDENT |                                                                    |
          |                                                                    |
        3 +                                                                    +
          |                                                                    |
          |                                                                    |
          |                                                                    |
          |                                                                    |
S         |                                          1                         |
t       2 +                                                                    +
u         |                                                                    |
d         |                                                                    |
e         |                                                                    |
n         |                                                  1                 |
t         |                           1                                    1   |
i       1 +                                       1                            +
z         |                                                                    |
e         |                                                                    |
d         |                      11                                            |
          |                       1                                            |
R         |                                                                    |
e       0 +                     1                 1                            +
s         |                                         H                          |
i         |                                                                    |
d         |                             1                   2                  |
u         |       1                                                            |
a         |                                                                    |
l      -1 +                                                                    +
          |                                            1         1             |
          |                                                                    |
          |                                     1                              |
          |                                           1                        |
          |                                                                    |
       -2 +                                                                    +
          |                                                                    |
          ---+------+------+------+------+------+------+------+------+------+---
            50     60     70     80     90     100    110    120    130    140  
                                                                                
                           Predicted Value of Weight      PRED                  
Figure 55.38: Painting One Observation

Next, the following statements identify observations with large absolute residuals:

   paint student.>=2 or student.<=-2 / symbol='s';
   plot;
   run;
The log shows the observation numbers found with these conditions and gives the painting symbol and the number of observations found. Note that the previous PAINT statement is also used in the PLOT statement. Figure 55.38 shows the scatter plot produced by the preceding statements.

 
The REG Procedure
Model: MODEL1
Dependent Variable: Weight

          ---+------+------+------+------+------+------+------+------+------+---
  STUDENT |                                                                    |
          |                                                                    |
        3 +                                                                    +
          |                                                                    |
          |                                                                    |
          |                                                                    |
          |                                                                    |
S         |                                          s                         |
t       2 +                                                                    +
u         |                                                                    |
d         |                                                                    |
e         |                                                                    |
n         |                                                  1                 |
t         |                           1                                    1   |
i       1 +                                       1                            +
z         |                                                                    |
e         |                                                                    |
d         |                      11                                            |
          |                       1                                            |
R         |                                                                    |
e       0 +                     1                 1                            +
s         |                                         H                          |
i         |                                                                    |
d         |                             1                   2                  |
u         |       1                                                            |
a         |                                                                    |
l      -1 +                                                                    +
          |                                            1         1             |
          |                                                                    |
          |                                     1                              |
          |                                           1                        |
          |                                                                    |
       -2 +                                                                    +
          |                                                                    |
          ---+------+------+------+------+------+------+------+------+------+---
            50     60     70     80     90     100    110    120    130    140  
                                                                                
                           Predicted Value of Weight      PRED                  
Figure 55.39: Painting Several Observations

The following statements relate two different scatter plots. These statements produce Figure 55.39.

   paint student.>=1 / symbol='p';
   paint student.<1 and student.>-1 / symbol='s';
   paint student.<=-1 / symbol='n';
   plot student. * p. cookd. * h. / hplots=2;
   run;

 
The REG Procedure
Model: MODEL1

     -+-----+-----+-----+-----+-----+--       -+----+----+----+----+----+----+- 
     |                                |       |                               | 
   3 +                                +       |                               | 
     |                                |       |                               | 
     |                                |       |                               | 
     |                                |   0.8 +                            p  + 
     |                                |       |                               | 
     |                                |       |                               | 
     |                    p           |       |                               | 
   2 +                                +       |                               | 
     |                                |       |                               | 
     |                                |       |                               | 
     |                                |   0.6 +                               + 
     |                                |       |                               | 
     |                        p       |       |                               | 
     |              p              p  |       |                               | 
S  1 +                   s            +       |                               | 
T    |                                | C     |                               | 
U    |                                | O     |                               | 
D    |            s                   | O 0.4 +                               + 
E    |                                | K     |                               | 
N    |            s                   | D     |                               | 
T    |                                |       |                               | 
   0 +           s       s            +       |                               | 
     |                                |       |                               | 
     |                    s           |       |                               | 
     |               s       s        |   0.2 +                               + 
     |                                |       |                     p         | 
     |     s                          |       |                               | 
     |                                |       |               n    s          | 
  -1 +                                +       |       p  n                s   | 
     |                     n   n      |       | n   p                         | 
     |                                |       |               ss              | 
     |                  n             |   0.0 +  ss ss s                      + 
     |                    n           |       |                               | 
     |                                |       |                               | 
     |                                |       |                               | 
  -2 +                                +       |                               | 
     -+-----+-----+-----+-----+-----+--       -+----+----+----+----+----+----+- 
     40    60    80    100   120   140      0.05 0.10 0.15 0.20 0.25 0.30 0.35  
                                                                                
                    PRED                                      H                 
Figure 55.40: Painting Observations on More than One Plot

Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
Top
Top

Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.