BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
bkq32
Quartz | Level 8

I've seen instructions for how to overlay ROC curves when the outcome is the same across models but not when they're different. For example, is it possible to overlay these two ROC curves that have the same predictors but different outcomes?

 

*Make example dataset;
data test ( keep = anemia allergy weight visit );
 set sashelp.bweight;
 if _N_ <= 100;
 anemia = black;
 allergy = married;
run;

*Outcome = ANEMIA;
proc logistic data = test descending;
 model anemia = weight visit;
 roc weight visit;
run; quit;

*Outcome = ALLERGY;
proc logistic data = test descending;
 model allergy = weight visit;
 roc weight visit;
run; quit;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

Use the OUTROC= option on the MODEL statement to output the points for each ROC curve. Merge the two curves. Use SGPLOT to overlay the two curves:

*Make example dataset;
data test ( keep = anemia allergy weight visit );
 set sashelp.bweight;
 if _N_ <= 100;
 anemia = black;
 allergy = married;
run;

*Outcome = ANEMIA;
proc logistic data = test descending;
 model anemia = weight visit / outroc=ROC1;
 run; quit;
*Outcome = ALLERGY;
proc logistic data = test descending;
 model allergy = weight visit / outroc=ROC2;
run; quit;

/* merge in the population ROC curve */
data ROCAll;
   set ROC1(in=r1) ROC2;
   if r1 then Model=1;
   else Model = 2;
run;

title "Compare ROC Curves for Different Models";
proc sgplot data=ROCAll aspect=1 noautolegend;
   step x=_1MSPEC_ y=_SENSIT_ / group=Model;
   lineparm x=0 y=0 slope=1 / lineattrs=(color=gray);
   xaxis grid;   yaxis grid;
   label _1MSPEC_ ="False Positive Rate (FPR)" _SENSIT_ ="True Positive Rate (TPR)";
run;

View solution in original post

3 REPLIES 3
Rick_SAS
SAS Super FREQ

Use the OUTROC= option on the MODEL statement to output the points for each ROC curve. Merge the two curves. Use SGPLOT to overlay the two curves:

*Make example dataset;
data test ( keep = anemia allergy weight visit );
 set sashelp.bweight;
 if _N_ <= 100;
 anemia = black;
 allergy = married;
run;

*Outcome = ANEMIA;
proc logistic data = test descending;
 model anemia = weight visit / outroc=ROC1;
 run; quit;
*Outcome = ALLERGY;
proc logistic data = test descending;
 model allergy = weight visit / outroc=ROC2;
run; quit;

/* merge in the population ROC curve */
data ROCAll;
   set ROC1(in=r1) ROC2;
   if r1 then Model=1;
   else Model = 2;
run;

title "Compare ROC Curves for Different Models";
proc sgplot data=ROCAll aspect=1 noautolegend;
   step x=_1MSPEC_ y=_SENSIT_ / group=Model;
   lineparm x=0 y=0 slope=1 / lineattrs=(color=gray);
   xaxis grid;   yaxis grid;
   label _1MSPEC_ ="False Positive Rate (FPR)" _SENSIT_ ="True Positive Rate (TPR)";
run;
bkq32
Quartz | Level 8
Thank you, both!
Ksharp
Super User
data test ( keep = anemia allergy weight visit );
 set sashelp.bweight;
 if _N_ <= 100;
 anemia = black;
 allergy = married;
run;





ods select none;
*Outcome = ANEMIA;
proc logistic data = test descending  ;
 model anemia = weight visit/outroc=roc1;
 ods output Association=Association1;
run;
*Outcome = ALLERGY;
proc logistic data = test descending  ;
 model allergy = weight visit/outroc=roc2;
 ods output Association=Association2;
run; 
ods select all;






proc sql noprint;
select cValue2 into :auc1 from Association1 where Label2='c';
select cValue2 into :auc2 from Association2 where Label2='c';
quit;
data roc;
 set roc1 roc2 indsname=dsn;
 model=scan(dsn,-1,'.');
run;
proc sgplot data=roc aspect=1;
series x=_1MSPEC_ y=_SENSIT_/group=model;
lineparm x=0 y=0 slope=1/lineattrs=(color=verylightgray);
xaxis grid valuesformat=F8.2;
yaxis grid valuesformat=F8.2;
inset "ROC1=&auc1." "ROC2=&auc2.";
run;

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!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1107 views
  • 2 likes
  • 3 in conversation