The LOGISTIC Procedure

Example 73.2 Logistic Modeling with Categorical Predictors

(View the complete code for this example.)

Consider a study of the analgesic effects of treatments on elderly patients with neuralgia. Two test treatments and a placebo are compared. The response variable is whether the patient reported pain or not. Researchers recorded the age and gender of 60 patients and the duration of complaint before the treatment began. The following DATA step creates the data set Neuralgia:

data Neuralgia;
   input Treatment $ Sex $ Age Duration Pain $ @@;
   datalines;
P  F  68   1  No   B  M  74  16  No  P  F  67  30  No
P  M  66  26  Yes  B  F  67  28  No  B  F  77  16  No
A  F  71  12  No   B  F  72  50  No  B  F  76   9  Yes
A  M  71  17  Yes  A  F  63  27  No  A  F  69  18  Yes
B  F  66  12  No   A  M  62  42  No  P  F  64   1  Yes
A  F  64  17  No   P  M  74   4  No  A  F  72  25  No
P  M  70   1  Yes  B  M  66  19  No  B  M  59  29  No
A  F  64  30  No   A  M  70  28  No  A  M  69   1  No
B  F  78   1  No   P  M  83   1  Yes B  F  69  42  No
B  M  75  30  Yes  P  M  77  29  Yes P  F  79  20  Yes
A  M  70  12  No   A  F  69  12  No  B  F  65  14  No
B  M  70   1  No   B  M  67  23  No  A  M  76  25  Yes
P  M  78  12  Yes  B  M  77   1  Yes B  F  69  24  No
P  M  66   4  Yes  P  F  65  29  No  P  M  60  26  Yes
A  M  78  15  Yes  B  M  75  21  Yes A  F  67  11  No
P  F  72  27  No   P  F  70  13  Yes A  M  75   6  Yes
B  F  65   7  No   P  F  68  27  Yes P  M  68  11  Yes
P  M  67  17  Yes  B  M  70  22  No  A  M  65  15  No
P  F  67   1  Yes  A  M  67  10  No  P  F  72  11  Yes
A  F  74   1  No   B  M  80  21  Yes A  F  69   3  No
;

The data set Neuralgia contains five variables: Treatment, Sex, Age, Duration, and Pain. The last variable, Pain, is the response variable. A specification of Pain=Yes indicates there was pain, and Pain=No indicates no pain. The variable Treatment is a categorical variable with three levels: A and B represent the two test treatments, and P represents the placebo treatment. The gender of the patients is given by the categorical variable Sex. The variable Age is the age of the patients, in years, when treatment began. The duration of complaint, in months, before the treatment began is given by the variable Duration.

The following statements use the LOGISTIC procedure to fit a two-way logit with interaction model for the effect of Treatment and Sex, with Age and Duration as covariates. The categorical variables Treatment and Sex are declared in the CLASS statement.

proc logistic data=Neuralgia;
   class Treatment Sex;
   model Pain= Treatment Sex Treatment*Sex Age Duration / expb;
run;

In this analysis, PROC LOGISTIC models the probability of no pain (Pain=No). By default, effect coding is used to represent the CLASS variables. Two design variables are created for Treatment and one for Sex, as shown in Output 73.2.1.

Output 73.2.1: Effect Coding of CLASS Variables

The LOGISTIC Procedure

Class Level Information
ClassValueDesign Variables
TreatmentA10
 B01
 P-1-1
SexF1 
 M-1 


PROC LOGISTIC displays a table of the Type 3 analysis of effects based on the Wald test (Output 73.2.2). Note that the Treatment*Sex interaction and the duration of complaint are not statistically significant (p = 0.9318 and p = 0.8752, respectively). This indicates that there is no evidence that the treatments affect pain differently in men and women, and no evidence that the pain outcome is related to the duration of pain.

Output 73.2.2: Wald Tests of Individual Effects

Joint Tests
EffectDFWald
Chi-Square
Pr > ChiSq
Treatment211.98860.0025
Sex15.31040.0212
Treatment*Sex20.14120.9318
Age17.27440.0070
Duration10.02470.8752

