BookmarkSubscribeRSS Feed
morten1
Calcite | Level 5

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;

 

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

morten1
Calcite | Level 5

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. 

Rick_SAS
SAS Super FREQ

>  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;
Rick_SAS
SAS Super FREQ

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.

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 1554 views
  • 0 likes
  • 3 in conversation