The performance of models on binary response data can be evaluated using the ASSESS procedure in SAS® Viya®. Several procedures in SAS® Visual Statistics can be used to model a binary response including LOGSELECT, TREESPLIT, SUPERLEARNER and others. PROC ASSESS can also be used to evaluate binary response models fit by SAS/STAT® procedures such as GENMOD, PROBIT, GAMPL, and others.
One of the most commonly used summaries of a model's performance is the Receiver Operating Characteristic (ROC) curve and the area under the ROC curve (AUC). After fitting the model in one of these procedures, you can save the observed responses and predicted probabilities in a data set. This is typically done using the OUTPUT statement in the modeling procedure. The ASSESS procedure can then process this data and save the data for the ROC curve using the ROCOUT= option in the PROC ASSESS statement. While PROC ASSESS does not directly produce a plot of the ROC curve, you can create it from the ROCOUT= data set as shown in the example below.
The ROC curve of a highly predictive model bends upward and approaches the upper-left corner of the unit square in which it is appears. On the other hand, the curve for an uninformative, nonpredictive model falls on or near the diagonal line from lower-left to upper-right. A summary measure is therefore the AUC, which is close to 1 for a highly predictive model and near 0.5 for an uniformative model.
Each point on the ROC curve corresponds to a cutpoint value on the predicted event probabilities that divides the observations into predicted events and nonevents. For each such cutpoint, many statistics can be computed from the 2×2 table of observed by predicted responses that the cutpoint creates. These include sensitivity and specificity, which locate the cutpoint on the ROC curve. The OUTROC= data set also includes measures that can be used to identify cutpoints that are optimal for classifying observations as events or nonevents. There are several measures that use different optimality criteria and can therefore identify different cutpoints as optimal.
To simplify production of the ROC plot and identification of optimal points, the necessary code is packaged in a macro called ROCCURVE. Click ROCCURVE to download the code that defines the macro. You can then run this code in your SAS® session by submitting the following %INCLUDE statement, substituting the path to the downloaded code.
%include "path/roccurve.sas";
Usage of the ROCCURVE macro is discussed and illustrated below. Note that PROC LOGISTIC can be an alternative to using PROC ASSESS and the ROCCURVE macro. In SAS® Viya®, PROC LOGISTIC can directly produce the ROC curve of a model fit by that procedure or of a model fit by another procedure. For more information, see SAS KB0058665 and SAS KB0057389. PROC LOGISTIC provides additional optimality criteria such as the Youden criterion, multiple ways of labeling cutpoints, and alternative methods for estimating the ROC curve.
Plots of other model evaluating statistics, such as lift and gain, are also used in some fields. These are discussed in SAS KB0060503.
The following statements use the home equity data in the SAMPSIO.HMEQ data set. The binary response, BAD, indicates delinquency of the loan (1=delinquent; 0=not). The following statements use PROC LOGSELECT to fit a logistic model to the response after starting a CAS session in SAS Viya and creating a CAS libref called SASCAS1. LASSO model selection is used to select predictive variables to keep in the model. The OUTPUT statement saves a data set containing the predicted probabilities of the event (delinquency) and nonevent. The COPYVAR= option also saves the response variable.
This data set is then used by PROC ASSESS to compute the ROC statistics, which are saved in a data set by the ROCOUT= option. The TARGET statement identifies the response variable. The EVENT= option specifies the response value of interest representing the event. The LEVEL=NOMINAL option indicates that the response is binary. The VAR statement identifies the variable that contains the predicted event probabilities.
The ROCCURVE macro is then called to plot the ROC curve and display the AUC. The macro uses the last created data set by default, which is the SASCAS1.LOGROC data set from PROC ASSESS. To use a data set that is not the last created, specify data=data-set-name in the macro:
data sascas1.hmeq;
set sampsio.hmeq;
run;
proc logselect data=sascas1.hmeq association;
model bad(event='1') = loan value mortdue yoj derog
delinq clage ninq clno;
selection method=lasso details=all;
output out=sascas1.logout predprobs copyvar=bad;
run;
proc assess data=sascas1.logout rocout=sascas1.logroc;
var _pred_1;
target bad / event="1" level=nominal;
run;
%roccurve()
The ROC curve has an AUC of about 0.8 indicating good predictive ability:
By including optimal=yes in the macro call, optimal cutoints on the ROC curve are identified using the four available optimality criteria: F1, F0.5, Accuracy, and KS (Kolmogorov-Smirnov). Accuracy is the correct classification rate. KS measures the separation between the distributions of events and nonevents, so the optimal KS cutpoint is the point that best separates the two responses. F1 and F0.5 are measures that combine precision (or positive predictive value (PPV), the proportion of predicted events that are true events) and sensitivity (or recall, the proportion of true events that are predicted as events) with different weighting. F1 weights them equally; F0.5 weights precision more than sensitivity. For details, see SAS Note 24170. A cutpoint is considered optimal on each of these criteria if it has the maximum criterion value across all cutpoints. For each criterion, the achieved maximum value (Max) and the cutpoint value (PProb) are displayed in the plot. By including response=bad in the macro call, the response name is added in the plot title:
%roccurve(response=bad, optimal=yes)
The ROC plot identifying optimal cutpoints follows. Essentially, two optimal cutpoints are found. Under the F1 and KS criteria, the cutpoint at predicted event probability 0.22 is optimal. A cutpoint of about 0.43 or 0.45 satisfies the accuracy and F0.5 criteria:
The following statements use the GAMSELECT and ASSESS procedures to fit a GAM to the data and generate assessment data. The shrinkage method is used to select the best model. The ROCCURVE macro is again used to display the ROC curve of the fitted model and the optimal points on that curve:
proc gamselect data=sascas1.hmeq;
model bad(event='1') = param(derog delinq ninq) spline(loan)
spline(yoj) spline(clage) spline(clno) / dist=binary;
selection method=shrinkage;
output out=sascas1.gamout pred copyvar=bad;
run;
proc assess data=sascas1.gamout rocout=sascas1.gamroc;
var pred;
target bad / event="1" level=nominal;
run;
%roccurve(response=bad (GAM), optimal=yes)
The fitted GAM model, which includes flexible splines for several predictors, performs slightly better than the ordinary logistic model as evidenced by the larger AUC – 0.8263 as compared to 0.8059 for the logistic model. Similar, but slightly different, optimal cutpoints are identified.
You can produce a comparison plot that shows both ROC curves using PROC SGPLOT directly as shown below. The code could be extended to accommodate ROC data from additional models.
data loggam;
set sascas1.logroc (in=log) sascas1.gamroc (in=gam);
if log then do;
Model="Logistic";
call symputx("auc1",put(_c_,6.4));
end;
if gam then do;
Model="GAM";
call symputx("auc2",put(_c_,6.4));
end;
run;
proc sgplot data=loggam aspect=1;
xaxis values=(0 to 1 by 0.25) grid
offsetmin=.05 offsetmax=.05 label="1-Specificity";
yaxis values=(0 to 1 by 0.25) grid
offsetmin=.05 offsetmax=.05;
lineparm x=0 y=0 slope=1 / transparency=.7
lineattrs=(color=gray);
series x=_fpr_ y=_sensitivity_ / group=model;
inset ("AUC Logistic" = "&auc1"
"AUC GAM" = "&auc2") /
opaque position=bottomright;
title "ROC Curves";
run;
Note the slight superiority of the GAM ROC curve: