The LOGISTIC Procedure

Example 74.1 Stepwise Logistic Regression and Predicted Values

(View the complete code for this example.)

Consider a study on cancer remission (Lee 1974). The data consist of patient characteristics and whether or not cancer remission occurred. The following DATA step creates the data set Remission containing seven variables. The variable remiss is the cancer remission indicator variable with a value of 1 for remission and a value of 0 for nonremission. The other six variables are the risk factors thought to be related to cancer remission.

data Remission;
   input remiss cell smear infil li blast temp;
   label remiss='Complete Remission';
   datalines;
1   .8   .83  .66  1.9  1.1     .996
1   .9   .36  .32  1.4   .74    .992
0   .8   .88  .7    .8   .176   .982
0  1     .87  .87   .7  1.053   .986
1   .9   .75  .68  1.3   .519   .98
0  1     .65  .65   .6   .519   .982
1   .95  .97  .92  1    1.23    .992
0   .95  .87  .83  1.9  1.354  1.02
0  1     .45  .45   .8   .322   .999
0   .95  .36  .34   .5  0      1.038
0   .85  .39  .33   .7   .279   .988
0   .7   .76  .53  1.2   .146   .982
0   .8   .46  .37   .4   .38   1.006
0   .2   .39  .08   .8   .114   .99
0  1     .9   .9   1.1  1.037   .99
1  1     .84  .84  1.9  2.064  1.02
0   .65  .42  .27   .5   .114  1.014
0  1     .75  .75  1    1.322  1.004
0   .5   .44  .22   .6   .114   .99
1  1     .63  .63  1.1  1.072   .986
0  1     .33  .33   .4   .176  1.01
0   .9   .93  .84   .6  1.591  1.02
1  1     .58  .58  1     .531  1.002
0   .95  .32  .3   1.6   .886   .988
1  1     .6   .6   1.7   .964   .99
1  1     .69  .69   .9   .398   .986
0  1     .73  .73   .7   .398   .986
;

The following invocation of PROC LOGISTIC illustrates the use of stepwise selection to identify the prognostic factors for cancer remission. A significance level of 0.3 is required to allow a variable into the model (SLENTRY=0.3), and a significance level of 0.35 is required for a variable to stay in the model (SLSTAY=0.35). A detailed account of the variable selection process is requested by specifying the DETAILS option. The Hosmer and Lemeshow goodness-of-fit test for the final selected model is requested by specifying the LACKFIT option. The OUTEST= and COVOUT options in the PROC LOGISTIC statement create a data set that contains parameter estimates and their covariances for the final selected model. The response variable option EVENT= chooses remiss=1 (remission) as the event so that the probability of remission is modeled. The OUTPUT statement creates a data set that contains the cumulative predicted probabilities and the corresponding confidence limits, and the individual and cross validated predicted probabilities for each observation. The ODS OUTPUT statement writes the "Association" table from each selection step to a SAS data set.

title 'Stepwise Regression on Cancer Remission Data';
proc logistic data=Remission outest=betas covout;
   model remiss(event='1')=cell smear infil li blast temp
                / selection=stepwise
                  slentry=0.3
                  slstay=0.35
                  details
                  lackfit;
   output out=pred p=phat lower=lcl upper=ucl
          predprob=(individual crossvalidate);
   ods output Association=Association;
run;
proc print data=betas;
   title2 'Parameter Estimates and Covariance Matrix';
run;
proc print data=pred;
   title2 'Predicted Probabilities and 95% Confidence Limits';
run;

In stepwise selection, an attempt is made to remove any insignificant variables from the model before adding a significant variable to the model. Each addition or deletion of a variable to or from a model is listed as a separate step in the displayed output, and at each step a new model is fitted. Details of the model selection steps are shown in Outputs Output 74.1.1 through Output 74.1.5.

Prior to the first step, the intercept-only model is fit and individual score statistics for the potential variables are evaluated (Output 74.1.1).

Output 74.1.1: Startup Model

Stepwise Regression on Cancer Remission Data

The LOGISTIC Procedure


Step 0. Intercept entered:

Model Convergence Status
Convergence criterion (GCONV=1E-8) satisfied.

