## gplot and sgplot

Solved
Occasional Contributor
Posts: 19

# gplot and sgplot

[ Edited ]

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?

Accepted Solutions
Solution
‎07-02-2017 02:10 PM
Super User
Posts: 21,572

## Re: gplot and sgplot

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...

All Replies
Solution
‎07-02-2017 02:10 PM
Super User
Posts: 21,572

## Re: gplot and sgplot

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...

Occasional Contributor
Posts: 19

## Re: gplot and sgplot

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?

Super User
Posts: 21,572

## Re: gplot and sgplot

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.

Occasional Contributor
Posts: 19

## Re: gplot and sgplot

[ Edited ]
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;

Posts: 1,137

## Re: gplot and sgplot

goptions interpol=sm70;

Thanks,
Jag
Occasional Contributor
Posts: 19

## Re: gplot and sgplot

[ Edited ]

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

Occasional Contributor
Posts: 19

## Re: gplot and sgplot

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.
SAS Super FREQ
Posts: 481

## Re: gplot and sgplot

[ Edited ]
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).

Occasional Contributor
Posts: 19

## Re: gplot and sgplot

[ Edited ]

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.

SAS Super FREQ
Posts: 481

## Re: gplot and sgplot

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.

Occasional Contributor
Posts: 19

## Re: gplot and sgplot

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.

SAS Super FREQ
Posts: 3,908

## Re: gplot and sgplot

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."

Occasional Contributor
Posts: 19

## Re: gplot and sgplot

But for residual plot, the transreg doesn't seem to give me the option to plot a refline.
SAS Super FREQ
Posts: 481

## Re: gplot and sgplot

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.

☑ This topic is solved.