Dears,
I would like to overlay two plots that are outputted by the plots= command in PROC LOGISTIC.
This is the syntax that I use:
proc logistic data=mergedss plots=effect ( clband=yes SHOWOBS=no x=(E_emo I_emo )) ;
model genre(event= 'literary') = E_emo I_emo /stb cl ;
The result is shown below.
Is there a way to overlay the two slopes, using different colors and symbols (e.g. continuous vs dotted line)?
The two predictors are both standardized, and the range is +4.5 and -3. Thus the x-axis range could be put at -6 / +6.
/*
1)get these data.
2)overlay these two graph by PROC SGPLOT.
*/
data have;
set sashelp.heart(obs=200);
run;
ods select none;
ods output EffectPlot= EffectPlot;
proc logistic data=have plots=effect ( clband=yes SHOWOBS=no x=(Diastolic Systolic)) ;
model status = Diastolic Systolic /stb cl ;
run;
ods select all;
data EffectPlot;
set EffectPlot;
id+1;
run;
proc rank data=EffectPlot out=want groups=2; /*2 is refer to two X variables(Diastolic Systolic)*/
var id;
ranks group;
run;
proc format;
value fmt
0='Diastolic'
1='Systolic'
;
run;
ods graphics/attrpriority=none ;
proc sgplot data=want ;
styleattrs datalinepatterns=(solid dash);
band x=_XVAR lower=_lower upper=_upper/group=group transparency=0.8;
series x=_XVAR y=_PROB /group=group name='x';
keylegend 'x';
yaxis values=(0 to 1 by 0.1);
label _XVAR='E_mmo and L_mmo' _PROB='Proability' ;
format group fmt.;
run;
/*
1)get these data.
2)overlay these two graph by PROC SGPLOT.
*/
data have;
set sashelp.heart(obs=200);
run;
ods select none;
ods output EffectPlot= EffectPlot;
proc logistic data=have plots=effect ( clband=yes SHOWOBS=no x=(Diastolic Systolic)) ;
model status = Diastolic Systolic /stb cl ;
run;
ods select all;
data EffectPlot;
set EffectPlot;
id+1;
run;
proc rank data=EffectPlot out=want groups=2; /*2 is refer to two X variables(Diastolic Systolic)*/
var id;
ranks group;
run;
proc format;
value fmt
0='Diastolic'
1='Systolic'
;
run;
ods graphics/attrpriority=none ;
proc sgplot data=want ;
styleattrs datalinepatterns=(solid dash);
band x=_XVAR lower=_lower upper=_upper/group=group transparency=0.8;
series x=_XVAR y=_PROB /group=group name='x';
keylegend 'x';
yaxis values=(0 to 1 by 0.1);
label _XVAR='E_mmo and L_mmo' _PROB='Proability' ;
format group fmt.;
run;
Thank you! it works seamlessly.
I will push my luck...
any chance you could suggest the same for a multiple linear regression?
proc reg data=xx ;
model DV1 = IV1 IV2 ;
Sure .Just use PROC PLM to get those data instead of PLOTS= option due to PROC GLM/REG don't have such graph as PROC LOGISTIC( I didn't found it ,maybe someone could).
Also could check Rick.Wicklin 's blogs:
4 reasons to use PROC PLM for linear regression models in SAS - The DO Loop
Use the EFFECTPLOT statement to visualize regression models in SAS - The DO Loop
3 ways to add confidence limits to regression curves in SAS - The DO Loop
Visualize uncertainty in regression predictions - The DO Loop (sas.com)
data have;
set sashelp.heart(obs=200);
run;
ods select none;
proc glm data=have ;
model ageatstart = Diastolic Systolic / solution ;
store PainModel;
quit;
proc plm restore=PainModel;
effectplot fit(x=Diastolic )/clm;
effectplot fit(x=Systolic )/clm;
ods output FitPlot= FitPlot;
run;
ods select all;
data FitPlot;
set FitPlot;
id+1;
run;
proc rank data=FitPlot out=want groups=2; /*2 is refer to two X variables(Diastolic Systolic)*/
var id;
ranks group;
run;
proc format;
value fmt
0='Diastolic'
1='Systolic'
;
run;
ods graphics/attrpriority=none ;
proc sgplot data=want ;
styleattrs datalinepatterns=(solid dash);
band x=_XCONT1 lower=_LCLM upper=_UCLM/group=group transparency=0.8;
series x=_XCONT1 y=_PREDICTED /group=group name='x';
keylegend 'x';
label _XCONT1='Diastolic and Systolic' _PREDICTED='ageatstart' ;
format group fmt.;
run;
hello. Yes, Rick.Wicklin's blog and responses here have been immensely valuable to me. I have seen these entries on his blog, but they refer to situations where there is one continuous predictor and a categorical one, and show how you can get separate slops for each of the level of the categorical variable, in the same graph. But I could not find a way to put the slopes of two continuous predictors in the same graph. Your solution for when I had PROC LOGISTIC as the starting point worked perfectly, but I could not find a way to adapt it to the situation in which my starting point PROC REG (or PROC GLM), in which my criterion is continuous, rather than categorical. When you have two continuous predictors, PROC GLM gives you a contour plot with the Plot=fit option, but that is not what I want. A solution where I can use SGPLOT with the output of the PROC REG or PROC GLM would be best, since SGPLOT allows to adjust the graph features.
Thank you again.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.