The REG Procedure

Polynomial Regression

Consider a response variable Y that can be predicted by a polynomial function of a regressor variable X. You can estimate , the intercept; , the slope due to X; and , the slope due to , in

for the observations .

Consider the following example on population growth trends. The population of the United States from 1790 to 2000 is fit to linear and quadratic functions of time. Note that the quadratic term, YearSq, is created in the DATA step; this is done since polynomial effects such as Year*Year cannot be specified in the MODEL statement in PROC REG. The data are as follows:

data USPopulation;
   input Population @@;
   retain Year 1780;
   Year       = Year+10;
   YearSq     = Year*Year;
   Population = Population/1000;
   datalines;
3929 5308 7239 9638 12866 17069 23191 31443 39818 50155
62947 75994 91972 105710 122775 131669 151325 179323 203211
226542 248710 281422
;
proc reg data=USPopulation plots=ResidualByPredicted;
   var YearSq;
   model Population=Year / r clm cli;
run;

The DATA option ensures that the procedure uses the intended data set. Any variable that you might add to the model but that is not included in the first MODEL statement must appear in the VAR statement.

The "Analysis of Variance" and "Parameter Estimates" tables are displayed in Figure 99.5.

Figure 99.5: ANOVA Table and Parameter Estimates

The REG Procedure
Model: MODEL1
Dependent Variable: Population

Analysis of Variance
SourceDFSum of
Squares
Mean
Square
F ValuePr > F
Model1146869146869228.92<.0001
Error2012832641.58160  
Corrected Total21159700   

Root MSE25.32946R-Square0.9197
Dependent Mean94.64800Adj R-Sq0.9156
Coeff Var26.76175  

Parameter Estimates
VariableDFParameter
Estimate
Standard
Error
t ValuePr > |t|
Intercept1-2345.85498161.39279-14.54<.0001
Year11.287860.0851215.13<.0001


The Model F statistic is significant (F = 228.92, p < 0.0001), indicating that the model accounts for a significant portion of variation in the data. The R-square indicates that the model accounts for 92% of the variation in population growth. The fitted equation for this model is

In the MODEL statement, three options are specified: R requests a residual analysis to be performed, CLI requests 95% confidence limits for an individual value, and CLM requests these limits for the expected value of the dependent variable. You can request specific % limits with the ALPHA= option in the PROC REG or MODEL statement.

Figure 99.6 shows the "Output Statistics" table. The residual, its standard error, the studentized residual, and Cook’s D are displayed for each observation. The studentized residual is the residual divided by its standard error. Cook’s D is a measure of the change in the predicted values upon deletion of that observation from the data set; hence, it measures the influence of the observation on the estimated regression coefficients. The studentized residuals and Cook’s D statistics are displayed in Figure 99.7.

Studentized residuals follow a beta distribution and can be used to identify outlying or extreme observations:

  • Having a few large absolute studentized residuals is no cause for alarm.

  • Many observations having absolute studentized residuals greater than two might indicate an inadequate model.

  • Absolute studentized residuals greater than three are rarer; they should be regarded as extreme, and the data should be reviewed carefully.

Figure 99.6: Output Statistics

The REG Procedure
Model: MODEL1
Dependent Variable: Population

Output Statistics
ObsDependent
Variable
Predicted
Value
Std
Error
Mean
Predict
95% CL Mean95% CL PredictResidualStd Error
Residual
Student
Residual
Cook's D
13.93-40.577810.4424-62.3602-18.7953-97.728016.572544.506823.0771.9290.381
25.31-27.69919.7238-47.9826-7.4156-84.295028.896833.007123.3891.4110.172
37.24-14.82059.0283-33.65334.0123-70.912841.271922.059523.6660.9320.063
49.64-1.94188.3617-19.384115.5004-57.582753.699111.579823.9090.4840.014
512.8710.93687.7314-5.190627.0643-44.306066.17971.929224.1210.0800.000
617.0723.81557.14708.907038.7239-31.083978.7148-6.746524.300-0.2780.003
723.1936.69416.620822.883450.5048-17.917491.3056-13.503124.449-0.5520.011
831.4449.57276.167536.707562.4380-4.8073103.9528-18.129724.567-0.7380.017
939.8262.45145.804450.343674.55928.2455116.6573-22.633424.655-0.9180.023
1050.1675.33005.549163.754786.905321.2406129.4195-25.175024.714-1.0190.026
1162.9588.20875.417076.909099.508434.1776142.2398-25.261724.743-1.0210.025
1275.99101.08735.417089.7876112.387047.0562155.1184-25.093324.743-1.0140.025
1391.97113.96605.5491102.3907125.541359.8765168.0554-21.994024.714-0.8900.020
14105.71126.84465.8044114.7368138.952472.6387181.0505-21.134624.655-0.8570.020
15122.78139.72336.1675126.8580152.588585.3432194.1033-16.948324.567-0.6900.015
16131.67152.60196.6208138.7912166.412697.9904207.2134-20.932924.449-0.8560.027
17151.33165.48057.1470150.5721180.3890110.5812220.3799-14.155524.300-0.5830.015
18179.32178.35927.7314162.2317194.4866123.1163233.60200.963824.1210.0400.000
19203.21191.23788.3617173.7956208.6801135.5969246.878711.973223.9090.5010.015
20226.54204.11659.0283185.2837222.9493148.0241260.208822.425523.6660.9480.065
21248.71216.99519.7238196.7116237.2786160.3992273.591031.714923.3891.3560.159
22281.42229.873810.4424208.0913251.6562172.7235287.024051.548223.0772.2340.511


