The LOGISTIC Procedure

Getting Started: LOGISTIC Procedure

(View the complete code for this example.)

The LOGISTIC procedure is similar in use to the other regression procedures in the SAS System. To demonstrate the similarity, suppose the response variable y is binary or ordinal, and x1 and x2 are two explanatory variables of interest. To fit a logistic regression model, you can specify a MODEL statement similar to that used in the REG procedure. For example:

proc logistic;
   model y=x1 x2;
run;

The response variable y can be either character or numeric. PROC LOGISTIC enumerates the total number of response categories and orders the response levels according to the response variable option ORDER= in the MODEL statement.

You can also input binary response data that are grouped. In the following statements, n represents the number of trials and r represents the number of events:

proc logistic;
   model r/n=x1 x2;
run;

The following example illustrates the use of PROC LOGISTIC. The data, taken from Cox and Snell (1989, pp. 10–11), consist of the number, r, of ingots not ready for rolling, out of n tested, for a number of combinations of heating time and soaking time.

data ingots;
   input Heat Soak r n @@;
   datalines;
7 1.0 0 10  14 1.0 0 31  27 1.0 1 56  51 1.0 3 13
7 1.7 0 17  14 1.7 0 43  27 1.7 4 44  51 1.7 0  1
7 2.2 0  7  14 2.2 2 33  27 2.2 0 21  51 2.2 0  1
7 2.8 0 12  14 2.8 0 31  27 2.8 1 22  51 4.0 0  1
7 4.0 0  9  14 4.0 0 19  27 4.0 1 16
;

The following invocation of PROC LOGISTIC fits the binary logit model to the grouped data. The continuous covariates Heat and Soak are specified as predictors, and the bar notation ("|") includes their interaction, Heat*Soak. The ODDSRATIO statement produces odds ratios in the presence of interactions, and a graphical display of the requested odds ratios is produced when ODS Graphics is enabled.

ods graphics on;
proc logistic data=ingots;
   model r/n = Heat | Soak;
   oddsratio Heat / at(Soak=1 2 3 4);
run;

The results of this analysis are shown in the following figures. PROC LOGISTIC first lists background information in Figure 74.1 about the fitting of the model. Included are the name of the input data set, the response variable(s) used, the number of observations used, and the link function used.

Figure 74.1: Binary Logit Model

The LOGISTIC Procedure

Model Information
Data SetWORK.INGOTS
Response Variable (Events)r
Response Variable (Trials)n
Modelbinary logit
Optimization TechniqueFisher's scoring

Number of Observations Read19
Number of Observations Used19
Sum of Frequencies Read387
Sum of Frequencies Used387


The "Response Profile" table (Figure 74.2) lists the response categories (which are Event and Nonevent when grouped data are input), their ordered values, and their total frequencies for the given data.

Figure 74.2: Response Profile with Events/Trials Syntax

Response Profile
Ordered
Value
Binary OutcomeTotal
Frequency
1Event12
2Nonevent375

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


The "Model Fit Statistics" table (Figure 74.3) contains Akaike’s information criterion (AIC), the Schwarz criterion (SC), and the negative of twice the log likelihood (–2 Log L) for the intercept-only model and the fitted model. AIC and SC can be used to compare different models, and the ones with smaller values are preferred. Results of the likelihood ratio test and the efficient score test for testing the joint significance of the explanatory variables (Soak, Heat, and their interaction) are included in the "Testing Global Null Hypothesis: BETA=0" table (Figure 74.3); the small p-values reject the hypothesis that all slope parameters are equal to zero.

Figure 74.3: Fit Statistics and Hypothesis Tests

Model Fit Statistics
CriterionIntercept OnlyIntercept and Covariates
Log LikelihoodFull Log Likelihood
AIC108.988103.22235.957
SC112.947119.05651.791
-2 Log L106.98895.22227.957

Testing Global Null Hypothesis: BETA=0
TestChi-SquareDFPr > ChiSq
Likelihood Ratio11.766330.0082
Score16.541730.0009
Wald13.458830.0037


The "Analysis of Maximum Likelihood Estimates" table in Figure 74.4 lists the parameter estimates, their standard errors, and the results of the Wald test for individual parameters. Note that the Heat*Soak parameter is not significantly different from zero (p=0.727), nor is the Soak variable (p=0.6916).

Figure 74.4: Parameter Estimates

Analysis of Maximum Likelihood Estimates
ParameterDFEstimateStandard
Error
Wald
Chi-Square
Pr > ChiSq
Intercept1-5.99011.666612.91820.0003
Heat10.09630.04714.18950.0407
Soak10.29960.75510.15740.6916
Heat*Soak1-0.008840.02530.12190.7270


The "Association of Predicted Probabilities and Observed Responses" table (Figure 74.5) contains four measures of association for assessing the predictive ability of a model. They are based on the number of pairs of observations with different response values, the number of concordant pairs, and the number of discordant pairs, which are also displayed. Formulas for these statistics are given in the section Rank Correlation of Observed Responses and Predicted Probabilities.

Figure 74.5: Association Table

Association of Predicted Probabilities and
Observed Responses
Percent Concordant73.2Somers' D0.541
Percent Discordant19.1Gamma0.586
Percent Tied7.6Tau-a0.033
Pairs4500c0.771


The ODDSRATIO statement produces the "Odds Ratio Estimates and Wald Confidence Intervals" table (Figure 74.6), and a graphical display of these estimates is shown in Figure 74.7. The differences between the odds ratios are small compared to the variability shown by their confidence intervals, which confirms the previous conclusion that the Heat*Soak parameter is not significantly different from zero.

