BookmarkSubscribeRSS Feed
greesamu
Obsidian | Level 7

I'm trying to check that I meet the linearity assumption for logist regression.

I want to plot the model-predicted log odds of the outcome by a continuous predictor in a scatter plot. Is there a way to do this in SAS?

 

I'm not sure it's needed but the code for my logistic model is below:

 

proc logistic data=ST;
class dow moonphase;
model complication(event='1') = hour month_concern dow moonphase ;
run;

3 REPLIES 3
Reeza
Super User

Something like these?

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/statug/statug_logistic_examples02.htm#statug....

 

If so, look into the EFFECTPLOT statement.

 


@greesamu wrote:

I'm trying to check that I meet the linearity assumption for logist regression.

I want to plot the model-predicted log odds of the outcome by a continuous predictor in a scatter plot. Is there a way to do this in SAS?

 

I'm not sure it's needed but the code for my logistic model is below:

 

proc logistic data=ST;
class dow moonphase;
model complication(event='1') = hour month_concern dow moonphase ;
run;


 

greesamu
Obsidian | Level 7

Thanks, this is on the right track and I'll keep looking in this direction. That said, I'd like the Y-axis to be the predicted log odds instead of predicted probability and I'd like the plot to be a scatterplot. 

Reeza
Super User

Sorry, what's the difference with predicted log odds versus predicted probability? Is this to check the linearity of the terms with respect to the regression?

 

Since I suspect it's just conversions of the values, you may want to use the EFFECTPLOT and capture the data behind the graph. Then plot it yourself using SGPLOT.

 

Here's some instructions and explanations on how to capture output that is shown.
https://blogs.sas.com/content/sastraining/2017/03/31/capturing-output-from-any-procedure-with-an-ods...

 

For shown example, depending on your effectplot statement your ods table name may vary. 

 

ods select none;
ods output   SliceFitPanel=rawData;
proc logistic data=Neuralgia plots(only)=(oddsratio(range=clip));
   class Treatment Sex /param=ref;
   model Pain= Treatment Sex Age / noor;
   effectplot / at(Sex=all) noobs;
run;
ods select all;

proc print data=rawData;
run;

data scaled;
set rawDAta;
logsvalue = log(_predicted/(1-_predicted));
run;

proc sgplot data=scaled;
where _at = "Sex=F";
scatter x=_xcont1 y=logsValue / jitter;
run;

There are too many data points in this one so the points blend together to form a line. 

You could reduce the frequency and take every 5th or 10th value I suppose. 

 

 

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

Register now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2591 views
  • 0 likes
  • 2 in conversation