Data visualization with SAS programming

How to display Regression Line and R-Squared value

Accepted Solution Solved
Reply
Contributor sfo
Contributor
Posts: 66
Accepted Solution

How to display Regression Line and R-Squared value

Hi,

 

I have SAS 9.2 and I need to display the linear regression line and R-Squared or the p-value on the plot. I have three groups and my plot looks something like attached.

 

Is it possible to display the regression line superimposed on the colored dots? I am trying the following for scatter plot and regression analysis:

 

proc gplot data = plot_data anno= anno ;
plot yaxis*xaxis=cohort_no /vaxis=axis1 haxis=axis nolegend noframe;

run;

proc reg data = plot_data anno= anno1 ;
model yaxis = xaxis;
plot yaxis*xaxis ;
run;

 

Thanks a lot

 

Attachment

Accepted Solutions
Solution
‎09-03-2016 11:41 AM
SAS Super FREQ
Posts: 3,416

Re: How to display Regression Line and R-Squared value

[ Edited ]

Most statisticians do not use the old PLOTS statement anymore. Instead, most use ODS statistical graphics, which are produced automatically by most SAS/STAT procedures. See the following two examples:

 

ods graphics on;
proc reg data =sashelp.class plots=FitPlot(stats=DEFAULT);
model weight = height;
quit;

proc glm data =sashelp.class plots=FitPlot;
class sex;
model weight = height | sex;
quit;

For an overview, see Rodriguez (2009) "Getting Started with ODS Statistical Graphics in SAS 9.2."

View solution in original post


All Replies
Solution
‎09-03-2016 11:41 AM
SAS Super FREQ
Posts: 3,416

Re: How to display Regression Line and R-Squared value

[ Edited ]

Most statisticians do not use the old PLOTS statement anymore. Instead, most use ODS statistical graphics, which are produced automatically by most SAS/STAT procedures. See the following two examples:

 

ods graphics on;
proc reg data =sashelp.class plots=FitPlot(stats=DEFAULT);
model weight = height;
quit;

proc glm data =sashelp.class plots=FitPlot;
class sex;
model weight = height | sex;
quit;

For an overview, see Rodriguez (2009) "Getting Started with ODS Statistical Graphics in SAS 9.2."

Grand Advisor
Posts: 10,229

Re: How to display Regression Line and R-Squared value

If you want to continue with GPLOT your solution would involve setting a Symbol statement to show the desired regression for each level of your cohort_no.

Something like

 

symbol1 i=RL color=red;

 

The i or Interpol option R is for regression options are availble for showing confidence limits of individual responses or the mean and the interval for the confidence limits as well.

Contributor sfo
Contributor
Posts: 66

Re: How to display Regression Line and R-Squared value

Thanks for the reply.

 

I amting two get different regression line plots, when I use PROC REG and when I use proc gplot see below, could you help me why?

 

Code:

For R squared value using proc reg

proc reg data = plot_data outest=reg_val outsscp=sscp1 rsquare;
model yaxis = xaxis ;
plot yaxis*xaxis;
run;
quit;

 

for scatter plot using gplot

symbol1 i=none v=dot w=2 l=3 h=4 color=blue;
symbol2 i=none v=C w=2 l=4 h=2.5 f=marker color=red;
symbol3 i=none v=U w=2 l=4 h=2.5 f=marker color=green;
symbol4 i=none w=2 l=3 h=3 i=rl color=black;

 

proc gplot data = plot_data anno= anno1 ;
plot yaxis*xaxis=cohort_no /vaxis=axis1 haxis=axis2 nolegend noframe;
plot2 yaxis*xaxis/ noaxis;
run;
quit;

 

 

Attachment
Attachment
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 548 views
  • 1 like
  • 3 in conversation