Figure 74.6: Odds Ratios of Heat at Several Values of Soak

Odds Ratio Estimates and Wald Confidence Intervals
Odds RatioEstimate95% Confidence Limits
Heat at Soak=11.0911.0321.154
Heat at Soak=21.0821.0281.139
Heat at Soak=31.0720.9861.166
Heat at Soak=41.0630.9351.208


Figure 74.7: Plot of Odds Ratios of Heat at Several Values of Soak

Plot of Odds Ratios of Heat at Several Values of Soak


Because the Heat*Soak interaction is nonsignificant, the following statements fit a main-effects model:

proc logistic data=ingots;
   model r/n = Heat Soak;
run;

The results of this analysis are shown in the following figures. The model information and response profiles are the same as those in Figure 74.1 and Figure 74.2 for the saturated model. The "Model Fit Statistics" table in Figure 74.8 shows that the AIC and SC for the main-effects model are smaller than for the saturated model, indicating that the main-effects model might be the preferred model. As in the preceding model, the "Testing Global Null Hypothesis: BETA=0" table indicates that the parameters are significantly different from zero.

Figure 74.8: Fit Statistics and Hypothesis Tests

The LOGISTIC Procedure

Model Fit Statistics
CriterionIntercept OnlyIntercept and Covariates
Log LikelihoodFull Log Likelihood
AIC108.988101.34634.080
SC112.947113.22145.956
-2 Log L106.98895.34628.080

Testing Global Null Hypothesis: BETA=0
TestChi-SquareDFPr > ChiSq
Likelihood Ratio11.642820.0030
Score15.109120.0005
Wald13.031520.0015


The "Analysis of Maximum Likelihood Estimates" table in Figure 74.9 again shows that the Soak parameter is not significantly different from zero (p=0.8639). The odds ratio for each effect parameter, estimated by exponentiating the corresponding parameter estimate, is shown in the "Odds Ratios Estimates" table (Figure 74.9), along with 95% Wald confidence intervals. The confidence interval for the Soak parameter contains the value 1, which also indicates that this effect is not significant.

Figure 74.9: Parameter Estimates and Odds Ratios

Analysis of Maximum Likelihood Estimates
ParameterDFEstimateStandard
Error
Wald
Chi-Square
Pr > ChiSq
Intercept1-5.55921.119724.6503<.0001
Heat10.08200.023711.94540.0005
Soak10.05680.33120.02940.8639

Odds Ratio Estimates
EffectPoint Estimate95% Wald
Confidence Limits
Heat1.0851.0361.137
Soak1.0580.5532.026

Association of Predicted Probabilities and
Observed Responses
Percent Concordant73.0Somers' D0.537
Percent Discordant19.3Gamma0.581
Percent Tied7.6Tau-a0.032
Pairs4500c0.769


Using these parameter estimates, you can calculate the estimated logit of as

For example, if Heat=7 and Soak=1, then logit. Using this logit estimate, you can calculate as follows:

This gives the predicted probability of the event (ingot not ready for rolling) for Heat=7 and Soak=1. Note that PROC LOGISTIC can calculate these statistics for you; use the OUTPUT statement with the PREDICTED= option, or use the SCORE statement.

To illustrate the use of an alternative form of input data, the following program creates the ingots data set with the new variables NotReady and Freq instead of n and r. The variable NotReady represents the response of individual units; it has a value of 1 for units not ready for rolling (event) and a value of 0 for units ready for rolling (nonevent). The variable Freq represents the frequency of occurrence of each combination of Heat, Soak, and NotReady. Note that, compared to the previous data set, NotReady=1 implies Freq=r, and NotReady=0 implies Freq=n–r.

data ingots;
   input Heat Soak NotReady Freq @@;
   datalines;
7 1.0 0 10  14 1.0 0 31  14 4.0 0 19  27 2.2 0 21  51 1.0 1  3
7 1.7 0 17  14 1.7 0 43  27 1.0 1  1  27 2.8 1  1  51 1.0 0 10
7 2.2 0  7  14 2.2 1  2  27 1.0 0 55  27 2.8 0 21  51 1.7 0  1
7 2.8 0 12  14 2.2 0 31  27 1.7 1  4  27 4.0 1  1  51 2.2 0  1
7 4.0 0  9  14 2.8 0 31  27 1.7 0 40  27 4.0 0 15  51 4.0 0  1
;

The following statements invoke PROC LOGISTIC to fit the main-effects model by using the alternative form of the input data set:

proc logistic data=ingots;
   model NotReady(event='1') = Heat Soak;
   freq Freq;
run;

Results of this analysis are the same as the preceding single-trial main-effects analysis. The displayed output for the two runs are identical except for the background information of the model fit and the "Response Profile" table shown in Figure 74.10.

Figure 74.10: Response Profile with Single-Trial Syntax

The LOGISTIC Procedure

Response Profile
Ordered
Value
NotReadyTotal
Frequency
10375
2112

Probability modeled is NotReady=1.



By default, Ordered Values are assigned to the sorted response values in ascending order, and PROC LOGISTIC models the probability of the response level that corresponds to the Ordered Value 1. There are several methods to change these defaults; the preceding statements specify the response variable option EVENT= to model the probability of NotReady=1 as displayed in Figure 74.10. For more information, see the section Response Level Ordering.

Last updated: February 13, 2019