Tjur (2009) proposed a goodness of fit statistic for binary logistic models which he calls the coefficient of discrimination, D. D is the difference in the average of the event probabilities between the groups of observations with observed events and nonevents. The Kolmogorov-Smirnov (KS) test is also used to assess the difference between event and nonevent groups. Both of these statistics are discussed below.
These are the properties of D according to Tjur (2009):
Beginning in SAS® 9.4M6, Tjur's statistic is available in PROC LOGISTIC with the GOF option in the MODEL statement. It is also available in PROC HPLOGISTIC when using the PARTITION statement and can easily be computed by PROC TTEST.
In this example used by Tjur, a logistic model is fitted to low birth weight data from Baystate Medical Center in Springfield, MA. These data are presented and analyzed in Hosmer and Lemeshow (2000) and in other places. The following statements fit the model. The GOF option produces a variety of R2 measures and other fit statistics and tests including Tjur's statistic, which is labeled "Tjur's R-Square". The ROC statement fits an intercept-only (naive, uninformative) model to which the fitted model is compared by the ROCCONTRAST statement to provide a test of the discriminatory power of the model. The OUTPUT statement creates a data set (OUT) with a variable (P) that contains the predicted event probabilities:
proc logistic data=lbw; class race; model low(event="1") = age lwt race smoke / gof; roc "Naive"; roccontrast; output out=out p=p; run;
The test from the ROCCONTRAST statement that compares the fitted and naive models shows that the model has significant discriminatory power (chi-square = 21.9010, p < .0001). A popular measure of the discriminatory power of a logistic model, the area under the ROC curve (AUC), is 0.6837 with confidence interval (0.61, 0.76). The AUC ranges from 0.5 for the naive model to 1 for a perfectly discriminating model. The c statistic is also known as the concordance index and is an estimate of the probability of concordance for a pair of observations. For more on concordance and the concordance index, see "Model Fitting Information" in the Details section of the LOGISTIC documentation.
The statistic labeled "R-Square," which is the Cox-Snell statistic mentioned by Tjur on page 371, is 0.1009, and Nagelkerke's adjusted R2 (labeled "Max rescaled R-Square") is 0.1418. Note that R-Square cannot be interpreted as the "proportion of variation explained" as in linear regression with ordinary least squares. In the context of logistic regression, it is most useful as a measure for comparing competing models. Several other R2 measures are provided. See "Model Fitting Information" in the Details section of the LOGISTIC documentation. The GOF option also displays several fit tests (not shown) that are discussed in "Goodness of fit" in the Details section of the LOGISTIC documentation. These tests are useful even with relatively sparse data.
In PROC HPLOGISTIC, the PARTITION statement is required to produce Tjur's statistic. However, if partitioning of the data is not needed, it can be avoided by specifying zero-sized test and validation partitions as shown below. In this way, all of the data is retained in the training data set. For the example above, the following statements produce the coefficient of discrimination which is labeled as the "Mean Difference" in the "Partition Fit Statistics" table. Several other fit statistics are also presented.
proc hplogistic data=lbw; class race; model low(event="1") = age lwt race smoke; partition fraction(test=0 validate=0); run;
The Tjur statistic is the difference in the average event probabilities of the two response groups. Consequently, it can also be produced using the TTEST procedure. The following statements produce the statistic. Since LOW=1 represents the event and this level appears after the LOW=0 level in the data, the following PROC SORT step reverses this order. Specifying the ORDER=DATA option uses the new order so that TTEST computes the event mean minus the nonevent mean. The PLOTS=SUMMARY option displays a comparative histogram plot of the two response levels:
proc sort data=out; by descending low; run; proc ttest data=out plots=summary order=data; class low; var p; run;
Note the change in the distribution averages from 0.28 for LOW=0 to 0.38 for LOW=1 and that the difference is the Tjur statistic reported above by the LOGISTIC and HPLOGISTIC procedures:
Another example of computing Tjur's statistic can be found in Allison (2012).
Nonparametric tests of the location shift between the two distributions of predicted event probabilities are available in PROC NPAR1WAY. The Kolmogorov-Smirnov (KS) test is sometimes proposed to test for differences in the two distribution functions and thereby test if the logistic model separates (discriminates between) the two responses. This test is provided by the KS (or EDF) option. However, the KS test rejects equality of the two distributions for any difference such as a shape difference, not just a shift in location which is of primary interest. Since the Wilcoxon test concentrates its power on detecting location shift it may be more suitable. The area under the ROC curve is related to the Wilcoxon statistic. The WILCOXON option provides this test.
proc npar1way data=out wilcoxon ks; class low; var p; run;
In the results below, both tests detect a significant difference in the two distributions (p < .0001). A plot of the empirical distribution functions (not shown) provides another visual comparison of the two distributions, but the comparative histogram above is better at showing the shift in location.
The KS statistic, and the related two-sample statistic also called D, measures the distance between the two response level distributions of predicted event probabilities. KS and D can be computed for each observation or for any set of probability values. The KS test results indicate that observation 20 in the input data set has predicted event probability 0.3218 and is the point of maximum difference between the distributions yielding D = 0.3473. This probability value is sometimes treated as an optimal point on the ROC curve for use as a cutpoint for classifying observations as predicted events or nonevents.
In SAS® Viya®, the ASSESS procedure uses the saved data set of predicted probabilities from the model to compute the D statistic at 100 probability values 0, 0.01, 0.02, ... , 0.99, 1. After starting a CAS session in SAS Viya and creating a CAS libref called SASCAS1, the ROCOUT= option in the following PROC ASSESS step produces a data set that contains several statistics related to the ROC curve for the model, including values on various optimality criteria such as the KS statistic. The variable _KS2_ contains the D statistic value for each of the 100 probability values, and _KS_ is an indicator variable that equals 1 in the observation with the maximum D value and 0 otherwise.
data sascas1.logout; set out; run; proc assess data=sascas1.logout rocout=sascas1.logroc; var p; target low / event="1" level=nominal; run;
As discussed in SAS KB0060666, the ROCCURVE macro can be used to plot the ROC curve and identify points on the curve that are optimal under the various optimality criteria provided by PROC ASSESS:
%roccurve(optimal=yes)
Among the other optimal points, the optimal point on the KS criterion is shown in the plot below to occur at probability 0.32 where D = 0.3319. Of the 100 probability values evaluated by PROC ASSESS, 0.32 is the closest to probability value 0.321792 in observation 20 where D = 0.3473 as shown in the NPAR1WAY results above.
_____
Tjur, T. (2009), "Coefficients of Determination in Logistic Regression Models – A New Proposal: The Coefficient of Discrimination," The American Statistician, 63(4), 366-372.