|The LOESS Procedure|
|Scatter Plot Smoothing|
The following data from the Connecticut Tumor Registry presents age-adjusted numbers of melanoma incidences per 100,000 people for the 37 years from 1936 to 1972 (Houghton, Flannery, and Viola; 1980).
data Melanoma; input Year Incidences @@; format Year d4.0; datalines; 1936 0.9 1937 0.8 1938 0.8 1939 1.3 1940 1.4 1941 1.2 1942 1.7 1943 1.8 1944 1.6 1945 1.5 1946 1.5 1947 2.0 1948 2.5 1949 2.7 1950 2.9 1951 2.5 1952 3.1 1953 2.4 1954 2.2 1955 2.9 1956 2.5 1957 2.6 1958 3.2 1959 3.8 1960 4.2 1961 3.9 1962 3.7 1963 3.3 1964 3.7 1965 3.9 1966 4.1 1967 3.8 1968 4.7 1969 4.4 1970 4.8 1971 4.8 1972 4.8 ;
The following PROC SGPLOT statements produce the simple scatter plot of these data displayed in Figure 50.1.
proc sgplot data=Melanoma; scatter y=Incidences x=Year; run;
Suppose that you want to smooth the response variable Incidences as a function of the variable Year. The following PROC LOESS statements request this analysis with the default settings:
ods graphics on; proc loess data=Melanoma; model Incidences=Year; run;
You use the PROC LOESS statement to invoke the procedure and specify the data set. The MODEL statement names the dependent and independent variables.
When you enable graphics with an ODS GRAPHICS statement, PROC LOESS produces several default plots. Figure 50.2 shows the "Fit Plot" that overlays the loess fit on a scatter plot of the data. You can see that the loess fit captures the increasing trend in the data as well as the periodic pattern in the data, which is related to an 11-year sunspot activity cycle.
|Fit Method||kd Tree|
|Number of Observations||37|
|Number of Fitting Points||37|
|kd Tree Bucket Size||1|
|Degree of Local Polynomials||1|
|Points in Local Neighborhood||9|
|Residual Sum of Squares||2.03105|
Figure 50.3 shows the "Fit Summary" table. This table details the settings used and provides statistics about the fit that is produced. You can see that smoothing parameter value for this loess fit is . This smoothing parameter determines the fraction of the data in each local neighborhood. In this example, there are data points and so the smoothing parameter value of yields local neighborhoods containing 9 observations.
The "Smoothing Criterion" table provides information about how this smoothing parameter value is selected. The default method implemented in PROC LOESS chooses the smoothing parameter that minimizes the AICC criterion (Hurvich, Simonoff, and Tsai; 1998) that strikes a balance between the residual sum of squares and the complexity of the fit.
You use options in the MODEL statement to change the default settings and request optionally displayed tables. For example, the following statements request that the "Model Summary" and "Output Statistics" tables be included in the displayed output. By default, these tables are not displayed.
proc loess data=Melanoma; model Incidences=Year / details(ModelSummary OutputStatistics); run;
The "Model Summary" table shown in Figure 50.5 provides information about all the models that PROC LOESS evaluated in choosing the smoothing parameter value.
Figure 50.6 shows the "Criterion Plot" that provides a graphical display of the smoothing parameter selection process.
Figure 50.7 show the "Output Statistics" table that contains the predicted loess fit value at each observation in the input data set.
Although the default method for selecting the smoothing parameter value is often satisfactory, it is often a good practice to examine how the loess fit varies with the smoothing parameter. In some cases, fits with different smoothing parameters might reveal important features of the data that cannot be discerned by looking at a fit with just a single "best" smoothing parameter. Example 50.4 provides such an example. You can produce the loess fits for a range of smoothing parameters by using the SMOOTH= option in the MODEL statement as follows:
proc loess data=Melanoma; model Incidences=Year/smooth=0.1 0.25 0.4 0.6 residual; ods output OutputStatistics=Results; run;
The RESIDUAL option causes the residuals to be added to the "Output Statistics" table. Note that, even if you do not specify the DETAILS option in the MODEL statement to request the display of the "Output Statistics" table, you can use an ODS OUTPUT statement to output this and other optionally displayed tables as data sets.
PROC PRINT displays the first five observations of the Results data set:
proc print data=Results(obs=5); id obs; run;
Note that the fits for all the smoothing parameters are placed in single data set. A variable named SmoothingParameter that you use to distinguish each fit is included in this data set.
When you specify a list of smoothing parameters for a model and you have enabled ODS Graphics, PROC LOESS produces a panel containing up to six plots that show the fit obtained for each value of the smoothing parameter that you specify. If you specify more than six smoothing values, then multiple panels are produced. For each regressor, PROC LOESS also produces panels of the residuals versus each regressor by the smoothing parameters that you specify.
If you examine the plots in Figure 50.9, you see that a visually reasonable fit is obtained with smoothing parameter values of . With smoothing parameter value , there is gross overfitting in the sense that the original data are exactly interpolated. When the smoothing parameter value is , you obtain an overly smooth fit where the contribution of the sunspot cycle has been mostly averaged away. At smoothing parameter value the fit shows just the increasing trend in the data.
It is also instructive to look at scatter plots of the residuals for each of the fits. These are also produced by default by PROC LOESS when ODS Graphics is enabled.
Figure 50.10 shows a scatter plot of the residuals by year for each smoothing parameter value. One way to discern patterns in these residuals is to superimpose a loess fit on each plot in the panel. You request loess fits on the residual plots in this panel by specifying the SMOOTH= suboption of the PLOTS=RESIDUALSBYSMOOTH option in the PROC LOESS statement. Note that the loess fits that are displayed on each of the residual plots are obtained independently of the loess fit that produces these residuals. The following statements show how you do this for the Melanoma data.
proc loess data=Melanoma plots=ResidualsBySmooth(smooth); model Incidences=Year/smooth=0.1 0.25 0.4 0.6; run;
The loess fits shown on the plots in Figure 50.11 help confirm the conclusions obtained when you look at Figure 50.9. Note that residuals for smoothing parameter value do not exhibit any pattern, confirming that at this value the loess fit of the melanoma data has successfully modeled the variation in this data. By contrast, the residuals for the fit with smoothing parameter retain the variation caused by the sunspot cycle.
The examination of the fits and residuals obtained with a range of smoothing parameter values confirms that the value of that PROC LOESS selects automatically is appropriate for these data. The next step in this analysis is to examine fit diagnostics and produce confidence limit for the fit. If you enable ODS Graphics, then a panel of fit diagnostics is produced. Furthermore, you can request prediction confidence limits by adding the CLM option in the MODEL statement. By default 95% limits are produced, but you can use the ALPHA= option in the MODEL statement to change the significance level. The following statements request 90% confidence limits.
proc loess data=Melanoma; model Incidences=Year/clm alpha=0.1; run; ods graphics off;
Figure 50.12 shows the fit diagnostics panel. The histogram of the residuals with overlaid normal density estimator and the normal quantile plot show that the residuals do exhibit some small departure from normality. The "Residual-Fit" spread plot shows that the spread in the centered fit is much wider that the spread in the residuals. This indicates that the fit has accounted for most of the variation in the incidences of melanoma in this data. This conclusion is supported by the absence of any clear pattern in the scatter plot of residuals by predicted values and the closeness of the points to the 45-degree reference line in the plot of observed by predicted values.
Finally, Figure 50.13 shows the selected loess fit with 90% confidence limits.
Copyright © SAS Institute, Inc. All Rights Reserved.