The LOGISTIC Procedure

Example 79.19 Goodness-of-Fit Tests and Calibration

(View the complete code for this example.)

The following data were originally published by Mroz (1987) and downloaded from Wooldridge (2002). This data set is based on a sample of 753 married white women. The dependent variable is a discrete variable of labor force participation (InLaborForce). Explanatory variables are the number of children age 5 or younger (KidsLt6); the number of children ages 6 to 18 (KidsGe6); the woman’s age (Age); the woman’s years of schooling (Education); the wife’s labor experience (Experience); the square of experience (SqExperience); and the family income, excluding the wife’s wages (IncomeExcl).

data Mroz;
   input InLaborForce IncomeExcl Education Experience
         SqExperience Age KidsLt6 KidsGe6 lWage;
   datalines;
1 10.91006    12 14  196   32  1   0   1.210154
1 19.49998    12 5   25    30  0   2   0.3285121

   ... more lines ...   

0 9.952       12 4   16    43  0   0   .
0 24.984      12 15  225   60  0   0   .
0 28.363      9  12  144   39  0   3   .
;

The following program sets aside about 30% of the data set to be used for testing the model. To do this, a new response variable, InLaborForce2, is set to missing for the test data; otherwise it is set to the original value of InLaborForce.

data Mroz;
   set Mroz;
   if (ranuni(3939)<.3) then InLaborForce2=.;
   else InLaborForce2=InLaborForce;
run;

In the following statements, the GOF option modifies the "Model Fitting Statistics" table by displaying a single column with more statistics in Output 79.19.1, displays more tests in the "Goodness-of-Fit" table, displays the results of the Hosmer-Lemeshow test, and displays a calibration plot because ODS Graphics is enabled. The SHOWOBS option modifies the calibration plot by displaying a bar chart of the events in the upper margin of the plot and a bar chart of the nonevents in the bottom margin. The CLM option displays confidence intervals for the mean loess fit as a band around the loess curve. The OUTPUT statement creates a data set that contains the linear predictors and the original InLaborForce variable.

ods graphics on;
proc logistic data=Mroz plots=calibration(clm showobs);
   model InLaborForce2 = IncomeExcl Education Experience
                         SqExperience Age KidsLt6 KidsGe6  / gof;
   id InLaborForce;
   output out=Scored xbeta=XBeta;
run;

Because of the continuous predictors, the Pearson and deviance tests in Output 79.19.1 cannot be trusted. However, all the other tests remain valid and do not reject the null hypothesis that the fit is adequate.

Output 79.19.1: Goodness-of-Fit Tests

Goodness-of-Fit Tests
Criterion Value DF Pr > ChiSq
Deviance 606.5035 544 0.0324
Pearson 538.4877 544 0.5586
Information Matrix 38.2455 35 0.3243
Information Matrix Diagonal 11.4027 8 0.1799
Osius and Rojek 0.8412 1 0.3590
Residual Sum of Squares 1.3502 1 0.2453
Spiegelhalter 0.0201 1 0.8871
Stukel 2.2581 2 0.3233

Number of unique profiles: 552



The "Model Fit Statistics" table displays an assortment of statistics in Output 79.19.2 that are most useful when you compare this model to other models. The misclassification rate and the average square error are of moderate size.

Output 79.19.2: Model Fit Statistics

Model Fit Statistics
Criterion Value
AIC 622.5035
AICC 622.7687
SC 657.0119
-2 Log L 606.5035
-2 Log L (Intercept-Only) 755.2843
Misclassification Rate 0.2754
Average Square Error 0.1862
R-Square 0.2363
Max-rescaled R-Square 0.3169
Aldrich-Nelson's R-Square 0.2123
Efron's R-Square 0.2417
Estrella's R-Square 0.2593
Estrella's Adjusted R-Square 0.2324
McFadden's R-Square 0.1970
Tjur's R-Square 0.2440
Veall-Zimmerman's R-Square 0.3675


The Hosmer-Lemeshow test is computed using 10 groups for an 8-degrees-of-freedom chi-square test, and you do not reject the null hypothesis that the fit is adequate. The results are shown in Output 79.19.3.

Output 79.19.3: Hosmer-Lemeshow Test

Partition for the Hosmer and Lemeshow Test
Group Total InLaborForce2 = 0
InLaborForce2 = 1
Observed Expected Observed Expected
1 55 3 5.22 52 49.78
2 55 10 9.12 45 45.88
3 55 10 12.24 45 42.76
4 55 20 15.85 35 39.15
5 55 24 19.39 31 35.61
6 55 17 23.44 38 31.56
7 55 36 28.84 19 26.16
8 55 30 34.31 25 20.69
9 55 40 41.02 15 13.98
10 57 49 49.58 8 7.42

Hosmer and Lemeshow Goodness-of-Fit
Test
Chi-Square DF Pr > ChiSq
13.2967 8 0.1020


The calibration plot in Output 79.19.4 shows you how well the predicted probabilities align with the observed responses. The smoothing parameter that the procedure selects seems rather small; you can change the smoothing parameter for the loess fit by specifying the PLOTS=CALIBRATION(SMOOTH=) option. The confidence band is not a simultaneous band, so you cannot use the fact that the band does or does not contain the diagonal line as a calibration test. The displayed Spiegelhalter z statistic is a standard normal; its squared value is reported in Output 79.19.1.

Output 79.19.4: Calibration Plot for Training Model

Calibration Plot for Training Model


Now that the model has been fit to the training data, refit the testing data by using the original response variable versus the linear predictor (Harrell 2015). Ideally, the intercept parameter should be near 0, and the slope parameter should be near 1. In the following statements, the WHERE data set option extracts the test data from the Scored data set, and the TEST statement performs a Wald test of this joint hypothesis. The calibration plot of this fit should also be close to the diagonal.

proc logistic data=Scored(where=(InLaborForce2=.))
              plots=calibration(clm showobs);
   model InLaborForce = XBeta;
   test intercept = 0, XBeta = 1;
run;

The TEST result in Output 79.19.5 shows that you do not reject the null that the intercept parameter is 0 and the slope parameter is 1.

Output 79.19.5: Calibration Test for Test Data

Linear Hypotheses Testing Results
Label Wald
Chi-Square
DF Pr > ChiSq
Test 1 2.7568 2 0.2520



The calibration plot displayed in Output 79.19.6 follows the diagonal quite well.

Output 79.19.6: Calibration Plot for Test Data

Calibration Plot for Test Data


Last updated: December 09, 2022