-2 Log L=34.372

Analysis of Maximum Likelihood Estimates
ParameterDFEstimateStandard
Error
Wald
Chi-Square
Pr > ChiSq
Intercept1-0.69310.40822.88270.0895

Residual Chi-Square Test
Chi-SquareDFPr > ChiSq
9.460960.1493

Analysis of Effects Eligible for
Entry
EffectDFScore
Chi-Square
Pr > ChiSq
cell11.88930.1693
smear11.07450.2999
infil11.88170.1701
li17.93110.0049
blast13.52580.0604
temp10.65910.4169


In Step 1 (Output 74.1.2), the variable li is selected into the model because it is the most significant variable among those to be chosen (). The intermediate model that contains an intercept and li is then fitted. li remains significant () and is not removed.

Output 74.1.2: Step 1 of the Stepwise Analysis


Step 1. Effect li entered:

Model Convergence Status
Convergence criterion (GCONV=1E-8) satisfied.

Model Fit Statistics
CriterionIntercept OnlyIntercept and
Covariates
AIC36.37230.073
SC37.66832.665
-2 Log L34.37226.073

Testing Global Null Hypothesis: BETA=0
TestChi-SquareDFPr > ChiSq
Likelihood Ratio8.298810.0040
Score7.931110.0049
Wald5.959410.0146

Analysis of Maximum Likelihood Estimates
ParameterDFEstimateStandard
Error
Wald
Chi-Square
Pr > ChiSq
Intercept1-3.77711.37867.50640.0061
li12.89731.18685.95940.0146

Odds Ratio Estimates
EffectPoint Estimate95% Wald
Confidence Limits
li18.1241.770185.563

Association of Predicted Probabilities and
Observed Responses
Percent Concordant84.0Somers' D0.710
Percent Discordant13.0Gamma0.732
Percent Tied3.1Tau-a0.328
Pairs162c0.855

Residual Chi-Square Test
Chi-SquareDFPr > ChiSq
3.117450.6819

Analysis of Effects Eligible for
Removal
EffectDFWald
Chi-Square
Pr > ChiSq
li15.95940.0146


Note:No effects for the model in Step 1 are removed.

Analysis of Effects Eligible for
Entry
EffectDFScore
Chi-Square
Pr > ChiSq
cell11.11830.2903
smear10.13690.7114
infil10.57150.4497
blast10.09320.7601
temp11.25910.2618


In Step 2 (Output 74.1.3), the variable temp is added to the model. The model then contains an intercept and the variables li and temp. Both li and temp remain significant at 0.35 level; therefore, neither li nor temp is removed from the model.

Output 74.1.3: Step 2 of the Stepwise Analysis


Step 2. Effect temp entered:

Model Convergence Status
Convergence criterion (GCONV=1E-8) satisfied.

Model Fit Statistics
CriterionIntercept OnlyIntercept and
Covariates
AIC36.37230.648
SC37.66834.535
-2 Log L34.37224.648

Testing Global Null Hypothesis: BETA=0
TestChi-SquareDFPr > ChiSq
Likelihood Ratio9.723920.0077
Score8.364820.0153
Wald5.905220.0522

Analysis of Maximum Likelihood Estimates
ParameterDFEstimateStandard
Error
Wald
Chi-Square
Pr > ChiSq
Intercept147.844846.43811.06150.3029
li13.30171.35935.90020.0151
temp1-52.421447.48971.21850.2697

Odds Ratio Estimates
EffectPoint Estimate95% Wald
Confidence Limits
li27.1581.892389.856
temp<0.001<0.001>999.999

Association of Predicted Probabilities and
Observed Responses
Percent Concordant87.0Somers' D0.747
Percent Discordant12.3Gamma0.752
Percent Tied0.6Tau-a0.345
Pairs162c0.873

Residual Chi-Square Test
Chi-SquareDFPr > ChiSq
2.142940.7095

Analysis of Effects Eligible for
Removal
EffectDFWald
Chi-Square
Pr > ChiSq
li15.90020.0151
temp11.21850.2697


Note:No effects for the model in Step 2 are removed.