Note:Under full-rank parameterizations, Type 3 effect tests are replaced by joint tests. The joint test for an effect is a test that all the parameters associated with that effect are zero. Such joint tests might not be equivalent to Type 3 effect tests under GLM parameterization.



Parameter estimates are displayed in Output 73.2.3. The Exp(Est) column contains the exponentiated parameter estimates requested with the EXPB option. These values can, but do not necessarily, represent odds ratios for the corresponding variables. For continuous explanatory variables, the Exp(Est) value corresponds to the odds ratio for a unit increase of the corresponding variable. For CLASS variables that use effect coding, the Exp(Est) values have no direct interpretation as a comparison of levels. However, when the reference coding is used, the Exp(Est) values represent the odds ratio between the corresponding level and the reference level. Following the parameter estimates table, PROC LOGISTIC displays the odds ratio estimates for those variables that are not involved in any interaction terms. If the variable is a CLASS variable, the odds ratio estimate comparing each level with the reference level is computed regardless of the coding scheme. In this analysis, because the model contains the Treatment*Sex interaction term, the odds ratios for Treatment and Sex were not computed. The odds ratio estimates for Age and Duration are precisely the values given in the Exp(Est) column in the parameter estimates table.

Output 73.2.3: Parameter Estimates with Effect Coding

Analysis of Maximum Likelihood Estimates
Parameter  DFEstimateStandard
Error
Wald
Chi-Square
Pr > ChiSqExp(Est)
Intercept  119.22367.13157.26610.00702.232E8
TreatmentA 10.84830.55022.37730.12312.336
TreatmentB 11.49490.66225.09560.02404.459
SexF 10.91730.39815.31040.02122.503
Treatment*SexAF1-0.20100.55680.13040.71800.818
Treatment*SexBF10.04870.55630.00770.93021.050
Age  1-0.26880.09967.27440.00700.764
Duration  10.005230.03330.02470.87521.005

Odds Ratio Estimates
EffectPoint Estimate95% Wald
Confidence Limits
Age0.7640.6290.929
Duration1.0050.9421.073


The following PROC LOGISTIC statements illustrate the use of forward selection on the data set Neuralgia to identify the effects that differentiate the two Pain responses. The option SELECTION=FORWARD is specified to carry out the forward selection. The term Treatment|Sex@2 illustrates another way to specify main effects and two-way interactions. (Note that, in this case, the "@2" is unnecessary because no interactions besides the two-way interaction are possible).

proc logistic data=Neuralgia;
   class Treatment Sex;
   model Pain=Treatment|Sex@2 Age Duration
         /selection=forward expb;
run;

Results of the forward selection process are summarized in Output 73.2.4. The variable Treatment is selected first, followed by Age and then Sex. The results are consistent with the previous analysis (Output 73.2.2) in which the Treatment*Sex interaction and Duration are not statistically significant.

Output 73.2.4: Effects Selected into the Model

The LOGISTIC Procedure

Summary of Forward Selection
StepEffect
Entered
DFNumber
In
Score
Chi-Square
Pr > ChiSq
1Treatment2113.71430.0011
2Age1210.60380.0011
3Sex135.99590.0143


Output 73.2.5 shows the Type 3 analysis of effects, the parameter estimates, and the odds ratio estimates for the selected model. All three variables, Treatment, Age, and Sex, are statistically significant at the 0.05 level (p=0.0018, p=0.0213, and p=0.0057, respectively). Because the selected model does not contain the Treatment*Sex interaction, odds ratios for Treatment and Sex are computed. The estimated odds ratio is 24.022 for treatment A versus placebo, 41.528 for Treatment B versus placebo, and 6.194 for female patients versus male patients. Note that these odds ratio estimates are not the same as the corresponding values in the Exp(Est) column in the parameter estimates table because effect coding was used. From Output 73.2.5, it is evident that both Treatment A and Treatment B are better than the placebo in reducing pain; females tend to have better improvement than males; and younger patients are faring better than older patients.

