Tutorial: A Module for Linear Regression


SAS/IML Studio Graphics

If you develop your SAS/IML programs in SAS/IML Studio, you can use high-level statistical graphics. For example, the following statements create three scatter plots that duplicate the low-resolution plots created in the previous section. Two of the plots are shown in FigureĀ 4.10. The main steps in the program are indicated by numbered comments; these steps are explained in the list that follows the program.

x = {1 1 1, 1 2 4, 1 3 9, 1 4 16, 1 5 25};        /* 1 */
y = {1, 5, 9, 23, 36};
x1 = x[,2];                   /* data = second column of X */
x = orpol(x1,2);              /* generates orthogonal polynomials */
run Regress;                  /* runs the Regress module */

declare DataObject dobj;                          /* 2 */
dobj = DataObject.Create("Reg",                   /* 3 */
         {"x" "y" "Residuals" "Predicted"},
          x1 || y || resid || yhat);

declare ScatterPlot p1, p2, p3;
p1 = ScatterPlot.Create(dobj, "x", "Residuals");  /* 4 */
p1.SetTitleText("Plot of Residuals", true);

p2 = ScatterPlot.Create(dobj, "x", "Predicted");  /* 5 */
p2.SetTitleText("Plot of Predicted Values", true);

p3 = ScatterPlot.Create(dobj, "x", "y");          /* 6 */
p3.SetTitleText("Scatter Plot with Regression Line", true);
p3.DrawUseDataCoordinates();
p3.DrawLine(x1,yhat);                             /* 7 */

To completely understand this program, you should read SAS/IML Studio for SAS/STAT Users. The following list describes the main steps of the program:

  1. Use SAS/IML to create the data and run the Regress module.

  2. Specify that the dobj variable is an object of the DataObject class. SAS/IML Studio extends the SAS/IML language by adding object-oriented programming techniques.

  3. Create an object of the DataObject class from SAS/IML vectors.

  4. Create a scatter plot of the residuals versus the values of the explanatory variable.

  5. Create a scatter plot of the predicted values versus the values of the explanatory variable.

  6. Create a scatter plot of the observed responses versus the values of the explanatory variable.

  7. Overlay a line for the predicted values.

Figure 4.10: Graphs Created by SAS/IML Studio

Graphs Created by SAS/IML Studio