BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.

Hello,

 

I am using PROC SGPLOT to produce a scatterplot that depicts a linear relationship between a continuous predictor and a continuous outcome with a linear fit line and a surrounding 95% confidence interval. The code is below:

proc sgplot data=mydata NOAUTOLEGEND;
reg x=Predictor y=Outcome / 
filledoutlinedmarkers markerfillattrs=(color=white) 
markeroutlineattrs=(color=black) 
markerattrs=(symbol=circlefilled size=7)
lineattrs=(pattern=SOLID thickness=2 color=black) 
clm clmattrs=(clmfillattrs=(color=gray transparency=.3));
xaxis values = (0 to 3 by .5) 
label='Predictor'
LABELATTRS=(size=20 weight=bold) 
VALUEATTRS=(size=18 weight=bold);
yaxis grid values = (0 to 4 by .5) 
label='Outcome' 
LABELATTRS=(size=20 weight=bold)
VALUEATTRS=(size=18 weight=bold) 
GRIDATTRS=(color=GrayCA thickness=.0mm);
run;

This produces a plot depicting a simple linear regression. The issue is that my analyses include not only a predictor and an outcome, but also covariates such as sex and income. Is there some way to produce a scatterplot that depicts a relationship between a predictor and outcome while adjusting for several covariates? [I'd prefer not to share any data for privacy reasons.]

Thanks.

1 ACCEPTED SOLUTION
5 REPLIES 5
PaigeMiller
Diamond | Level 26

Use the predicted values from PROC REG in your SGPLOT scatterplot. I believe, if I am understanding you properly, you will have to pick a specific value of the covariate in order to get a predicted value; you could plot the predicted values for several different values of the covariate in SGPLOT, that might help show how the line changes as the covariate changes.

--
Paige Miller
confooseddesi89
Quartz | Level 8

Excellent, thank you. That is the plot I was looking for. For those who are interested, here is how I produced the partial plot with 95% confidence interval:

/***Run linear regression analysis with covariates & produce partial dataset***/
Proc reg data=mydata plots(only)=PartialPlot;
model Outcome=Predictor Covariate1 Covariate2 / VIF clb stb partial partialdata;
ods exclude PartialPlotData;
ods output PartialPlotData=partialdata;quit;run;

/*Obtain means of predictor and outcome in main data*/
proc means data=mydata mean; 
var Predictor Outcome;run;
/*create non-mean centered Predictor and Outcome in partial data*/
data partialdata; set partialdata;
Predictor=part_Predictor+[mean of predictor];
Outcome= part_Outcome_Predictor+[mean of outcome];run;
/**generate plot**/
proc sort data=partialdata; by Predictor;run;
proc sgplot data=partialdata NOAUTOLEGEND;
reg x=Predictor y=Outcome / 
filledoutlinedmarkers markerfillattrs=(color=white) 
markeroutlineattrs=(color=black) 
markerattrs=(symbol=circlefilled size=7)
lineattrs=(pattern=SOLID thickness=2 color=black) 
clm clmattrs=(clmfillattrs=(color=gray transparency=.3));
xaxis values = (.5 to 2.5 by .5) 
label='Predictor'
LABELATTRS=(size=20 weight=bold) 
VALUEATTRS=(size=18 weight=bold);
yaxis grid values = (1.5 to 2.5 by .25) 
label='Outcome' 
LABELATTRS=(size=20 weight=bold)
VALUEATTRS=(size=18 weight=bold) 
GRIDATTRS=(color=GrayCA thickness=.0mm);run;
PaigeMiller
Diamond | Level 26

@confooseddesi89 

I am going to have to disagree with the use of PARTIALDATA  here. It doesn't seem to fit the requirements you stated above, which was to plot the predicted values in the presence of a covariate. The PARTIALDATA plots the leverage, as stated in the PROC REG documentation.

 

 

PARTIALDATA

requests partial regression leverage data for each regressor. You can request partial regression leverage plots of these data with the PARTIAL option. See the section Influence Statistics for more information.

 

--
Paige Miller
confooseddesi89
Quartz | Level 8

Hi PaigeMiller,

 

According to the documentation, "For a given regressor, the partial regression leverage plot is the plot of the dependent variable and the regressor after they have been made orthogonal to the other regressors in the model." This appears to be what I desired. Indeed, the slope of the line in the partial plot is identical to the coefficient produced in the adjusted model. Perhaps I explained my desired plot incorrectly. Thanks for your answer nonetheless.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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