Output 73.2.5: Type 3 Effects and Parameter Estimates with Effect Coding

Type 3 Analysis of Effects
EffectDFWald
Chi-Square
Pr > ChiSq
Treatment212.69280.0018
Sex15.30130.0213
Age17.63140.0057

Analysis of Maximum Likelihood Estimates
Parameter DFEstimateStandard
Error
Wald
Chi-Square
Pr > ChiSqExp(Est)
Intercept 119.08046.78827.90070.00491.9343E8
TreatmentA10.87720.52742.76620.09632.404
TreatmentB11.42460.60365.57110.01834.156
SexF10.91180.39605.30130.02132.489
Age 1-0.26500.09597.63140.00570.767

Odds Ratio Estimates
EffectPoint Estimate95% Wald
Confidence Limits
Treatment A vs P24.0223.295175.121
Treatment B vs P41.5284.500383.262
Sex F vs M6.1941.31229.248
Age0.7670.6360.926


Finally, the following statements refit the previously selected model, except that reference coding is used for the CLASS variables instead of effect coding:

ods graphics on;
proc logistic data=Neuralgia plots(only)=(oddsratio(range=clip));
   class Treatment Sex /param=ref;
   model Pain= Treatment Sex Age / noor;
   oddsratio Treatment;
   oddsratio Sex;
   oddsratio Age;
   contrast 'Pairwise A vs P' Treatment 1  0 / estimate=exp;
   contrast 'Pairwise B vs P' Treatment 0  1 / estimate=exp;
   contrast 'Pairwise A vs B' Treatment 1 -1 / estimate=exp;
   contrast 'Female vs Male' Sex 1 / estimate=exp;
   effectplot / at(Sex=all) noobs;
   effectplot slicefit(sliceby=Sex plotby=Treatment) / noobs;
run;

The ODDSRATIO statements compute the odds ratios for the covariates, and the NOOR option suppresses the default odds ratio table. Four CONTRAST statements are specified; they provide another method of producing the odds ratios. The three contrasts labeled 'Pairwise' specify a contrast vector, L, for each of the pairwise comparisons between the three levels of Treatment. The contrast labeled 'Female vs Male' compares female to male patients. The option ESTIMATE=EXP is specified in all CONTRAST statements to exponentiate the estimates of . With the given specification of contrast coefficients, the first of the 'Pairwise' CONTRAST statements corresponds to the odds ratio of A versus P, the second corresponds to B versus P, and the third corresponds to A versus B. You can also specify the 'Pairwise' contrasts in a single contrast statement with three rows. The 'Female vs Male' CONTRAST statement corresponds to the odds ratio that compares female to male patients.

The PLOTS(ONLY)= option displays only the requested odds ratio plot when ODS Graphics is enabled. The EFFECTPLOT statements do not honor the ONLY option, and display the fitted model. The first EFFECTPLOT statement by default produces a plot of the predicted values against the continuous Age variable, grouped by the Treatment levels. The AT option produces one plot for males and another for females; the NOOBS option suppresses the display of the observations. In the second EFFECTPLOT statement, a SLICEFIT plot is specified to display the Age variable on the X axis, the fits are grouped by the Sex levels, and the PLOTBY= option produces a panel of plots that displays each level of the Treatment variable.

The reference coding is shown in Output 73.2.6. The Type 3 analysis of effects and the parameter estimates for the reference coding are displayed in Output 73.2.7. Although the parameter estimates are different because of the different parameterizations, the "Type 3 Analysis of Effects" table remains the same as in Output 73.2.5. With effect coding, the treatment A parameter estimate (0.8772) estimates the effect of treatment A compared to the average effect of treatments A, B, and placebo. The treatment A estimate (3.1790) under the reference coding estimates the difference in effect of treatment A and the placebo treatment.

Output 73.2.6: Reference Coding of CLASS Variables

The LOGISTIC Procedure

Class Level Information
ClassValueDesign Variables
TreatmentA10
 B01
 P00
SexF1 
 M0 


Output 73.2.7: Type 3 Effects and Parameter Estimates with Reference Coding

