LOGSELECT Procedure
Binary Logistic Regression
(View the complete code for this example.)
Note: Input data must be in a CAS table that is accessible in your CAS session. You must refer to this table by using a two-level name. The first level must be a CAS engine libref, and the second level must be the table name. For more information, see the sections Using CAS Sessions and CAS Engine Librefs and Loading a SAS Data Set onto a CAS Server in Chapter 2, Shared Concepts.
The following DATA step creates the data table getStarted, which consists of 100 observations on a dichotomous response variable (y), a character variable (C), and 10 continuous variables (x1–x10):
data mylib.getStarted;
input C$ y x1-x10;
datalines;
D 0 10.2 6 1.6 38 15 2.4 20 0.8 8.5 3.9
F 1 12.2 6 2.6 42 61 1.5 10 0.6 8.5 0.7
D 1 7.7 1 2.1 38 61 1 90 0.6 7.5 5.2
J 1 10.9 7 3.5 46 42 0.3 0 0.2 6 3.6
E 0 17.3 6 3.8 26 47 0.9 10 0.4 1.5 4.7
A 0 18.7 4 1.8 2 34 1.7 80 1 9.5 2.2
B 0 7.2 1 0.3 48 61 1.1 10 0.8 3.5 4
D 0 0.1 3 2.4 0 65 1.6 70 0.8 3.5 0.7
H 1 2.4 4 0.7 38 22 0.2 20 0 3 4.2
J 0 15.6 7 1.4 0 98 0.3 0 1 5 5.2
J 0 11.1 3 2.4 42 55 2.2 60 0.6 4.5 0.7
F 0 4 6 0.9 4 36 2.1 30 0.8 9 4.6
A 0 6.2 2 1.8 14 79 1.1 70 0.2 0 5.1
H 0 3.7 3 0.8 12 66 1.3 40 0.4 0.5 3.3
A 1 9.2 3 2.3 48 51 2.3 50 0 6 5.4
G 0 14 3 2 18 12 2.2 0 0 3 3.4
E 1 19.5 6 3.7 26 81 0.1 30 0.6 5 4.8
C 0 11 3 2.8 38 9 1.7 50 0.8 6.5 0.9
I 0 15.3 7 2.2 20 98 2.7 100 0.4 7 0.8
H 1 7.4 4 0.5 28 65 1.3 60 0.2 9.5 5.4
F 0 11.4 2 1.4 42 12 2.4 10 0.4 1 4.5
C 1 19.4 1 0.4 42 4 2.4 10 0 6.5 0.1
G 0 5.9 4 2.6 12 57 0.8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 7 1.7 40 36 1.4 60 0.6 6 3.9
I 0 14.8 2 3.2 8 37 0.4 10 0 4.5 3
D 0 7.4 4 3 12 3 0.6 60 0.6 7 0.7
D 0 4.8 3 2.3 44 41 1.9 60 0.2 3 3.1
A 0 4.5 0 0.2 4 48 1.7 80 0.8 9 4.2
D 0 6.9 6 3.3 14 92 0.5 40 0.4 7.5 5
B 0 4.7 4 0.9 14 99 2.4 80 1 0.5 0.7
I 1 7.5 4 2.1 20 79 0.4 40 0.4 2.5 0.7
C 0 6.1 0 1.4 38 18 2.3 60 0.8 4.5 0.7
C 0 18.3 1 1 26 98 2.7 20 1 8.5 0.5
F 0 16.4 7 1.2 32 94 2.9 40 0.4 5.5 2.1
I 0 9.4 2 2.3 32 42 0.2 70 0.4 8.5 0.3
F 1 17.9 4 1.3 32 42 2 40 0.2 1 5.4
H 0 14.9 3 1.6 36 74 2.6 60 0.2 1 2.3
C 0 12.7 0 2.6 0 88 1.1 80 0.8 0.5 2.1
F 0 5.4 4 1.5 2 1 1.8 70 0.4 5.5 3.6
J 1 12.1 4 1.8 20 59 1.3 60 0.4 3 3.8
;
These statements assume that the CAS engine libref is named mylib, but you can substitute any appropriately named CAS engine libref.
The following statements fit a logistic model to these data by using a classification effect for variable C and 10 regressor effects for x1–x10. The ITHIST option displays a table that summarizes the steps of the optimization.
proc logselect data=mylib.getStarted ithist;
class C;
model y = C x1-x10;
run;
The output from this analysis is presented in Figure 1 through Figure 10.
Figure 1 displays the "Model Information" table. The LOGSELECT procedure uses a Newton-Raphson algorithm to model a binary distribution with a logit link function for the variable y. The CLASS variable C is parameterized using the GLM parameterization, which is the default.
Figure 1: Model Information
| Model Information | |
|---|---|
| Data Source | GETSTARTED |
| Response Variable | y |
| Distribution | Binary |
| Link Function | Logit |
| Optimization Technique | Newton-Raphson with Ridging |
Figure 2 displays the "Number of Observations" table. All 100 observations in the data table are used in the analysis.
Figure 2: Number of Observations
| Number of Observations Read | 100 |
|---|---|
| Number of Observations Used | 100 |
The "Response Profile" table in Figure 3 is produced by default. It shows the breakdown of the response variable levels by frequency. By default for binary data, the LOGSELECT procedure models the probability of the event with the lower OrderedValue value in the "Response Profile" table, as indicated by the note that follows the table. In this example, the values that are represented by y = 0 are modeled as the "successes" in the Bernoulli experiments.
Figure 3: Response Profile
| Response Profile | ||
|---|---|---|
| Ordered Value | y | Total Frequency |
| 1 | 0 | 69 |
| 2 | 1 | 31 |
| Probability modeled is y = 0. |
You can use the response-variable options in the MODEL statement to choose which value of the response variable to model.
The CLASS variable C has 10 unique formatted levels that are displayed in the "Class Level Information" table in Figure 4.
Figure 4: Class Level Information
| Class Level Information | ||
|---|---|---|
| Class | Levels | Values |
| C | 10 | A B C D E F G H I J |
The "Iteration History" table is shown in Figure 5. The Newton-Raphson algorithm with ridging converged after four iterations, not counting the initial setup iteration.
Figure 5: Iteration History
| Iteration History | ||||
|---|---|---|---|---|
| Iteration | Evaluations | Objective Function | Change | Maximum Gradient |
| 0 | 4 | 0.4493546916 | 0.410972 | |
| 1 | 2 | 0.4436453992 | 0.00570929 | 0.081339 |
| 2 | 2 | 0.4435038109 | 0.00014159 | 0.003302 |
| 3 | 2 | 0.4435035933 | 0.00000022 | 5.623E-6 |
| 4 | 2 | 0.4435035933 | 0.00000000 | 1.59E-11 |
Figure 6 displays the final convergence status of the Newton-Raphson algorithm. The GCONV= relative convergence criterion is satisfied.
Figure 6: Convergence Status
| Convergence criterion (GCONV=1E-8) satisfied. |
Figure 7 displays the "Dimensions" table for this model. This table summarizes some important sizes of various model components. For example, it shows that the design matrix has 21 columns, which correspond to 1 column for the intercept, 10 columns for the effect associated with the classification variable
C, and 1 column each for the continuous variables x1–x10. However, the rank of the crossproducts matrix is only 20. Because the classification variable C uses GLM parameterization and because the model contains an intercept, there is one singularity in the crossproducts matrix of the model. Consequently, only 20 parameters enter the optimization.
Figure 7: Dimensions in Binary Logistic Regression
| Dimensions | |
|---|---|
| Columns in Design | 21 |
| Number of Effects | 12 |
| Max Effect Columns | 10 |
| Rank of Design | 20 |
| Parameters in Optimization | 20 |
Figure 8 shows the global test for the null hypothesis that all model effects jointly do not affect the probability of success of the binary response. The test is significant (p = 0.0135). One or more of the model effects thus significantly affect the probability of observing an event.
Figure 8: Null Test
| Testing Global Null Hypothesis: BETA=0 | |||
|---|---|---|---|
| Test | DF | Chi-Square | Pr > ChiSq |
| Likelihood Ratio | 19 | 35.1194 | 0.0135 |
The "Fit Statistics" table is shown in Figure 9. The –2 log likelihood at the converged estimates is 88.7007. You can use this value to compare the model to nested model alternatives by means of a likelihood ratio test. To compare models that are not nested, you can use information criteria such as AIC (Akaike’s information criterion), AICC (Akaike’s bias-corrected information criterion), and SBC (Schwarz Bayesian information criterion). These criteria penalize the –2 log likelihood for the number of parameters. Because of the large number of parameters relative to the number of observations, the discrepancy between the –2 log likelihood and, for example, AIC is substantial in this case.
Figure 9: Fit Statistics
| Fit Statistics | |
|---|---|
| -2 Log Likelihood | 88.70072 |
| AIC (smaller is better) | 128.70072 |
| AICC (smaller is better) | 139.33363 |
| SBC (smaller is better) | 180.80412 |
However, the "Parameter Estimates" table in Figure 10 shows that many parameters have fairly large p-values, indicating that one or more of the model effects might not be necessary.
Figure 10: Parameter Estimates
| Parameter Estimates | |||||
|---|---|---|---|---|---|
| Parameter | DF | Estimate | Standard Error | Chi-Square | Pr > ChiSq |
| Intercept | 1 | 1.210139 | 1.750750 | 0.4778 | 0.4894 |
| C A | 1 | 3.434071 | 1.613142 | 4.5318 | 0.0333 |
| C B | 1 | 2.163830 | 1.427083 | 2.2990 | 0.1295 |
| C C | 1 | 0.655205 | 1.081024 | 0.3674 | 0.5445 |
| C D | 1 | 2.494481 | 1.109366 | 5.0560 | 0.0245 |
| C E | 1 | 3.244860 | 1.432140 | 5.1336 | 0.0235 |
| C F | 1 | 3.605371 | 1.307025 | 7.6091 | 0.0058 |
| C G | 1 | 2.084085 | 1.189764 | 3.0684 | 0.0798 |
| C H | 1 | 2.936779 | 1.293876 | 5.1518 | 0.0232 |
| C I | 1 | 1.378522 | 1.031899 | 1.7847 | 0.1816 |
| C J | 0 | 0 | . | . | . |
| x1 | 1 | 0.032181 | 0.057100 | 0.3176 | 0.5730 |
| x2 | 1 | -0.367741 | 0.153824 | 5.7152 | 0.0168 |
| x3 | 1 | 0.314640 | 0.357414 | 0.7750 | 0.3787 |
| x4 | 1 | -0.051957 | 0.024428 | 4.5239 | 0.0334 |
| x5 | 1 | -0.006828 | 0.010555 | 0.4184 | 0.5177 |
| x6 | 1 | 0.253852 | 0.378462 | 0.4499 | 0.5024 |
| x7 | 1 | -0.007233 | 0.010734 | 0.4541 | 0.5004 |
| x8 | 1 | 2.537042 | 0.994180 | 6.5122 | 0.0107 |
| x9 | 1 | -0.167502 | 0.106789 | 2.4603 | 0.1168 |
| x10 | 1 | -0.222155 | 0.157743 | 1.9834 | 0.1590 |
Finally, the procedure displays the table in Figure 11, which shows the amount of time (in seconds) that PROC LOGSELECT required to perform different tasks in the analysis.
Figure 11: Procedure Timing
| Task Timing | ||
|---|---|---|
| Task | Seconds | Percent |
| Setup and Parsing | 0.07 | 24.60% |
| Levelization | 0.06 | 20.95% |
| Model Initialization | 0.01 | 2.04% |
| SSCP Computation | 0.01 | 3.94% |
| Model Fitting | 0.13 | 47.57% |
| Display | 0.00 | 0.57% |
| Cleanup | 0.00 | 0.00% |
| Total | 0.27 | 100.00% |