proc sgplot: how to show equation of 95 % prediction limits

Occasional Contributor
Posts: 5

proc sgplot: how to show equation of 95 % prediction limits

Hi,

I am using proc sgplot to calculate the best fit regression line as well as the 95% prediction limits. I want the equation for all three lines plotted on the graph (or showed in the results). Now I can only see the the Parameter estimates for the best fit line.

This is my code:

``````data _null_;
set outputds;
if variable eq 'Intercept' then call symput('Int', put(estimate, BEST.));
else            call symput('Slope', put(estimate, BEST.));
ods output outputds;
run;
proc sgplot data=diffs noautolegend;
title "Regression Line with Slope and Intercept";
reg y=diff x=mean / cli;
ods output parameterestimates=outputds;
inset "Intercept = &Int" "Slope = &Slope" /
border title="Parameter Estimates" position=topleft;
run;
``````

Super User
Posts: 9,599

Re: proc sgplot: how to show equation of 95 % prediction limits

Not entireley sure on the spefics in this question - where the "equation" comes from.  Is that part of an output table from proc reg or something you hard code in?  As for plotting it, well that pretty simple.  Add into your plot data, the text you want to show, at the places you want to show, then have another statement in your sgplot:

scatter y=dif x=mean / markechars=(<variable>)

Examples here:

http://blogs.sas.com/content/graphicallyspeaking/?s=scatter+markerchar

Occasional Contributor
Posts: 5

Re: proc sgplot: how to show equation of 95 % prediction limits

Thank you! I was maybe a little bit unclear in my explanation: I already have the intercept and slope (with this I mean equation) for the fit-line in my Parameter Estimates, but I also need the intercept and slope for the upper and lower 95 % prediction limits. I can not see this in the example and I am also not very good at programming in SAS so it would be great if you know a code for this.

SAS Super FREQ
Posts: 4,241

Re: proc sgplot: how to show equation of 95 % prediction limits

>  I also need the intercept and slope for the upper and lower 95 % prediction limits.

Unfortunately, the prediction limits are not linear, so they do not have an intercept or slope.  Run the following code. The graph that is produced shows that the prediction limits are wide at the extreme of the X variable and narrow in the middle.  There is no simple equation for those curves in terms of X.

``````ods graphics on;
proc reg data=sashelp.class plots(only)=fitplot;
model weight = height;
run;``````
SAS Super FREQ
Posts: 4,241

Re: proc sgplot: how to show equation of 95 % prediction limits

[ Edited ]

To show the estimated slope and intercept, see the article "How to use PROC SGPLOT to display the slope and intercept of a regression line", which gives complete step-by-step code and an example.

In particular, you are trying to use the REG statement in PROC SGPLOT, but you need to use PROC REG if you want to use ODS OUTPUT to capture the ParameterEstimates table.

The title of your question is "show equation of 95% prediction limits," which different from the slope/intercept equation that you seem to want. See the documentation for "Statistical Background in Linear Regression" if you want to see the formulas used to compute those limits.

Discussion stats
• 4 replies
• 482 views
• 0 likes
• 3 in conversation