Obsidian | Level 7

## Scatterplot of logistic regression model-predicted log odds of the outcome by a continuous predictor

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
Super User

## Re: Scatterplot of logistic regression model-predicted log odds of the outcome by a continuous predi

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;

Obsidian | Level 7

## Re: Scatterplot of logistic regression model-predicted log odds of the outcome by a continuous predi

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.

Super User

## Re: Scatterplot of logistic regression model-predicted log odds of the outcome by a continuous predi

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.

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