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

Hello,

 

I am running a multiple logistic regression and would like to produce a plot that depicts the logistic regression curve, with one predictor on the x-axis and the predicted probability of outcome on y-axis, while adjusting for other predictors in the model. I'd prefer to produce such a plot with PROC SGPLOT if possible. Is there a way to do this? Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

It might help to include the code you are currently using for your regression and indicate which predictor you want to use.

 

Likely you need to create an output data set with the predictors and predicted values and the method for that might change depending on how your are doing your regression. Then use that data set, or perhaps a modified version of it, as the input for Proc Sgplot.

View solution in original post

8 REPLIES 8
ballardw
Super User

It might help to include the code you are currently using for your regression and indicate which predictor you want to use.

 

Likely you need to create an output data set with the predictors and predicted values and the method for that might change depending on how your are doing your regression. Then use that data set, or perhaps a modified version of it, as the input for Proc Sgplot.

confooseddesi89
Quartz | Level 8

This worked, but I noticed something odd - the line on the plot changes depending on which reference group I choose for a certain class covariate I include in the model. That is, I have the class covariate "race" in the model with the reference as "White," and when I change the reference to "Black," the line becomes steeper. Is there any reason why this may be so? See first graph with reference "White" and second graph with reference "Black." Additionally, when I run the logistic regression analysis and request all plots, the analysis produces the plot (third graph) that appears to depict the effect of the predictor on the outcome at each level of "race." However, I want the mean line across all races, not a different line for each race (I am not interested in interactions). The point estimate and p-level are the same no matter what I set as the reference race, so I'm not sure why the graphs I'm producing are specifically at the reference level of race.

 

Graph ref 1.pngGraph ref 2.png

for sas forum.png

Ksharp
Super User
"I change the reference to "Black," the line becomes steeper. Is there any reason why this may be so?"
That is because you changed design matrix I think.
And @Rick_SAS know more things could give you more explanation .
Rick_SAS
SAS Super FREQ

If you post the code that generated the two graphs, we will be able to answer your questions.

 

The predicted values do not depend on the parameterization, so I assume the problem is that the two curves are using different values for the covariates that are not depicted.

confooseddesi89
Quartz | Level 8

Hello,

Below is my code:

/*reference of "Black" race*/
proc logistic data=Mydata desc;
class race(ref='2');
model Outcome=Predictor race / EXPEST;
store outdata;
run;
ods output fitplot =  Fit_outdata;
proc plm source=outdata;
effectplot fit(x=Predictor);
run;
proc sgplot data=Fit_outdata noautolegend;
series x = _XCONT1 y = _PREDICTED / 
lineattrs=(color=VIB pattern=SOLID thickness=3);
band X=_XCONT1 lower=_lclm upper=_uclm / 
fillattrs=(color=VLIGB transparency=.5);
xaxis values = (0 to 3 by 1) 
label='Predictor'
LABELATTRS=(size=14) VALUEATTRS=(size=14);
yaxis grid values = (0 to .8 by .2) label='Outcome' LABELATTRS=(size=14)
VALUEATTRS=(size=14) GRIDATTRS=(color=GrayCA thickness=.0mm);run;

/*reference of "White" race*/
proc logistic data=Mydata desc;
class race(ref='1');
model Outcome=Predictor race / EXPEST;
store outdata;
run;
ods output fitplot =  Fit_outdata;
proc plm source=outdata;
effectplot fit(x=Predictor);
run;
proc sgplot data=Fit_outdata noautolegend;
series x = _XCONT1 y = _PREDICTED / 
lineattrs=(color=VIB pattern=SOLID thickness=3);
band X=_XCONT1 lower=_lclm upper=_uclm / 
fillattrs=(color=VLIGB transparency=.5);
xaxis values = (0 to 3 by 1) 
label='Predictor'
LABELATTRS=(size=14) VALUEATTRS=(size=14);
yaxis grid values = (0 to .8 by .2) label='Outcome' LABELATTRS=(size=14)
VALUEATTRS=(size=14) GRIDATTRS=(color=GrayCA thickness=.0mm);run;

As you can see, the only thing that changes is the "ref" for the "race" variable in the "class" statement, yet the lines produced by both effectplot and sgplot (which uses the predicted values from the data produced by the "store" statement) are quite different.

Rick_SAS
SAS Super FREQ

Yes, the STORE statement records the reference level, so PROC PLM produces a fit plot for RACE equal to the reference level. Notice that the first call to PROC PLM produces a fit plot that has the footnote "Fit computed at Race=2". In contrast, the second call to PROC PLM produces a fit plot that has the footnote "Fit computed at Race=1". So the two plots are showing different predicted values. The first plot shows the predicted values for Black subjects and the second shows the predicted values for White subjects.

 

 

 

Ksharp
Super User
OMG, As Rick pointed out, your Y variable is changed .

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 8 replies
  • 1429 views
  • 2 likes
  • 4 in conversation