Analysis of Effects Eligible for
Entry
EffectDFScore
Chi-Square
Pr > ChiSq
cell11.47000.2254
smear10.17300.6775
infil10.82740.3630
blast11.10130.2940


In Step 3 (Output 74.1.4), the variable cell is added to the model. The model then contains an intercept and the variables li, temp, and cell. None of these variables are removed from the model because all are significant at the 0.35 level.

Output 74.1.4: Step 3 of the Stepwise Analysis


Step 3. Effect cell entered:

Model Convergence Status
Convergence criterion (GCONV=1E-8) satisfied.

Model Fit Statistics
CriterionIntercept OnlyIntercept and
Covariates
AIC36.37229.953
SC37.66835.137
-2 Log L34.37221.953

Testing Global Null Hypothesis: BETA=0
TestChi-SquareDFPr > ChiSq
Likelihood Ratio12.418430.0061
Score9.250230.0261
Wald4.828130.1848

Analysis of Maximum Likelihood Estimates
ParameterDFEstimateStandard
Error
Wald
Chi-Square
Pr > ChiSq
Intercept167.633956.88751.41350.2345
cell19.65217.75111.55070.2130
li13.86711.77834.72900.0297
temp1-82.073761.71241.76870.1835

Odds Ratio Estimates
EffectPoint Estimate95% Wald
Confidence Limits
cell>999.9990.004>999.999
li47.8041.465>999.999
temp<0.001<0.001>999.999

Association of Predicted Probabilities and
Observed Responses
Percent Concordant88.9Somers' D0.778
Percent Discordant11.1Gamma0.778
Percent Tied0.0Tau-a0.359
Pairs162c0.889

Residual Chi-Square Test
Chi-SquareDFPr > ChiSq
0.183130.9803

Analysis of Effects Eligible for
Removal
EffectDFWald
Chi-Square
Pr > ChiSq
cell11.55070.2130
li14.72900.0297
temp11.76870.1835


Note:No effects for the model in Step 3 are removed.

Analysis of Effects Eligible for
Entry
EffectDFScore
Chi-Square
Pr > ChiSq
smear10.09560.7572
infil10.08440.7714
blast10.02080.8852


Finally, none of the remaining variables outside the model meet the entry criterion, and the stepwise selection is terminated. A summary of the stepwise selection is displayed in Output 74.1.5.

Output 74.1.5: Summary of the Stepwise Selection

Summary of Stepwise Selection
StepEffectDFNumber
In
Score
Chi-Square
Wald
Chi-Square
Pr > ChiSq
EnteredRemoved
1li 117.9311 0.0049
2temp 121.2591 0.2618
3cell 131.4700 0.2254


Results of the Hosmer and Lemeshow test are shown in Output 74.1.6. There is no evidence of a lack of fit in the selected model .

Output 74.1.6: Display of the LACKFIT Option

Partition for the Hosmer and Lemeshow Test
GroupTotalremiss = 1 remiss = 0
ObservedExpectedObservedExpected
1300.0033.00
2300.0132.99
3300.1932.81
4300.5632.44
5411.0932.91
6321.3511.65
7321.8411.16
8332.1500.85
9211.8010.20

Hosmer and Lemeshow Goodness-of-Fit
Test
Chi-SquareDFPr > ChiSq
6.298370.5054


The data set betas created by the OUTEST= and COVOUT options is displayed in Output 74.1.7. The data set contains parameter estimates and the covariance matrix for the final selected model. Note that all explanatory variables listed in the MODEL statement are included in this data set; however, variables that are not included in the final model have all missing values.

Output 74.1.7: Data Set of Estimates and Covariances

Stepwise Regression on Cancer Remission Data
Parameter Estimates and Covariance Matrix

Obs_LINK__TYPE__STATUS__NAME_Interceptcellsmearinfilliblasttemp_LNLIKE__ESTTYPE_
1LOGITPARMS0 Convergedremiss67.639.652..3.8671.-82.07-10.9767MLE
2LOGITCOV0 ConvergedIntercept3236.19157.097..64.5726.-3483.23-10.9767MLE
3LOGITCOV0 Convergedcell157.1060.079..6.9454.-223.67-10.9767MLE
4LOGITCOV0 Convergedsmear.......-10.9767MLE
5LOGITCOV0 Convergedinfil.......-10.9767MLE
6LOGITCOV0 Convergedli64.576.945..3.1623.-75.35-10.9767MLE
7LOGITCOV0 Convergedblast.......-10.9767MLE
8LOGITCOV0 Convergedtemp-3483.23-223.669..-75.3513.3808.42-10.9767MLE


