SAS Loess Plot

SAS Day 32: Loess Model Scatter Plot 

When I was in Middle School, Sin(x) and Cos(x) are my favorite curves, because they are so predictable! Once we know the cycle and amplitude, we can solve everything about it. 
However, in statistical modeling, oscillating curves are not so welcomed. Today we will introduce the Loess Plot for finding a curve of best fit without assuming the data must fit some distribution shape.

Loess regression is a nonparametric technique that uses locally weighted regression to fit a smooth curve through points in a scatter plot.

LOESS: Locally weighted scatter plot smoothing

we will use ENSO dataset to perform a Loess graph.

ENSO-El Nino Southern Oscillation dataset capture the monthly averaged atmospheric pressure differences between Easter Island and Darwin, Australia for 168 months.

 

Cleverpix / Pixabay

 

Basic Loess Graph with 95% Confidence Limits

 

proc sgplot data=sashelp.enso;
title “losess Fit”;
loess y=pressure x=month/clm;
run;

 

Advanced Loess Graph with Linear, Polynomial, and Penalized B-Spline Model comparison

 

proc sgplot data=sashelp.enso;
title “Fit Functions”;
reg y=pressure x=month/legendlabel=”Linear”;
reg y=pressure x=month/legendlabel=”Cubic” degree=3 nomarkers;
pbspline y=pressure x=month/nomarkers;
loess y=pressure x=month/nomarkers;
run;

 

 

proc template;
define statgraph Fits;
begingraph;
entrytitle “Fit Functions”;
layout overlay;
scatterplot y=pressure x=month;
regressionplot y=pressure x=month/lineattrs=GraphData1 name=”Linear“;
regressionplot y=pressure x=month/lineattrs=GraphData2 name=”Cubic” degree=3;
pbsplineplot y=pressure x=month/lineattrs=GraphData3 name=”Penalized B-spline“;
loessplot y=pressure x=month/lineattrs=GraphData4 name=”Loess“;
discretelegend “Linear” “Cubic” “Penalized B-spline” “Loess“;
endlayout;
endgraph;
end;
run;

proc sgrender data=sashelp.enso template=Fits;
run;

Both Proc SGPLOT and Proc Template would generate the same result. As we can see, Linear and 3rd-degree Polynomial are not great approaches for ENSO dataset.  The statistical model winner for ENSO dataset are LOESS and Penalized B-Spline.

 

Reference:

Creating Statistical Graphics in SAS,
Warren F.Kuhfeld  

Happy Practicing!  🍹

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Social media & sharing icons powered by UltimatelySocial
%d bloggers like this: