*** loglinear models for contigency tables;
*** relation to logit models;
data newdrug;
input sex $ trtmnt $ response $ count;
datalines;
1 1 1 950
1 1 2 50
1 2 1 9000
1 2 2 1000
2 1 1 5000
2 1 2 5000
2 2 1 5
2 2 2 95
;
run;
** two factors case: X and Y only;
proc genmod data=newdrug;
class trtmnt response;
model count=trtmnt|response/ dist=poisson link=log p r;
run;
proc genmod data=newdrug;
freq count;
class trtmnt;
model response=trtmnt/ dist=bin link=logit p r;
run;
** X, Y, and Z;
** saturated model;
proc genmod data=newdrug;
class sex trtmnt response;
model count=sex|trtmnt|response/ dist=poisson link=log p r;
run;
** homogeneous association;
proc genmod data=newdrug;
class sex trtmnt response;
model count=sex trtmnt response sex*trtmnt sex*response trtmnt*response/ dist=poisson link=log p r;
run;
** the corresponding logit regression model;
proc genmod data=newdrug;
freq count; ** saturated model is different!! Ungrouped;
class sex trtmnt;
model response=sex trtmnt/ dist=bin link=logit p r;
run;
The SAS System 21:36 Sunday, November 8, 2009 13
The GENMOD Procedure
Model Information
Data Set WORK.NEWDRUG
Distribution Poisson
Link Function Log
Dependent Variable count
Number of Observations Read 8
Number of Observations Used 8
Class Level Information
Class Levels Values
trtmnt 2 1 2
response 2 1 2
Criteria For Assessing Goodness Of Fit
Criterion DF Value Value/DF
Deviance 4 22733.4149 5683.3537
Scaled Deviance 4 22733.4149 5683.3537
Pearson Chi-Square 4 17341.6819 4335.4205
Scaled Pearson X2 4 17341.6819 4335.4205
Log Likelihood 148707.7040
Algorithm converged.
Analysis Of Parameter Estimates
Standard Wald 95% Confidence Chi-
Parameter DF Estimate Error Limits Square Pr > ChiSq
Intercept 1 6.3054 0.0302 6.2461 6.3646 43534.6 <.0001
trtmnt 1 1 1.5286 0.0333 1.4633 1.5940 2102.76 <.0001
trtmnt 2 0 0.0000 0.0000 0.0000 0.0000 . .
response 1 1 2.1070 0.0320 2.0443 2.1698 4334.27 <.0001
response 2 0 0.0000 0.0000 0.0000 0.0000 . .
trtmnt*response 1 1 1 -1.9430 0.0373 -2.0161 -1.8699 2715.33 <.0001
trtmnt*response 1 2 0 0.0000 0.0000 0.0000 0.0000 . .
trtmnt*response 2 1 0 0.0000 0.0000 0.0000 0.0000 . .
trtmnt*response 2 2 0 0.0000 0.0000 0.0000 0.0000 . .
Scale 0 1.0000 0.0000 1.0000 1.0000
The SAS System 21:36 Sunday, November 8, 2009 14
The GENMOD Procedure
NOTE: The scale parameter was held fixed.
Observation Statistics
Observation count Pred Xbeta Std HessWgt Resraw
Reschi Resdev StResdev StReschi Reslik
1 950 2975 7.9979993 0.0129641 2975 -2025
-37.12629 -43.37141 -61.33643 -52.5045 -57.09151
2 50 2525 7.8339963 0.014072 2525 -2475
-49.25434 -67.5115 -95.47568 -69.65616 -83.56909
3 9000 4502.5 8.4123881 0.010538 4502.5 4497.5
67.026155 58.920726 83.32649 94.789297 89.242128
4 1000 547.5 6.3053625 0.0302199 547.5 452.5
19.338666 17.314319 24.486144 27.349004 25.957073
5 5000 2975 7.9979993 0.0129641 2975 2025
37.126289 33.792584 47.789931 52.504502 50.20259
6 5000 2525 7.8339963 0.014072 2525 2475
49.254341 43.381661 61.350933 69.656157 65.635041
7 5 4502.5 8.4123881 0.010538 4502.5 -4497.5
-67.02616 -94.48265 -133.6186 -94.7893 -115.8425
8 95 547.5 6.3053625 0.0302199 547.5 -452.5
-19.33867 -23.92107 -33.82951 -27.349 -30.76039
The SAS System 21:36 Sunday, November 8, 2009 15
The GENMOD Procedure
Model Information
Data Set WORK.NEWDRUG
Distribution Binomial
Link Function Logit
Dependent Variable response
Frequency Weight Variable count
Number of Observations Read 8
Number of Observations Used 8
Sum of Frequencies Read 21100
Sum of Frequencies Used 21100
Number of Events 4
Number of Trials 8
Class Level Information
Class Levels Values
trtmnt 2 1 2
Response Profile
Ordered Total
Value response Frequency
1 1 14955
2 2 6145
PROC GENMOD is modeling the probability that response='1'. One way to change this to model the
probability that response='2' is to specify the DESCENDING option in the PROC statement.
Criteria For Assessing Goodness Of Fit
Criterion DF Value Value/DF
Deviance 21E3 22107.9653 1.0479
Scaled Deviance 21E3 22107.9653 1.0479
Pearson Chi-Square 21E3 21099.9973 1.0001
Scaled Pearson X2 21E3 21099.9973 1.0001
Log Likelihood -11053.9827
Algorithm converged.
The SAS System 21:36 Sunday, November 8, 2009 16
The GENMOD Procedure
Analysis Of Parameter Estimates
Standard Wald 95% Confidence Chi-
Parameter DF Estimate Error Limits Square Pr > ChiSq
Intercept 1 2.1070 0.0320 2.0443 2.1698 4334.27 <.0001
trtmnt 1 1 -1.9430 0.0373 -2.0161 -1.8699 2715.33 <.0001
trtmnt 2 0 0.0000 0.0000 0.0000 0.0000 . .
Scale 0 1.0000 0.0000 1.0000 1.0000
NOTE: The scale parameter was held fixed.
Observation Statistics
Observation response count Pred Xbeta Std HessWgt Resraw
Reschi Resdev StResdev StReschi Reslik
1 1 950 0.5409091 0.164003 0.0191334 235.91012 0.4590909
0.9212706 1.1086064 1.1598202 0.9638302 1.144219
2 2 50 0.5409091 0.164003 0.0191334 12.416322 -0.540909
-1.085457 -1.247804 -1.250649 -1.087933 -1.249958
3 1 9000 0.8915841 2.1070253 0.0320045 869.95686 0.1084159
0.3487107 0.479073 1.4516639 1.0566463 1.106532
4 2 1000 0.8915841 2.1070253 0.0320045 96.661873 -0.891584
-2.867707 -2.107976 -2.22078 -3.021167 -2.312416
5 1 5000 0.5409091 0.164003 0.0191334 1241.6322 0.4590909
0.9212706 1.1086064 1.5010601 1.2474063 1.3915067
6 2 5000 0.5409091 0.164003 0.0191334 1241.6322 -0.540909
-1.085457 -1.247804 -1.689534 -1.469716 -1.593381
7 1 5 0.8915841 2.1070253 0.0320045 0.4833094 0.1084159
0.3487107 0.479073 0.4791917 0.348797 0.4791359
8 2 95 0.8915841 2.1070253 0.0320045 9.1828779 -0.891584
-2.867707 -2.107976 -2.11796 -2.881289 -2.126417
The SAS System 21:36 Sunday, November 8, 2009 17
The GENMOD Procedure
Model Information
Data Set WORK.NEWDRUG
Distribution Poisson
Link Function Log
Dependent Variable count
Number of Observations Read 8
Number of Observations Used 8
Class Level Information
Class Levels Values
sex 2 1 2
trtmnt 2 1 2
response 2 1 2
Criteria For Assessing Goodness Of Fit
Criterion DF Value Value/DF
Deviance 0 0.0000 .
Scaled Deviance 0 0.0000 .
Pearson Chi-Square 0 0.0000 .
Scaled Pearson X2 0 0.0000 .
Log Likelihood 160074.4114
Algorithm converged.
Analysis Of Parameter Estimates
Standard Wald 95% Chi-
Parameter DF Estimate Error Confidence Limits Square Pr > ChiSq
Intercept 1 4.5539 0.1026 4.3528 4.7550 1970.09 <.0001
sex 1 1 2.3539 0.1074 2.1435 2.5643 480.70 <.0001
sex 2 0 0.0000 0.0000 0.0000 0.0000 . .
trtmnt 1 1 3.9633 0.1036 3.7603 4.1663 1464.42 <.0001
trtmnt 2 0 0.0000 0.0000 0.0000 0.0000 . .
sex*trtmnt 1 1 1 -6.9590 0.1781 -7.3082 -6.6099 1526.44 <.0001
sex*trtmnt 1 2 0 0.0000 0.0000 0.0000 0.0000 . .
sex*trtmnt 2 1 0 0.0000 0.0000 0.0000 0.0000 . .
sex*trtmnt 2 2 0 0.0000 0.0000 0.0000 0.0000 . .
response 1 1 -2.9444 0.4588 -3.8437 -2.0451 41.18 <.0001
The SAS System 21:36 Sunday, November 8, 2009 18
The GENMOD Procedure
Analysis Of Parameter Estimates
Standard Wald 95% Chi-
Parameter DF Estimate Error Confidence Limits Square Pr > ChiSq
response 2 0 0.0000 0.0000 0.0000 0.0000 . .
sex*response 1 1 1 5.1417 0.4600 4.2400 6.0433 124.92 <.0001
sex*response 1 2 0 0.0000 0.0000 0.0000 0.0000 . .
sex*response 2 1 0 0.0000 0.0000 0.0000 0.0000 . .
sex*response 2 2 0 0.0000 0.0000 0.0000 0.0000 . .
trtmnt*response 1 1 1 2.9444 0.4593 2.0443 3.8446 41.10 <.0001
trtmnt*response 1 2 0 0.0000 0.0000 0.0000 0.0000 . .
trtmnt*response 2 1 0 0.0000 0.0000 0.0000 0.0000 . .
trtmnt*response 2 2 0 0.0000 0.0000 0.0000 0.0000 . .
sex*trtmnt*response 1 1 1 1 -2.1972 0.4828 -3.1435 -1.2510 20.71 <.0001
sex*trtmnt*response 1 1 2 0 0.0000 0.0000 0.0000 0.0000 . .
sex*trtmnt*response 1 2 1 0 0.0000 0.0000 0.0000 0.0000 . .
sex*trtmnt*response 1 2 2 0 0.0000 0.0000 0.0000 0.0000 . .
sex*trtmnt*response 2 1 1 0 0.0000 0.0000 0.0000 0.0000 . .
sex*trtmnt*response 2 1 2 0 0.0000 0.0000 0.0000 0.0000 . .
sex*trtmnt*response 2 2 1 0 0.0000 0.0000 0.0000 0.0000 . .
sex*trtmnt*response 2 2 2 0 0.0000 0.0000 0.0000 0.0000 . .
Scale 0 1.0000 0.0000 1.0000 1.0000
NOTE: The scale parameter was held fixed.
Observation Statistics
Observation count Pred Xbeta Std HessWgt Resraw
Reschi Resdev StResdev StReschi Reslik
1 950 950 6.856462 0.0324443 950 -1.14E-13
-3.69E-15 0 . . .
2 50 50 3.912023 0.1414214 50 -6.39E-14
-9.04E-15 -2.281E-9 -0.033642 -1.334E-7 -1.334E-7
3 9000 9000 9.1049799 0.0105409 9000 -3.64E-12
-3.83E-14 -2.296E-8 . . .
4 1000 1000 6.9077553 0.0316228 1000 -6.82E-12
-2.16E-13 -2.356E-8 -0.453515 -4.152E-6 -4.152E-6
5 5000 5000 8.5171932 0.0141421 5000 -1.27E-11
-1.8E-13 -1.054E-8 . . .
6 5000 5000 8.5171932 0.0141421 5000 -3.64E-12
-5.14E-14 0 0 -2.572E-7 -2.572E-7
7 5 5 1.6094379 0.4472136 5 1.319E-11
5.898E-12 6.585E-10 0.0023146 0.0000207 0.0000207
8 95 95 4.5538769 0.1025978 95 1.435E-11
1.473E-12 0 . . .
The SAS System 21:36 Sunday, November 8, 2009 19
The GENMOD Procedure
Model Information
Data Set WORK.NEWDRUG
Distribution Poisson
Link Function Log
Dependent Variable count
Number of Observations Read 8
Number of Observations Used 8
Class Level Information
Class Levels Values
sex 2 1 2
trtmnt 2 1 2
response 2 1 2
Criteria For Assessing Goodness Of Fit
Criterion DF Value Value/DF
Deviance 1 32.9989 32.9989
Scaled Deviance 1 32.9989 32.9989
Pearson Chi-Square 1 28.2187 28.2187
Scaled Pearson X2 1 28.2187 28.2187
Log Likelihood 160057.9120
Algorithm converged.
Analysis Of Parameter Estimates
Standard Wald 95% Confidence Chi-
Parameter DF Estimate Error Limits Square Pr > ChiSq
Intercept 1 4.3483 0.1053 4.1419 4.5546 1706.05 <.0001
sex 1 1 2.5770 0.1085 2.3643 2.7897 564.05 <.0001
sex 2 0 0.0000 0.0000 0.0000 0.0000 . .
trtmnt 1 1 4.1725 0.1059 3.9648 4.3801 1551.04 <.0001
trtmnt 2 0 0.0000 0.0000 0.0000 0.0000 . .
response 1 1 -1.2278 0.1452 -1.5124 -0.9432 71.49 <.0001
response 2 0 0.0000 0.0000 0.0000 0.0000 . .
sex*trtmnt 1 1 1 -7.6213 0.1504 -7.9162 -7.3265 2567.00 <.0001
sex*trtmnt 1 2 0 0.0000 0.0000 0.0000 0.0000 . .
sex*trtmnt 2 1 0 0.0000 0.0000 0.0000 0.0000 . .
The SAS System 21:36 Sunday, November 8, 2009 20
The GENMOD Procedure
Analysis Of Parameter Estimates
Standard Wald 95% Confidence Chi-
Parameter DF Estimate Error Limits Square Pr > ChiSq
sex*trtmnt 2 2 0 0.0000 0.0000 0.0000 0.0000 . .
sex*response 1 1 1 3.4055 0.1442 3.1230 3.6881 557.90 <.0001
sex*response 1 2 0 0.0000 0.0000 0.0000 0.0000 . .
sex*response 2 1 0 0.0000 0.0000 0.0000 0.0000 . .
sex*response 2 2 0 0.0000 0.0000 0.0000 0.0000 . .
trtmnt*response 1 1 1 1.2207 0.1448 0.9368 1.5046 71.02 <.0001
trtmnt*response 1 2 0 0.0000 0.0000 0.0000 0.0000 . .
trtmnt*response 2 1 0 0.0000 0.0000 0.0000 0.0000 . .
trtmnt*response 2 2 0 0.0000 0.0000 0.0000 0.0000 . .
Scale 0 1.0000 0.0000 1.0000 1.0000
NOTE: The scale parameter was held fixed.
Observation Statistics
Observation count Pred Xbeta Std HessWgt Resraw
Reschi Resdev StResdev StReschi Reslik
1 950 967.65696 6.8748776 0.0319629 967.65696 -17.65696
-0.567617 -0.569356 -5.328409 -5.31213 -5.312316
2 50 32.343056 3.4763993 0.1426775 32.343056 17.656944
3.1047384 2.8720164 4.9139446 5.3121259 5.179552
3 9000 8982.343 9.103016 0.0105448 8982.343 17.656956
0.1863035 0.1862425 5.3103906 5.3121296 5.3121274
4 1000 1017.657 6.9252582 0.0311766 1017.657 -17.65696
-0.553497 -0.555109 -5.327603 -5.31213 -5.312298
5 5000 4982.343 8.5136556 0.0141515 4982.343 17.656956
0.2501491 0.2500016 5.3089966 5.3121296 5.3121226
6 5000 5017.657 8.5207184 0.0141017 5017.657 -17.65696
-0.249267 -0.249414 -5.31525 -5.31213 -5.312136
7 5 22.656967 3.1204674 0.1503799 22.656967 -17.65697
-3.709499 -4.494846 -6.436778 -5.312133 -5.887446
8 95 77.343044 4.3482506 0.1052733 77.343044 17.656956
2.0077295 1.9378016 5.1271114 5.3121294 5.2860965
The SAS System 21:36 Sunday, November 8, 2009 21
The GENMOD Procedure
Model Information
Data Set WORK.NEWDRUG
Distribution Binomial
Link Function Logit
Dependent Variable response
Frequency Weight Variable count
Number of Observations Read 8
Number of Observations Used 8
Sum of Frequencies Read 21100
Sum of Frequencies Used 21100
Number of Events 4
Number of Trials 8
Class Level Information
Class Levels Values
sex 2 1 2
trtmnt 2 1 2
Response Profile
Ordered Total
Value response Frequency
1 1 14955
2 2 6145
PROC GENMOD is modeling the probability that response='1'. One way to change this to model the
probability that response='2' is to specify the DESCENDING option in the PROC statement.
Criteria For Assessing Goodness Of Fit
Criterion DF Value Value/DF
Deviance 21E3 20834.3355 0.9875
Scaled Deviance 21E3 20834.3355 0.9875
Pearson Chi-Square 21E3 21418.9779 1.0153
Scaled Pearson X2 21E3 21418.9779 1.0153
Log Likelihood -10417.1678
The SAS System 21:36 Sunday, November 8, 2009 22
The GENMOD Procedure
Algorithm converged.
Analysis Of Parameter Estimates
Standard Wald 95% Confidence Chi-
Parameter DF Estimate Error Limits Square Pr > ChiSq
Intercept 1 -1.2278 0.1452 -1.5124 -0.9432 71.49 <.0001
sex 1 1 3.4055 0.1442 3.1230 3.6881 557.90 <.0001
sex 2 0 0.0000 0.0000 0.0000 0.0000 . .
trtmnt 1 1 1.2207 0.1448 0.9368 1.5046 71.02 <.0001
trtmnt 2 0 0.0000 0.0000 0.0000 0.0000 . .
Scale 0 1.0000 0.0000 1.0000 1.0000
NOTE: The scale parameter was held fixed.
Observation Statistics
Observation response count Pred Xbeta Std HessWgt Resraw
Reschi Resdev StResdev StReschi Reslik
1 1 950 0.9676569 3.398478 0.1437792 29.732141 0.0323431
0.1828226 0.256428 0.4130763 0.2945064 0.3450583
2 2 50 0.9676569 3.398478 0.1437792 1.5648495 -0.967657
-5.469783 -2.619678 -2.663107 -5.560461 -2.804088
3 1 9000 0.8982343 2.1777579 0.0328749 822.68495 0.1017657
0.3365936 0.4633019 1.3913665 1.0108422 1.0597902
4 2 1000 0.8982343 2.1777579 0.0328749 91.409439 -0.898234
-2.970942 -2.137794 -2.251921 -3.129547 -2.353239
5 1 5000 0.4982343 -0.007063 0.0199559 1249.9844 0.5017657
1.0035376 1.1804108 1.6656764 1.4160909 1.5464783
6 2 5000 0.4982343 -0.007063 0.0199559 1249.9844 -0.498234
-0.996475 -1.174412 -1.657212 -1.406125 -1.537358
7 1 5 0.2265697 -1.227783 0.1452136 0.8761794 0.7734303
1.8476073 1.7231963 1.7393392 1.8649157 1.7417414
8 2 95 0.2265697 -1.227783 0.1452136 16.647408 -0.22657
-0.541241 -0.716826 -0.889828 -0.671866 -0.81994