- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
That is because you changed design matrix I think.
And @Rick_SAS know more things could give you more explanation .
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Calling @Rick_SAS
You could try EFFECTPLOT of PROC LOGISTIC.
Rick wrote a couple of blogs about it.
https://blogs.sas.com/content/iml/2016/06/22/sas-effectplot-statement.html
https://blogs.sas.com/content/iml/2019/02/11/proc-plm-regression-models-sas.html