The GAMMOD Procedure
Example 6.2 Nonparametric Logistic Regression
This example shows how you can use PROC GAMMOD to build a nonparametric logistic regression model for a data set that contains a binary response and then use that model to classify observations.
The example uses the Pima Indians Diabetes data set, which can be obtained from the UCI Machine Learning Repository (Lichman 2013). It is extracted from a larger database that was originally owned by the National Institute of Diabetes and Digestive and Kidney Diseases. Data are for female patients who are at least 21 years old, are of Akimel O’otham (Pima Indian) heritage, and live near Phoenix, Arizona. The objective of this study is to investigate the relationship between a diabetes diagnosis and variables that represent physiological measurements and medical attributes. Some missing or invalid observations are removed from the analysis. The reduced data set contains 532 records. The following DATA step creates the data set DiabetesStudy:
title 'Diabetes Study';
data DiabetesStudy;
input NPreg Glucose Pressure Triceps BMI Pedigree Age Diabetes Test@@;
datalines;
6 148 72 35 33.6 0.627 50 1 1 1 85 66 29 26.6 0.351 31 0 1
1 89 66 23 28.1 0.167 21 0 0 3 78 50 32 31 0.248 26 1 0
2 197 70 45 30.5 0.158 53 1 0 5 166 72 19 25.8 0.587 51 1 1
0 118 84 47 45.8 0.551 31 1 1 1 103 30 38 43.3 0.183 33 0 1
3 126 88 41 39.3 0.704 27 0 0 9 119 80 35 29 0.263 29 1 0
... more lines ...
1 128 48 45 40.5 0.613 24 1 0 2 112 68 22 34.1 0.315 26 0 0
1 140 74 26 24.1 0.828 23 0 1 2 141 58 34 25.4 0.699 24 0 1
7 129 68 49 38.5 0.439 43 1 1 0 106 70 37 39.4 0.605 22 0 0
1 118 58 36 33.3 0.261 23 0 1 8 155 62 26 34 0.543 46 1 0
;
The data set contains nine variables, including the binary response variable Diabetes. Table 17 describes the variables.
Table 17: Variables in the DiabetesStudy Data Set
The Test variable splits the data set into training and test subsets. The training observations (whose Test value is 0) hold approximately 59.4% of the data. To build a model that is based on the training data and evaluate its performance by predicting the test data, you use the following statements to create a new variable, Result, whose value is the same as that of the Diabetes variable for a training observation and is missing for a test observation:
data mycas.DiabetesStudy;
set DiabetesStudy;
Result = Diabetes;
if Test=1 then Result=.;
run;
A typical starting point of your analysis for modeling the binary response might be a parametric logistic regression model. But it is restricted in the sense that all variables affect the response in strictly linear fashion. If you are uncertain that a variable is an important factor and its contribution is linear in predicting the response, you might want to choose a nonparametric logistic regression model to fit the data. You can use PROC GAMMOD to form a nonparametric model by including the spline transformation of each explanatory variable, as shown in the following statements:
proc gammod data=mycas.DiabetesStudy seed=12345;
model Result(event='1') = spline(NPreg) spline(Glucose)
spline(Pressure) spline(Triceps)
spline(BMI) spline(Pedigree)
spline(Age) / dist=binary;
run;
Because the response variable Result is binary, the DIST=BINARY option in the MODEL statement specifies a binary distribution for the response variable. By default, PROC GAMMOD models the probability of the first ordered response category, which is a negative diabetes testing result in this case. The EVENT= option specifically requests that PROC GAMMOD model the probability of positive diabetes testing results. The “Response Profile” table in Output 6.2.1 shows the frequencies of the response in both categories.
Output 6.2.1: Response Profile
| Diabetes Study |
| Response Profile | ||
|---|---|---|
| Ordered Value | Result | Total Frequency |
| 1 | 0 | 208 |
| 2 | 1 | 122 |
| Probability modeled is Result = 1. |
Output 6.2.2 lists the summary statistics from the nonparametric logistic regression model, which include spline transformations of all variables.
Output 6.2.2: Fit Statistics
| Fit Statistics | |
|---|---|
| Penalized Log Likelihood | -138.57851 |
| Roughness Penalty | 1.208688E-8 |
| Effective Degrees of Freedom | 16.00000 |
| Effective Degrees of Freedom for Error | 313.75437 |
| AIC (smaller is better) | 309.15702 |
| AICC (smaller is better) | 310.89504 |
| BIC (smaller is better) | 369.94250 |
| UBRE (smaller is better) | 0.02357 |
The “Tests for Smoothing Components” table in Output 6.2.3 shows approximate tests results. Although some spline terms are significant, others are not. The null testing hypothesis is whether the total contribution from a variable is 0. So you can form a reduced model by removing those nonsignificant spline terms from the model. In this case, spline transformations for NPreg, Pressure, BMI, and Triceps are dropped from the model because their p-values are larger than the 0.1 nominal level.
Output 6.2.3: Tests for Smoothing Components
| Tests for Smoothing Components | ||||
|---|---|---|---|---|
| Component | Effective DF | Effective DF for Test | Chi-Square | Pr > ChiSq |
| Spline(NPreg) | 1.00000 | 1 | 0.0186 | 0.8916 |
| Spline(Glucose) | 1.00000 | 1 | 44.5949 | <.0001 |
| Spline(Pressure) | 1.00000 | 1 | 2.8310 | 0.0925 |
| Spline(Triceps) | 1.00000 | 1 | 1.2128 | 0.2708 |
| Spline(BMI) | 1.00000 | 1 | 5.8112 | 0.0159 |
| Spline(Pedigree) | 1.00000 | 1 | 6.1108 | 0.0134 |
| Spline(Age) | 9.00000 | 9 | 19.0721 | 0.0246 |
The following statements use PROC GAMMOD to fit a reduced nonparametric logistic regression model. The OUTPUT statement requests predicted probabilities for both training and test data. The COPYVARS option in the OUTPUT statement requests that the Diabetes and Test variables also be included in the output data table so that you can use them to identify test observations and compute misclassification errors.
ods graphics on;
proc gammod data=mycas.DiabetesStudy plots seed=12345;
model Result(event='1') = spline(Glucose)
spline(Pedigree) spline(Age) / dist=binary;
output out=mycas.DiabetesStudyOut copyvars=(Diabetes Test);
run;
Output 6.2.4 shows the summary statistics from the reduced nonparametric logistic regression model. The values of the information criteria are better than those of the parametric logistic regression model.
Output 6.2.4: Fit Statistics
| Diabetes Study |
| Fit Statistics | |
|---|---|
| Penalized Log Likelihood | -149.85766 |
| Roughness Penalty | 2.85613 |
| Effective Degrees of Freedom | 8.05241 |
| Effective Degrees of Freedom for Error | 320.61183 |
| AIC (smaller is better) | 312.96402 |
| AICC (smaller is better) | 313.41826 |
| BIC (smaller is better) | 343.55588 |
| UBRE (smaller is better) | -0.00230 |
In the “Estimates for Smoothing Components” table in Output 6.2.5, PROC GAMMOD reports that the effective degrees of freedom value for spline transformations of Glucose is quite close to 1. This suggests a strictly linear form for Glucose. For Pedigree, the degrees of freedom value demonstrates a moderate amount of nonlinearity. For Age, the degrees of freedom value is much larger than 1. The measure suggests a nonlinear pattern in the dependency of the response on Age.
Output 6.2.5: Estimates for Smoothing Components
| Estimates for Smoothing Components | ||||||
|---|---|---|---|---|---|---|
| Component | Effective DF | Smoothing Parameter | Roughness Penalty | Number of Parameters | Rank of Penalty Matrix | Number of Knots |
| Spline(Glucose) | 1.00000 | 9.636E17 | 2.66E-14 | 9 | 10 | 110 |
| Spline(Pedigree) | 1.51071 | 0.4383 | 0.5086 | 9 | 10 | 283 |
| Spline(Age) | 4.54170 | 69.8812 | 2.3475 | 9 | 10 | 42 |
The “Tests for Smoothing Components” table in Output 6.2.6 shows that all spline transformations are significant in predicting diabetes testing results.
Output 6.2.6: Tests for Smoothing Components
| Tests for Smoothing Components | ||||
|---|---|---|---|---|
| Component | Effective DF | Effective DF for Test | Chi-Square | Pr > ChiSq |
| Spline(Glucose) | 1.00000 | 1 | 53.0363 | <.0001 |
| Spline(Pedigree) | 1.51071 | 2 | 9.9354 | 0.0070 |
| Spline(Age) | 4.54170 | 6 | 23.0661 | 0.0008 |
The smoothing component panel (which is produced by the PLOTS option and is shown in Output 6.2.7) visualizes the spline transformations for the four variables in addition to 95% Bayesian curvewise confidence bands. For Glucose, the spline transformation is almost a straight line. For Pedigree, the spline transformation shows a slightly nonlinear trend. For Age, the dependency is obviously nonlinear.
Output 6.2.7: Smoothing Components Panel

The following statements compute the misclassification error on the test data from the reduced nonparametric logistic regression model that PROC GAMMOD produces:
data test;
set mycas.DiabetesStudyOut(where=(Test=1));
if ((Pred>0.5 & Diabetes=1) | (Pred<0.5 & Diabetes=0))
then Error=0;
else Error=1;
run;
proc freq data=test;
tables Diabetes*Error/nocol norow;
run;
Output 6.2.8 shows the misclassification errors for observations in the test set and observations of each response category.
Output 6.2.8: Crosstabulation Table for Test Set Prediction
| Diabetes Study |
|
| ||||||||||||||||||||||||||||||||||||||||||||