Figure 99.7: Studentized Residuals

Studentized Residuals


Figure 99.8 shows the residual statistics table. A fairly close agreement between the PRESS statistic (see Table 99.7) and the sum of squared residuals indicates that the MSE is a reasonable measure of the predictive accuracy of the fitted model (Neter, Wasserman, and Kutner 1990).

Figure 99.8: Residual Statistics

Sum of Residuals0
Sum of Squared Residuals12832
Predicted Residual SS (PRESS)16662


Graphical representations are very helpful in interpreting the information in the "Output Statistics" table. When ODS Graphics is enabled, the REG procedure produces a default set of diagnostic plots that are appropriate for the requested analysis.

Figure 99.9 displays a panel of diagnostics plots. These diagnostics indicate an inadequate model:

  • The plots of residual and studentized residual versus predicted value show a clear quadratic pattern.

  • The plot of studentized residual versus leverage seems to indicate that there are two outlying data points. However, the plot of Cook’s D distance versus observation number reveals that these two points are just the data points for the endpoint years 1790 and 2000. These points show up as apparent outliers because the departure of the linear model from the underlying quadratic behavior in the data shows up most strongly at these endpoints.

  • The normal quantile plot of the residuals and the residual histogram are not consistent with the assumption of Gaussian errors. This occurs as the residuals themselves still contain the quadratic behavior that is not captured by the linear model.

  • The plot of the dependent variable versus the predicted value exhibits a quadratic form around the 45-degree line that represents a perfect fit.

  • The "Residual-Fit" (or RF) plot consisting of side-by-side quantile plots of the centered fit and the residuals shows that the spread in the residuals is no greater than the spread in the centered fit. For inappropriate models, the spread of the residuals in such a plot is often greater than the spread of the centered fit. In this case, the RF plot shows that the linear model does indeed capture the increasing trend in the data, and hence accounts for much of the variation in the response.

Figure 99.9: Diagnostics Panel

Diagnostics Panel


Figure 99.10 shows a plot of residuals versus Year. Again you can see the quadratic pattern that strongly indicates that a quadratic term should be added to the model.

Figure 99.10: Residual Plot

Residual Plot


Figure 99.11 shows the FitPlot consisting of a scatter plot of the data overlaid with the regression line, and 95% confidence and prediction limits. Note that this plot also indicates that the model fails to capture the quadratic nature of the data. This plot is produced for models containing a single regressor. You can use the ALPHA= option in the model statement to change the significance level of the confidence band and prediction limits.

Figure 99.11: Fit Plot

Fit Plot


These default plots provide strong evidence that the Yearsq needs to be added to the model. You can use the interactive feature of PROC REG to do this by specifying the following statements:

   add YearSq;
   print;
run;

The ADD statement requests that YearSq be added to the model, and the PRINT command causes the model to be refit and displays the ANOVA and parameter estimates for the new model. The print statement also produces updated ODS graphical displays.

Figure 99.12 displays the ANOVA table and parameter estimates for the new model.

Figure 99.12: ANOVA Table and Parameter Estimates

Analysis of Variance
SourceDFSum of
Squares
Mean
Square
F ValuePr > F
Model2159529797658864.19<.0001
Error19170.971938.99852  
Corrected Total21159700   

Root MSE2.99975R-Square0.9989
Dependent Mean94.64800Adj R-Sq0.9988
Coeff Var3.16938  

Parameter Estimates
VariableDFParameter
Estimate
Standard
Error
t ValuePr > |t|
Intercept121631639.5018133.82<.0001
Year1-24.045810.67547-35.60<.0001
YearSq10.006680.0001782037.51<.0001


The overall F statistic is still significant (F = 8864.19, p < 0.0001). The R-square has increased from 0.9197 to 0.9989, indicating that the model now accounts for 99.9% of the variation in Population. All effects are significant with p < 0.0001 for each effect in the model.

The fitted equation is now

Figure 99.13 show the panel of diagnostics for this quadratic polynomial model. These diagnostics indicate that this model is considerably more successful than the corresponding linear model:

  • The plots of residuals and studentized residuals versus predicted values exhibit no obvious patterns.

  • The points on the plot of the dependent variable versus the predicted values lie along a 45-degree line, indicating that the model successfully predicts the behavior of the dependent variable.

  • The plot of studentized residual versus leverage shows that the years 1790 and 2000 are leverage points with 2000 showing up as an outlier. This is confirmed by the plot of Cook’s D distance versus observation number. This suggests that while the quadratic model fits the current data well, the model might not be quite so successful over a wider range of data. You might want to investigate whether the population trend over the last couple of decades is growing slightly faster than quadratically.

Figure 99.13: Diagnostics Panel

Diagnostics Panel


When a model contains more than one regressor, PROC REG does not produce a fit plot. However, when all the regressors in the model are functions of a single variable, it is appropriate to plot predictions and residuals as a function of that variable. You request such plots by using the PLOTS=PREDICTIONS option in the PROC REG statement, as the following code illustrates:

proc reg data=USPopulation plots=predictions(X=Year);
   model Population=Year Yearsq;
quit;

ods graphics off;

Figure 99.14 shows the data, predictions, and residuals by Year. These plots confirm that the quadratic polynomial model successfully model the growth in U.S. population between the years 1780 and 2000.

Figure 99.14: Predictions and Residuals by Year

Predictions and Residuals by Year


To complete an analysis of these data, you might want to examine influence statistics and, since the data are essentially time series data, examine the Durbin-Watson statistic.