The data set pred created by the OUTPUT statement is displayed in Output 74.1.8. It contains all the variables in the input data set, the variable phat for the (cumulative) predicted probability, the variables lcl and ucl for the lower and upper confidence limits for the probability, and four other variables (IP_1, IP_0, XP_1, and XP_0) for the PREDPROBS= option. The data set also contains the variable _LEVEL_, indicating the response value to which phat, lcl, and ucl refer. For instance, for the first row of the OUTPUT data set, the values of _LEVEL_ and phat, lcl, and ucl are 1, 0.72265, 0.16892, and 0.97093, respectively; this means that the estimated probability that remiss=1 is 0.723 for the given explanatory variable values, and the corresponding 95% confidence interval is (0.16892, 0.97093). The variables IP_1 and IP_0 contain the predicted probabilities that remiss=1 and remiss=0, respectively. Note that values of phat and IP_1 are identical because they both contain the probabilities that remiss=1. The variables XP_1 and XP_0 contain the cross validated predicted probabilities that remiss=1 and remiss=0, respectively.

Output 74.1.8: Predicted Probabilities and Confidence Intervals

Stepwise Regression on Cancer Remission Data
Predicted Probabilities and 95% Confidence Limits

Obsremisscellsmearinfilliblasttemp_FROM__INTO_IP_0IP_1XP_0XP_1_LEVEL_phatlclucl
110.800.830.661.91.1000.996110.277350.722650.438730.5612710.722650.168920.97093
210.900.360.321.40.7400.992110.421260.578740.474610.5253910.578740.267880.83762
300.800.880.700.80.1760.982000.895400.104600.870600.1294010.104600.007810.63419
401.000.870.870.71.0530.986000.717420.282580.672590.3274110.282580.074980.65683
510.900.750.681.30.5190.980110.285820.714180.369010.6309910.714180.252180.94876
601.000.650.650.60.5190.982000.729110.270890.672690.3273110.270890.058520.68951
710.950.970.921.01.2300.992100.678440.321560.729230.2707710.321560.132550.59516
800.950.870.831.91.3541.020010.392770.607230.099060.9009410.607230.105720.95287
901.000.450.450.80.3220.999000.833680.166320.808640.1913610.166320.030180.56123
1000.950.360.340.50.0001.038000.998430.001570.998400.0016010.001570.000000.68962
1100.850.390.330.70.2790.988000.927150.072850.917230.0827710.072850.006140.49982
1200.700.760.531.20.1460.982000.827140.172860.638380.3616210.172860.006370.87206
1300.800.460.370.40.3801.006000.996540.003460.996440.0035610.003460.000010.46530
1400.200.390.080.80.1140.990000.999820.000180.999810.0001910.000180.000000.96482
1501.000.900.901.11.0370.990010.428780.571220.353540.6464610.571220.253030.83973
1611.000.840.841.92.0641.020110.285300.714700.472130.5278710.714700.153620.97189
1700.650.420.270.50.1141.014000.999380.000620.999370.0006310.000620.000000.62665
1801.000.750.751.01.3221.004000.777110.222890.736120.2638810.222890.044830.63670
1900.500.440.220.60.1140.990000.998460.001540.998420.0015810.001540.000000.79644
2011.000.630.631.11.0720.986110.350890.649110.420530.5794710.649110.263050.90555
2101.000.330.330.40.1761.010000.983070.016930.981700.0183010.016930.000290.50475
2200.900.930.840.61.5911.020000.993780.006220.993480.0065210.006220.000030.56062
2311.000.580.581.00.5311.002100.747390.252610.844230.1557710.252610.061370.63597
2400.950.320.301.60.8860.988010.129890.870110.036370.9636310.870110.409100.98481
2511.000.600.601.70.9640.990110.068680.931320.080170.9198310.931320.441140.99573
2611.000.690.690.90.3980.986100.539490.460510.623120.3768810.460510.166120.78529
2701.000.730.730.70.3980.986000.717420.282580.672590.3274110.282580.074980.65683