Type 3 Analysis of Effects
EffectDFWald
Chi-Square
Pr > ChiSq
Treatment212.69280.0018
Sex15.30130.0213
Age17.63140.0057

Analysis of Maximum Likelihood Estimates
Parameter DFEstimateStandard
Error
Wald
Chi-Square
Pr > ChiSq
Intercept 115.86696.40566.13570.0132
TreatmentA13.17901.01359.83750.0017
TreatmentB13.72641.133910.80060.0010
SexF11.82350.79205.30130.0213
Age 1-0.26500.09597.63140.0057


The ODDSRATIO statement results are shown in Output 73.2.8, and the resulting plot is displayed in Output 73.2.9. Note in Output 73.2.9 that the odds ratio confidence limits are truncated due to specifying the RANGE=CLIP option; this enables you to see which intervals contain "1" more clearly. The odds ratios are identical to those shown in the "Odds Ratio Estimates" table in Output 73.2.5 with the addition of the odds ratio for "Treatment A vs B". Both treatments A and B are highly effective over placebo in reducing pain, as can be seen from the odds ratios comparing treatment A against P and treatment B against P (the second and third rows in the table). However, the 95% confidence interval for the odds ratio comparing treatment A to B is (0.0932, 3.5889), indicating that the pain reduction effects of these two test treatments are not very different. Again, the ’Sex F vs M’ odds ratio shows that female patients fared better in obtaining relief from pain than male patients. The odds ratio for Age shows that a patient one year older is 0.77 times as likely to show no pain; that is, younger patients have more improvement than older patients.

Output 73.2.8: Results from the ODDSRATIO Statements

Odds Ratio Estimates and Wald Confidence Intervals
Odds RatioEstimate95% Confidence Limits
Treatment A vs B0.5780.0933.589
Treatment A vs P24.0223.295175.121
Treatment B vs P41.5284.500383.262
Sex F vs M6.1941.31229.248
Age0.7670.6360.926


Output 73.2.9: Plot of the ODDSRATIO Statement Results

Plot of the ODDSRATIO Statement Results


Output 73.2.10 contains two tables: the "Contrast Test Results" table and the "Contrast Estimation and Testing Results by Row" table. The former contains the overall Wald test for each CONTRAST statement. The latter table contains estimates and tests of individual contrast rows. The estimates for the first two rows of the ’Pairwise’ CONTRAST statements are the same as those given in the two preceding odds ratio tables (Output 73.2.7 and Output 73.2.8). The third row estimates the odds ratio comparing A to B, agreeing with Output 73.2.8, and the last row computes the odds ratio comparing pain relief for females to that for males.

Output 73.2.10: Results of CONTRAST Statements

Contrast Test Results
ContrastDFWald
Chi-Square
Pr > ChiSq
Pairwise A vs P19.83750.0017
Pairwise B vs P110.80060.0010
Pairwise A vs B10.34550.5567
Female vs Male15.30130.0213

Contrast Estimation and Testing Results by Row
ContrastTypeRowEstimateStandard
Error
AlphaConfidence LimitsWald
Chi-Square
Pr > ChiSq
Pairwise A vs PEXP124.021824.34730.053.2951175.19.83750.0017
Pairwise B vs PEXP141.528447.08770.054.4998383.310.80060.0010
Pairwise A vs BEXP10.57840.53870.050.09323.58890.34550.5567
Female vs MaleEXP16.19374.90530.051.311629.24765.30130.0213


ANCOVA-style plots of the model-predicted probabilities against the Age variable for each combination of Treatment and Sex are displayed in Output 73.2.11 and Output 73.2.12. These plots confirm that females always have a higher probability of pain reduction in each treatment group, the placebo treatment has a lower probability of success than the other treatments, and younger patients respond to treatment better than older patients.

Output 73.2.11: Model-Predicted Probabilities by Sex

Model-Predicted Probabilities by Sex


Output 73.2.12: Model-Predicted Probabilities by Treatment

Model-Predicted Probabilities by Treatment