BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
syk
Obsidian | Level 7 syk
Obsidian | Level 7

What is the sgplot equivalent of:

 

symbol1 i=sm70;
proc gplot data=somefile;
     plot resid*x / vref = 0;

 

I got a similar graph from doing:

 

proc sgplot data=somefile;
    loess x=x y=resid;
    refline 0;

 

 

But it seems like the sm70 smoothing function contributes to creating a slightly different graph from the sgplot. What am I missing from the sgplot?

 

 

 


gplot.GIFsgplot.GIF
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Does it make sense to expect a SPLINE to fit a LOESS curve?

Why not use the SPLINE statement if you want a spline interpolation, which is what sm70 creates?

http://support.sas.com/documentation/cdl/en/graphref/69717/HTML/default/viewer.htm#n0c0j84n1e2jz9n1b...

 

 

View solution in original post

16 REPLIES 16
Reeza
Super User

Does it make sense to expect a SPLINE to fit a LOESS curve?

Why not use the SPLINE statement if you want a spline interpolation, which is what sm70 creates?

http://support.sas.com/documentation/cdl/en/graphref/69717/HTML/default/viewer.htm#n0c0j84n1e2jz9n1b...

 

 

syk
Obsidian | Level 7 syk
Obsidian | Level 7

To clarify my question, I need to use sgplot instead of gplot beacuse I'm using SAS University Edition. How do I produce the same result using sgplot from the original gplot with symbol1 i=sm70?

Reeza
Super User

Can you post some data so we can replicate it to test? 

Trying to read those images isn't going to cut it for testing.

syk
Obsidian | Level 7 syk
Obsidian | Level 7
data orig; input age plasma @@;
cards;
0 13.44 0 12.84 0 11.91 0 20.09 0 15.60
1 10.11 1 11.38 1 10.28 1 8.96 1 8.59
2 9.83 2 9.00 2 8.65 2 7.85 2 8.88
3 7.94 3 6.01 3 5.14 3 6.90 3 6.77
4 4.86 4 5.10 4 5.67 4 5.75 4 6.23
; 
proc reg data=orig;
 model plasma=age;
 output out = notrans r = resid;
run;

/*
symbol1 i=sm70;
proc gplot data = notrans;
 plot resid*age / vref = 0; 
*/

proc sgplot data=notrans;
 loess x=age y=resid;
 refline 0;

 

Jagadishkatam
Amethyst | Level 16

Please try the 

 

goptions interpol=sm70;

Thanks,
Jag
syk
Obsidian | Level 7 syk
Obsidian | Level 7

 

 

 

Where in the code does the statement have to be inserted?

 

 

sgplot.GIF

error.GIF

syk
Obsidian | Level 7 syk
Obsidian | Level 7
You were right in trying to fit the curve using the SPLINE, I used the PBSPLINE since the SPLINE statement doesn't have the smooth option. I got the result that I wanted using the gplot sm70.
WarrenKuhfeld
Rhodochrosite | Level 12
proc sgplot data=sashelp.enso;
pbspline y=pressure x=month;
run;

proc gplot data=sashelp.enso;
symbol1 color=blue i=sm70;
symbol2 color=red i=none v=circle;
plot pressure*month
pressure*month / overlay;
run; quit;

proc transreg data=sashelp.enso design;
model ide(pressure) = smooth(month / sm=70);
output out=b p;
run;

proc sgplot data=b;
scatter y=pressure x=month;
series y=ppressure x=month;
run;

proc gplot data=b;
symbol1 color=blue i=sm70 v=none;
symbol2 color=red i=none v=circle;
symbol3 color=green i=none v=square;
plot pressure*month pressure*month ppressure*month / overlay;
run; quit;

Personally, I would prefer the penalized b-spline, but I am biased since I wrote it.  Decades ago, before ODS, users requested GPLOT smooth functions in an output data set. It was at or near the top of the sasware ballot. I knew GPLOT would never provide it, so I put it in transreg, which fits a lot of other smooth functions.  You can then output the smooth function from transreg and put that smooth function into SGPLOT or GPLOT (just to reassure yourself that they are doing the same thing).

syk
Obsidian | Level 7 syk
Obsidian | Level 7

Your method of creating a data 'b' also works. But for the sake of succinctness sgplot pbspline produced the same result as gplot. Thank you for providing me with a detailed alternative.

WarrenKuhfeld
Rhodochrosite | Level 12

Are you saying you can get precisely the same results from pbspline in sgplot with a smoothing parameter as you get from gplot and sm70?  The two methods are quite different.  Or are you saying you can get similar smooths?  Thanks in advance for clarifying.

syk
Obsidian | Level 7 syk
Obsidian | Level 7

Not precise but very close. SPLINE statement doesn't provide the smooth option, so I had no other choice other than to use the PBSPLINE. 

 

sgplot.GIF

gplot.GIF

Rick_SAS
SAS Super FREQ

You can exactly reproduce the result from PROC GPLOT by using either PROC TRANSREG or PROC IML, as shown in the article "Three ways to add a smoothing spline to a scatter plot in SAS."

 

However, I recommend one of the statistical fits because then SAS can automatically choose the smoothing parameter based on statistical criteria. See "How to automatically select a smooth curve for a scatter plot in SAS."

 

syk
Obsidian | Level 7 syk
Obsidian | Level 7
But for residual plot, the transreg doesn't seem to give me the option to plot a refline.
WarrenKuhfeld
Rhodochrosite | Level 12

I'm not sure what you are saying.  Transreg makes graphs, but it is not a graphing procedure per se.  I just used it to add a variable to the data set that I then showed how to plot with sgplot and how to verify that it matched gplot.  You can add reference lines in the usual way to sgplot.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 16 replies
  • 3121 views
  • 7 likes
  • 5 in conversation