If you want to order the selected models based on a statistic such as the AIC, R-square, or area under the ROC curve (AUC), you can use the ODS OUTPUT statement to save the appropriate table to a data set and then display the statistic along with the step number. For example, the following program orders the steps according to the "c" statistic from the Association data set:

data Association(rename=(Label2=Statistic nValue2=Value));
   set Association;
   if (Label2='c');
   keep Step Label2 nValue2;
proc sort data=Association;
   by Value;
title;
proc print data=Association;
run;

The results, displayed in Output 74.1.9, show that the model that has the largest AUC (0.889) is the final model selected by the stepwise method. You can also perform this analysis by using the %SELECT macro (SAS Institute Inc. 2015).

Output 74.1.9: Selection Steps Ordered by AUC

ObsStepStatisticValue
11c0.854938
22c0.873457
33c0.888889


Next, a different variable selection method is used to select prognostic factors for cancer remission, and an efficient algorithm is employed to eliminate insignificant variables from a model. The following statements invoke PROC LOGISTIC to perform the backward elimination analysis:

title 'Backward Elimination on Cancer Remission Data';
proc logistic data=Remission;
   model remiss(event='1')=temp cell li smear blast
         / selection=backward fast slstay=0.2 ctable;
run;

The backward elimination analysis (SELECTION=BACKWARD) starts with a model that contains all explanatory variables given in the MODEL statement. By specifying the FAST option, PROC LOGISTIC eliminates insignificant variables without refitting the model repeatedly. This analysis uses a significance level of 0.2 to retain variables in the model (SLSTAY=0.2), which is different from the previous stepwise analysis where SLSTAY=.35. The CTABLE option is specified to produce classifications of input observations based on the final selected model.

Results of the fast elimination analysis are shown in Output 74.1.10 and Output 74.1.11. Initially, a full model containing all six risk factors is fit to the data (Output 74.1.10). In the next step (Output 74.1.11), PROC LOGISTIC removes blast, smear, cell, and temp from the model all at once. This leaves li and the intercept as the only variables in the final model. Note that in this analysis, only parameter estimates for the final model are displayed because the DETAILS option has not been specified.

Output 74.1.10: Initial Step in Backward Elimination

Backward Elimination on Cancer Remission Data

The LOGISTIC Procedure

Model Information
Data SetWORK.REMISSION 
Response VariableremissComplete Remission
Number of Response Levels2 
Modelbinary logit 
Optimization TechniqueFisher's scoring 

Number of Observations Read27
Number of Observations Used27

Response Profile
Ordered
Value
remissTotal
Frequency
1018
219

Probability modeled is remiss=1.



Backward Elimination Procedure


Step 0. The following effects were entered:


Intercept temp cell li smear blast

Model Convergence Status
Convergence criterion (GCONV=1E-8) satisfied.

Model Fit Statistics
CriterionIntercept OnlyIntercept and
Covariates
AIC36.37233.857
SC37.66841.632
-2 Log L34.37221.857

Testing Global Null Hypothesis: BETA=0
TestChi-SquareDFPr > ChiSq
Likelihood Ratio12.514650.0284
Score9.329550.0966
Wald4.728450.4499


Output 74.1.11: Fast Elimination Step



Step 1. Fast Backward Elimination:

Analysis of Effects Removed by Fast Backward Elimination
Effect
Removed
Chi-SquareDFPr > ChiSqResidual
Chi-Square
DFPr >
Residual
ChiSq
blast0.000810.97680.000810.9768
smear0.095110.75780.095920.9532
cell1.513410.21861.609430.6573
temp0.653510.41892.262840.6875

Model Convergence Status
Convergence criterion (GCONV=1E-8) satisfied.

Model Fit Statistics
CriterionIntercept OnlyIntercept and
Covariates
AIC36.37230.073
SC37.66832.665
-2 Log L34.37226.073

Testing Global Null Hypothesis: BETA=0
TestChi-SquareDFPr > ChiSq
Likelihood Ratio8.298810.0040
Score7.931110.0049
Wald5.959410.0146

