- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I want to draw a graph for observed vs predicted values with confidence and predicted intervals in simple linear regression. And also need to show residuals versus model predicted values on the same graph (similar to the below graph).
Does anyone know how to do it?
Thanks,
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
How about this one ?
data have;
set sashelp.class;
run;
ods select none;
ods output FitStatistics=FitStatistics;
proc reg data=have ;
model weight= height;
output out=want p=pred r=residual ;
quit;
ods select all;
data _null_;
set FitStatistics;
call symputx('rsquare',put(nValue2,8.2));
stop;
run;
data want;
set want;
residual=-residual;
run;
proc sgplot data=want;
title 'Hoffman Holstein Model';
reg x=weight y=pred/clm nomarkers;
scatter x=weight y=pred/markerattrs=(symbol=circlefilled) name='a' legendlabel='Observed DMI';
scatter x=weight y=residual/markerattrs=(symbol=diamondfilled) name='b' legendlabel='Residuals';
lineparm x=0 y=0 slope=1/lineattrs=(color=grey);
inset "R(*ESC*){sup '2'} = &rsquare."/ position=TopLeft border;
refline 0/axis=y;
yaxis label='Predicted DMI';
xaxis label='Observed DMI';
keylegend 'a' 'b';
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Show us a portion of your data. Show us your code.
Do you really want residuals and the raw data on the same plot? That really doesn't make sense to do.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
How about this one ?
data have;
set sashelp.class;
run;
ods select none;
ods output FitStatistics=FitStatistics;
proc reg data=have ;
model weight= height;
output out=want p=pred r=residual ;
quit;
ods select all;
data _null_;
set FitStatistics;
call symputx('rsquare',put(nValue2,8.2));
stop;
run;
data want;
set want;
residual=-residual;
run;
proc sgplot data=want;
title 'Hoffman Holstein Model';
reg x=weight y=pred/clm nomarkers;
scatter x=weight y=pred/markerattrs=(symbol=circlefilled) name='a' legendlabel='Observed DMI';
scatter x=weight y=residual/markerattrs=(symbol=diamondfilled) name='b' legendlabel='Residuals';
lineparm x=0 y=0 slope=1/lineattrs=(color=grey);
inset "R(*ESC*){sup '2'} = &rsquare."/ position=TopLeft border;
refline 0/axis=y;
yaxis label='Predicted DMI';
xaxis label='Observed DMI';
keylegend 'a' 'b';
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Use the OUTPUT statement in your regression procedure to output the predicted and residual values to a data set. Use PROC SGPLOT to create the plot. You will use two SCATTER statements and a SERIES statement. As Paige says, you'd better hope that the scale of the residuals is such that you can plot both Y and Residuals on the same axis.
data Have;
set sashelp.class;
X = Height;
Y = Weight;
keep X Y;
run;
proc reg data=Have plots=none;
model Y = X;
output out=RegOut P=Pred R=Resid;
quit;
proc sort data=RegOut;
by X;
run;
proc sgplot data=RegOut;
scatter x=X y=Y; /* origin data */
series x=X y=Pred; /* regression fit */
scatter x=x y=Resid / markerattrs=GraphData2;
refline 0;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you so much