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

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.

 

 

Screenshot 2024-01-07 at 10.06.52.png

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
/*
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;

Ksharp_0-1704622051469.png

 

View solution in original post

5 REPLIES 5
Ksharp
Super User
/*
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;

Ksharp_0-1704622051469.png

 

emaneman
Pyrite | Level 9

Thank you! it works seamlessly. 

emaneman
Pyrite | Level 9

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 ;

Ksharp
Super User

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;

Ksharp_0-1704680497536.png

 

emaneman
Pyrite | Level 9

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.  

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is ANOVA?

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.

Discussion stats
  • 5 replies
  • 645 views
  • 0 likes
  • 2 in conversation