![]() | ![]() | ![]() | ![]() | ![]() |
| Contents: | Purpose / History / Requirements / Usage / Details / Limitations / Missing Values / See Also / References |
| Version | Update Notes |
| 1.7 | Fixed row labeling when CONTRAST= option is specified. |
| 1.6 | Removed computation of estimated correlations to avoid problems with use of intercept-only model. Fix to automatic check for new version. |
| 1.5 | Fixed subscript error in RNAME with 15 or more data sets and XBETA variables. Added automatic check for new version. |
| 1.4 | Corrected errors with default contrast and only one variable specified in VAR=. The single area is now estimated and tested. |
| 1.3 | Added confidence intervals for each area. Added ALPHA= parameter to control confidence level. Default contrasts are now all pairwise differences. Added table of confidence intervals and tests of each contrast row. |
| 1.2 | Put original author's code in macro form. Allow input of several data sets to compare several models which may each have multiple predictors. Default contrast set generated. Added DETAILS= parameter to minimize default output. Creates macro variable with overall p-value. |
%inc "<location of your file containing the ROC macro>";
Following this statement, you may call the %ROC macro. See the Results tab for examples.
You must first run the LOGISTIC procedure to fit each of the the models whose ROC curves are to be compared. Each model must be fit to exactly the same data set (with observations in the same order) and they must all be fit to the same response variable. The ROC macro requires that the response variable have only values of 0 and 1 even though this is not a restriction necessary for PROC LOGISTIC. Use the XBETA= or PRED= option in the OUTPUT statement in each run of LOGISTIC. The output data set names must be unique. Since the XBETA= or PRED= output variables are used to identify and compare the models' ROC curves, the names must be unique and it is recommended that you select a name for each variable that adequately identifies the fitted model.
The following macro parameters can be specified. The DATA, VAR=, and RESPONSE= parameters are required.
%str(). An L
matrix with
more than one row may be specified by using commas to separate the rows
of coefficients. If omitted, a default contrast testing the equality of
all ROC curve areas jointly and pairwise is used.
The version of the %ROC macro that you are using is displayed when you specify version (or any string) as the first argument. For example:
%roc(version, data=a b, var=xba xbb, response=y)
The ROC macro assigns a name to each table it creates. You can use these names to reference the table when using the Output Delivery System (ODS) to select or exclude tables and to create output data sets. The table names are listed in the following table along with any macro parameters required to make the table available. When outputting a table to a data set, you can determine the names of variables in the data set by using PROC CONTENTS.
| ODS table name | Description | %ROC macro option |
| T | Pairwise deletion Mann-Whitney Statistics | DETAILS=yes |
| V | Estimated Variance Matrix | DETAILS=yes |
| NX | X populations sample sizes | DETAILS=yes |
| NY | Y populations sample sizes | DETAILS=yes |
| L | Coefficients of Contrast | default |
| LT | Estimates of Contrast | default |
| LV | Variance Estimates of Contrast | DETAILS=yes |
| AREASTAB | ROC Area Std Error Confidence Limits | default |
| DIFFSTAB | Tests and 100(1-α)% Confidence Intervals for Contrast Rows | default |
| CTEST | Contrast Test Results | default |
In addition to displayable output, the ROC macro creates a macro variable, pvalue, containing the p-value from the test of joint equality of ROC curve areas.
The %ROC macro attempts to check for a later version of itself. If it is unable to do this (such as if there is no active internet connection available), the macro will issue the following message:
ROC: Unable to check for newer version
The computations performed by the macro are not affected by the appearance of this message.
Puri M.L and Sen P.K. (1971), Nonparametric Methods in Multivariate Analysis, Wiley.
Each ROC curve is plotted separately with labels and a final joint plot of all curves is produced. Statistical tests of the equality of the areas under all three curves and pairwise comparisons among the curves are given along with point and confidence interval estimates.
Before running this example, be sure to define both the %ROC and %ROCPLOT macros.
/* Define the ROC macro */
%include "<path to your copy of the ROC macro>";
/* Define the ROCPLOT macro */
%include "<path to your copy of the ROCPLOT macro>";
data roc;
input alb tp totscore popind;
totscore = 10 - totscore;
datalines;
3.0 5.8 10 0
3.2 6.3 5 1
3.9 6.8 3 1
2.8 4.8 6 0
3.2 5.8 3 1
0.9 4.0 5 0
2.5 5.7 8 0
1.6 5.6 5 1
3.8 5.7 5 1
3.7 6.7 6 1
. . 6 1
3.2 5.4 4 1
3.8 6.6 6 1
4.1 6.6 5 1
3.6 5.7 5 1
4.3 7.0 4 1
3.6 6.7 4 0
2.3 4.4 6 1
4.2 7.6 4 0
4.0 6.6 6 0
3.5 5.8 6 1
3.8 6.8 7 1
3.0 4.7 8 0
4.5 7.4 5 1
3.7 7.4 5 1
3.1 6.6 6 1
4.1 8.2 6 1
4.3 7.0 5 1
4.3 6.5 4 1
3.2 5.1 5 1
2.6 4.7 6 1
3.3 6.8 6 0
1.7 4.0 7 0
. . 6 1
3.7 6.1 5 1
3.3 6.3 7 1
4.2 7.7 6 1
3.5 6.2 5 1
2.9 5.7 9 0
2.1 4.8 7 1
. . 8 1
2.8 6.2 8 0
. . 7 1
. . 7 1
4.0 7.0 7 1
3.3 5.7 6 1
3.7 6.9 5 1
2.0 . 7 1
3.6 6.6 5 1
;
/* Albumin */
title "ROC plot for Albumin";
proc logistic data=roc;
model popind(event='1') = alb / outroc=or roceps=0;
output out=albpred p=palb;
ods output association=assoc;
run;
data _null_;
set assoc;
if label2='c' then call symput("area",cvalue2);
run;
title2 "Approximate area under curve = &area";
%rocplot(out=albpred, outroc=or, p=palb, id=alb)
title2;
data joint;
set _rocplot;
length index $ 13;
Index='Albumin';
run;
/* Total Protein */
title "ROC plot for Total Protein";
proc logistic data=roc;
model popind(event='1') = tp / outroc=or roceps=0;
output out=tppred p=ptp;
ods output association=assoc;
run;
data _null_;
set assoc;
if label2='c' then call symput("area",cvalue2);
run;
title2 "Approximate area under curve = &area";
%rocplot(out=tppred, outroc=or, p=ptp, id=tp)
title2;
data tp;
set _rocplot;
length index $ 13;
Index='Total Protein';
run;
data joint;
set joint tp;
run;
/* K-G score */
title "ROC plot for K-G score";
proc logistic data=roc;
model popind(event='1') = totscore / outroc=or roceps=0;
output out=totspred p=ptots;
ods output association=assoc;
run;
data _null_;
set assoc;
if label2='c' then call symput("area",cvalue2);
run;
title2 "Approximate area under curve = &area";
%rocplot(out=totspred, outroc=or, p=ptots, id=totscore)
title2;
data kg;
set _rocplot;
length index $ 13;
Index='K-G Score';
run;
data joint;
set joint kg;
run;
/* Compare areas under the ROC curves of the indices using the method presented
in DeLong, et. al. (1988).
*/
%roc(data=albpred tppred totspred,
var=palb ptp ptots,
response=popind)
/* Plot all indices and p-value of overall test comparing areas */
symbol1 i=join v=circle c=blue line=33;
symbol2 i=join v=dot c=green line=1;
symbol3 i=join v=triangle c=red line=4;
proc gplot data=joint;
title "Post-Op Indices of surgical success";
title2 "Test of H0: equal areas under curves -- p=&pvalue";
footnote "From DeLong, et. al. (1988, Biometrics 44)";
label index="Index";
plot _sensit_ * _1mspec_ = Index /
vaxis=0 to 1 by .1 haxis=0 to 1 by .1;
run;
quit;
title;
title2;
footnote;
For brevity, the PROC LOGISTIC results are not shown. The following plots are generated by the %ROCPLOT macro:
Following are the results of the %ROC macro.
Three models are fit and their ROC curve areas tested for equality. A significant finding is followed by pairwise comparisons.
data wallet;
input wallet male business punish explain @@;
if wallet in (1,2) then wallet=0;
if wallet=3 then wallet=1;
datalines;
2 0 0 2 0 3 0 0 1 1 3 1 0 1 1 2 0 1 1 1 3 1 0 1 1
2 0 0 2 1 3 0 0 1 1 3 0 0 1 1 1 0 0 3 0 2 1 0 1 0
3 0 0 1 1 3 0 0 1 1 3 0 1 1 1 1 0 1 2 0 3 0 1 2 1
3 0 0 2 0 3 0 0 2 0 3 0 0 1 1 3 0 0 1 1 2 1 1 2 1
1 1 0 1 1 3 1 1 1 1 3 0 0 1 1 3 0 0 1 1 3 0 0 1 1
3 0 0 1 1 3 1 0 1 1 3 0 0 2 1 3 0 0 1 1 1 1 0 1 1
3 0 0 1 1 3 0 0 1 1 2 1 1 1 0 3 1 1 1 1 3 1 1 3 1
3 1 0 1 1 3 0 0 1 1 3 1 0 1 1 3 0 0 1 0 2 1 0 1 1
3 1 0 1 1 3 0 0 1 0 3 0 0 1 1 3 0 0 1 1 1 0 0 1 0
3 0 0 2 1 3 0 1 3 0 2 1 1 1 1 3 1 0 1 1 2 1 0 3 0
2 0 1 1 1 3 1 0 2 0 3 0 0 1 1 3 1 1 1 1 3 0 0 1 1
3 1 1 1 1 2 0 0 2 1 3 1 1 1 1 3 1 0 1 1 2 1 1 1 1
3 1 0 1 1 3 0 0 1 1 3 0 0 1 1 2 1 1 1 1 3 0 0 1 1
3 1 0 1 1 3 1 0 1 1 3 0 0 1 1 2 0 0 1 0 2 0 0 2 0
3 0 0 1 1 3 1 0 1 1 3 0 0 1 1 3 0 0 1 1 2 1 0 1 1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 0 1 1 3 0 0 1 1 3 0 0 1 1
3 0 0 2 0 2 1 0 1 1 3 0 0 1 1 3 1 0 1 1 3 1 1 1 1
3 0 0 1 1 3 0 0 1 0 1 1 0 3 0 2 1 1 1 0 3 1 0 1 1
3 1 0 1 1 3 1 1 1 1 2 1 0 1 1 3 0 0 1 1 2 1 0 1 1
;
/* Fit three models to the Pr(return wallet) */
proc logistic data=wallet;
model wallet(event="1") = male business punish explain;
output out=w1 xbeta=mbpe;
run;
proc logistic data=wallet;
model wallet(event="1") = business punish explain;
output out=w2 xbeta=bpe;
run;
proc logistic data=wallet;
model wallet(event="1") = business punish ;
output out=w3 xbeta=bp;
run;
/* Test equality of the three ROC curve areas. */
%roc(data=w1 w2 w3,
response=wallet,
var=mbpe bpe bp)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
proc logistic data=wallet;
model wallet(event="1") = ;
output out=w4 xbeta=int;
run;
%roc(data=w3 w4,
response=wallet,
var=bp int)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Right-click on the link below and select Save to save
the %ROC macro definition
to a file. It is recommended that you name the file
roc.sas.
| Type: | Sample |
| Topic: | SAS Reference ==> Procedures ==> IML Analytics ==> Regression Analytics ==> Matrix Programming SAS Reference ==> Procedures ==> LOGISTIC Analytics ==> Descriptive Statistics |
| Date Modified: | 2007-08-14 03:03:08 |
| Date Created: | 2005-01-13 15:03:44 |
| Product Family | Product | Host | SAS Release | |
| Starting | Ending | |||
| SAS System | SAS/STAT | All | 8 TS M0 | n/a |
| SAS System | SAS/IML | All | 8 TS M0 | n/a |