Residual Chi-Square Test
Chi-SquareDFPr > ChiSq
2.853040.5827

Summary of Backward Elimination
StepEffect
Removed
DFNumber
In
Wald
Chi-Square
Pr > ChiSq
1blast140.00080.9768
1smear130.09510.7578
1cell121.51340.2186
1temp110.65350.4189

Analysis of Maximum Likelihood Estimates
ParameterDFEstimateStandard
Error
Wald
Chi-Square
Pr > ChiSq
Intercept1-3.77711.37867.50640.0061
li12.89731.18685.95940.0146

Odds Ratio Estimates
EffectPoint Estimate95% Wald
Confidence Limits
li18.1241.770185.563

Association of Predicted Probabilities and
Observed Responses
Percent Concordant84.0Somers' D0.710
Percent Discordant13.0Gamma0.732
Percent Tied3.1Tau-a0.328
Pairs162c0.855


Note that you can also use the FAST option when SELECTION=STEPWISE. However, the FAST option operates only on backward elimination steps. In this example, the stepwise process only adds variables, so the FAST option would not be useful.

Results of the CTABLE option are shown in Output 74.1.12.

Output 74.1.12: Classifying Input Observations

Classification Table
Prob
Level
CorrectIncorrectPercentages
EventNon-
Event
EventNon-
Event
CorrectSensi-
tivity
Speci-
ficity
False
POS
False
NEG
0.0609018033.3100.00.066.7.
0.0809216040.7100.011.164.00.0
0.1009414048.1100.022.260.90.0
0.1209414048.1100.022.260.90.0
0.1409711059.3100.038.955.00.0
0.1609108070.4100.055.647.10.0
0.1809108070.4100.055.647.10.0
0.2008135177.888.972.238.57.1
0.2208135177.888.972.238.57.1
0.2408135177.888.972.238.57.1
0.2606135370.466.772.245.518.8
0.2806135370.466.772.245.518.8
0.3006135370.466.772.245.518.8
0.3206144374.166.777.840.017.6
0.3405144470.455.677.844.422.2
0.3605144470.455.677.844.422.2
0.3805153474.155.683.337.521.1
0.4005153474.155.683.337.521.1
0.4205153474.155.683.337.521.1
0.4405153474.155.683.337.521.1
0.4604162574.144.488.933.323.8
0.4804162574.144.488.933.323.8
0.5004162574.144.488.933.323.8
0.5204162574.144.488.933.323.8
0.5403162670.433.388.940.027.3
0.5603162670.433.388.940.027.3
0.5803162670.433.388.940.027.3
0.6003162670.433.388.940.027.3
0.6203162670.433.388.940.027.3
0.6403162670.433.388.940.027.3
0.6603162670.433.388.940.027.3
0.6803162670.433.388.940.027.3
0.7003162670.433.388.940.027.3
0.7202162766.722.288.950.030.4
0.7402162766.722.288.950.030.4
0.7602162766.722.288.950.030.4
0.7802162766.722.288.950.030.4
0.8002171770.422.294.433.329.2
0.8202171770.422.294.433.329.2
0.8400171963.00.094.4100.034.6
0.8600171963.00.094.4100.034.6
0.8800171963.00.094.4100.034.6
0.9000171963.00.094.4100.034.6
0.9200171963.00.094.4100.034.6
0.9400171963.00.094.4100.034.6
0.9600180966.70.0100.0.33.3


Each row of the "Classification Table" corresponds to a cutpoint applied to the predicted probabilities, which is given in the Prob Level column. The frequency tables of observed and predicted responses are given by the next four columns. For example, with a cutpoint of 0.5, 4 events and 16 nonevents were classified correctly. On the other hand, 2 nonevents were incorrectly classified as events and 5 events were incorrectly classified as nonevents. For this cutpoint, the correct classification rate is 20/27 (=74.1%), which is given in the sixth column. Accuracy of the classification is summarized by the sensitivity, specificity, and false positive and negative rates, which are displayed in the last four columns. You can control the number of cutpoints used, and their values, by using the PPROB= option.

Last updated: February 13, 2019