Categorical Data Analysis: Chapter 12
data salmonella;
input lab $ counts @@;
datalines;
A 63 A 64 A 65 A 68 A 69 A 70 A 72 A 73
A 75 A 80 A 82 A 83 A 83 A 84 A 84 A 85 A 90 A 91
B 168 B 171 B 174 B 175 B 185 B 189 B 190
B 191 B 195 B 197 B 198 B 198 B 203 B 205 B 205
B 207 B 210 B 214 B 216 B 218
;
proc genmod;
class lab;
model counts = lab / dist=poisson link=log type3;
run;
data melanoma;
input age $ region $ cases total;
ltotal=log(total);
datalines;
35-44 south 75 220407
45-54 south 68 198119
55-64 south 63 134084
65-74 south 45 70708
75+ south 27 34233
<35 south 64 1074246
35-44 north 76 564535
45-54 north 98 592983
55-64 north 104 450740
65-74 north 63 270908
75+ north 80 161850
<35 north 61 2880262
;
proc genmod data=melanoma;
class region (ref='north') age (ref='<35') / param=ref;
model cases = age region
/ dist=poisson link=log offset=ltotal;
run;
proc genmod data=melanoma;
class region (ref='north') age (ref='<35') / param=ref;
model cases = age region
/ dist=poisson link=log offset=ltotal;
estimate '45-54 vs. < 35' age 0 1 0 0/ exp;
estimate 'South vs. North' region 1 / exp;
run;
data lri;
input id count risk passive crowding ses agegroup race @@;
logrisk =log(risk/52);
datalines;
1 0 42 1 0 2 2 0 96 1 41 1 0 1 2 0 191 0 44 1 0 0 2 0
2 0 43 1 0 0 2 0 97 1 26 1 1 2 2 0 192 0 45 0 0 0 2 1
3 0 41 1 0 1 2 0 98 0 36 0 0 0 2 0 193 0 42 0 0 0 2 0
4 1 36 0 1 0 2 0 99 0 34 0 0 0 2 0 194 1 31 0 0 0 2 1
5 1 31 0 0 0 2 0 100 1 3 1 1 2 3 1 195 0 35 0 0 0 2 0
6 0 43 1 0 0 2 0 101 0 45 1 0 0 2 0 196 1 35 1 0 0 2 0
7 0 45 0 0 0 2 0 102 0 38 0 0 1 2 0 197 1 27 1 0 1 2 0
8 0 42 0 0 0 2 1 103 0 41 1 1 1 2 1 198 1 33 0 0 0 2 0
9 0 45 0 0 0 2 1 104 1 37 0 1 0 2 0 199 0 39 1 0 1 2 0
10 0 35 1 1 0 2 0 105 0 40 0 0 0 2 0 200 3 40 0 1 2 2 0
11 0 43 0 0 0 2 0 106 1 35 1 0 0 2 0 201 4 26 1 0 1 2 0
12 2 38 0 0 0 2 0 107 0 28 0 1 2 2 0 202 0 14 1 1 1 1 1
13 0 41 0 0 0 2 0 108 3 33 0 1 2 2 0 203 0 39 0 1 1 2 0
14 0 12 1 1 0 1 0 109 0 38 0 0 0 2 0 204 0 4 1 1 1 3 0
15 0 6 0 0 0 3 0 110 0 42 1 1 2 2 1 205 1 27 1 1 1 2 1
16 0 43 0 0 0 2 0 111 0 40 1 1 2 2 0 206 0 36 1 0 0 2 1
17 2 39 1 0 1 2 0 112 0 38 0 0 0 2 0 207 0 30 1 0 2 2 1
18 0 43 0 1 0 2 0 113 2 37 0 1 1 2 0 208 0 34 0 1 0 2 0
19 2 37 0 0 0 2 1 114 1 42 0 1 0 2 0 209 1 40 1 1 1 2 0
20 0 31 1 1 1 2 0 115 5 37 1 1 1 2 1 210 0 6 1 0 1 1 1
21 0 45 0 1 0 2 0 116 0 38 0 0 0 2 0 211 1 40 1 1 1 2 0
22 1 29 1 1 1 2 1 117 0 4 0 0 0 3 0 212 2 43 0 1 0 2 0
23 1 35 1 1 1 2 0 118 2 37 1 1 1 2 0 213 0 36 1 1 1 2 0
24 3 20 1 1 2 2 0 119 0 39 1 0 1 2 0 214 0 35 1 1 1 2 1
25 1 23 1 1 1 2 0 120 0 42 1 1 0 2 0 215 1 35 1 1 2 2 0
26 1 37 1 0 0 2 0 121 0 40 1 0 0 2 0 216 0 43 1 0 1 2 0
27 0 49 0 0 0 2 0 122 0 36 1 0 0 2 0 217 0 33 1 1 2 2 0
28 0 35 0 0 0 2 0 123 1 42 0 1 1 2 0 218 0 36 0 1 1 2 1
29 3 44 1 1 1 2 0 124 1 39 0 0 0 2 0 219 1 41 0 0 0 2 0
30 0 37 1 0 0 2 0 125 2 29 0 0 0 2 0 220 0 41 1 1 0 2 1
31 2 39 0 1 1 2 0 126 3 37 1 1 2 2 1 221 1 42 0 0 0 2 1
32 0 41 0 0 0 2 0 127 0 40 1 0 0 2 0 222 0 33 0 1 2 2 1
33 1 46 1 1 2 2 0 128 0 40 0 0 0 2 0 223 0 40 1 1 2 2 0
34 0 5 1 1 2 3 1 129 0 39 0 0 0 2 0 224 0 40 1 1 1 2 1
35 1 29 0 0 0 2 0 130 0 40 1 0 1 2 0 225 0 40 0 0 2 2 0
36 0 31 0 1 0 2 0 131 1 32 0 0 0 2 0 226 0 28 1 0 1 2 0
37 0 22 1 1 2 2 0 132 0 46 1 0 1 2 0 227 0 47 0 0 0 2 1
38 1 22 1 1 2 2 1 133 4 39 1 1 0 2 0 228 0 18 1 1 2 2 1
39 0 47 0 0 0 2 0 134 0 37 0 0 0 2 0 229 0 45 1 0 0 2 0
40 1 46 1 1 1 2 1 135 0 51 0 0 1 2 0 230 0 35 0 0 0 2 0
41 0 37 0 0 0 2 0 136 1 39 1 1 0 2 0 231 1 17 1 0 1 1 1
42 1 39 0 0 0 2 0 137 1 34 1 1 0 2 0 232 0 40 0 0 0 2 0
43 0 33 0 1 1 2 1 138 1 14 0 1 0 1 0 233 0 29 1 1 2 2 0
44 0 34 1 0 1 2 0 139 2 15 1 0 0 2 0 234 1 35 1 1 1 2 0
45 3 32 1 1 1 2 0 140 1 34 1 1 0 2 1 235 0 40 0 0 2 2 0
46 3 22 0 0 0 2 0 141 0 43 0 1 0 2 0 236 1 22 1 1 1 2 0
47 1 6 1 0 2 3 0 142 1 33 0 0 0 2 0 237 0 42 0 0 0 2 0
48 0 38 0 0 0 2 0 143 3 34 1 0 0 2 1 238 0 34 1 1 1 2 1
49 1 43 0 1 0 2 0 144 0 48 0 0 0 2 0 239 6 38 1 0 1 2 0
50 2 36 0 1 0 2 0 145 4 26 1 1 0 2 0 240 0 25 0 0 1 2 1
51 0 43 0 0 0 2 0 146 0 30 0 1 2 2 1 241 0 39 0 1 0 2 0
52 0 24 1 0 0 2 0 147 0 41 1 1 1 2 0 242 1 35 0 1 2 2 1
53 0 25 1 0 1 2 1 148 0 34 0 1 1 2 0 243 1 36 1 1 1 2 1
54 0 41 0 0 0 2 0 149 0 43 0 1 0 2 0 244 0 23 1 0 0 2 0
55 0 43 0 0 0 2 0 150 1 31 1 0 1 2 0 245 4 30 1 1 1 2 0
56 2 31 0 1 1 2 0 151 0 26 1 0 1 2 0 246 1 41 1 1 1 2 1
57 3 28 1 1 1 2 0 152 0 37 0 0 0 2 0 247 0 37 0 1 1 2 0
58 1 22 0 0 1 2 1 153 0 44 0 0 0 2 0 248 0 46 1 1 0 2 0
59 1 11 1 1 1 1 0 154 0 40 1 0 0 2 0 249 0 45 1 1 0 2 1
60 3 41 0 1 1 2 0 155 0 8 1 1 1 3 1 250 1 38 1 1 1 2 0
61 0 31 0 0 1 2 0 156 0 40 1 1 1 2 1 251 0 10 1 1 1 1 0
62 0 11 0 0 1 1 1 157 1 45 0 0 0 2 0 252 0 30 1 1 2 2 0
63 0 44 0 1 0 2 0 158 0 4 0 0 2 3 0 253 0 32 0 1 2 2 0
64 0 9 1 0 0 3 1 159 1 36 0 1 0 2 0 254 0 46 1 0 0 2 0
65 0 36 1 1 1 2 0 160 3 37 1 1 1 2 0 255 5 35 1 1 2 2 1
66 0 29 1 0 0 2 0 161 0 15 1 0 0 1 0 256 0 44 0 0 0 2 0
67 0 27 0 1 0 2 1 162 1 27 1 0 1 2 1 257 0 41 0 1 1 2 0
68 0 36 0 1 0 2 0 163 2 31 0 1 0 2 0 258 2 36 1 0 1 2 0
69 1 33 1 0 0 2 0 164 0 42 0 0 0 2 0 259 0 34 1 1 1 2 1
70 2 13 1 1 2 1 1 165 0 42 1 0 0 2 0 260 1 30 0 1 0 2 1
71 0 38 0 0 0 2 0 166 1 38 0 0 0 2 0 261 1 27 1 0 0 2 0
72 0 41 0 0 0 2 1 167 0 44 1 0 0 2 0 262 0 48 1 0 0 2 0
73 0 41 1 0 2 2 0 168 0 45 0 0 0 2 0 263 1 6 0 1 2 3 1
74 0 35 0 0 1 2 0 169 0 34 0 1 0 2 0 264 0 38 1 1 0 2 1
75 0 45 0 0 0 2 0 170 2 41 0 0 0 2 0 265 0 29 1 1 1 2 1
76 4 38 1 0 2 2 1 171 2 30 1 1 1 2 0 266 1 43 0 1 2 2 1
77 1 42 1 0 0 2 1 172 0 44 0 0 0 2 0 267 0 43 0 1 0 2 0
78 1 42 1 1 2 2 1 173 0 40 1 0 0 2 0 268 0 37 1 0 2 2 0
79 6 36 1 1 0 2 0 174 2 31 0 0 0 2 0 269 1 23 1 1 0 2 1
80 2 23 1 1 1 2 1 175 0 41 1 0 0 2 0 270 0 44 0 0 1 2 0
81 1 32 0 0 1 2 0 176 0 41 0 0 0 2 0 271 0 5 0 1 1 3 1
82 0 41 0 1 0 2 0 177 0 39 1 0 0 2 0 272 0 25 1 0 2 2 0
83 0 50 0 0 0 2 0 178 0 40 1 0 0 2 0 273 0 25 1 0 1 2 0
84 0 42 1 1 1 2 1 179 2 35 1 0 2 2 0 274 1 28 1 1 1 2 1
85 1 30 0 0 0 2 0 180 1 43 1 0 0 2 0 275 0 7 0 1 0 3 1
86 2 47 0 1 0 2 0 181 2 39 0 0 0 2 0 276 0 32 0 0 0 2 0
87 1 35 1 1 2 2 0 182 0 35 1 1 0 2 0 277 0 41 0 0 0 2 0
88 1 38 1 0 1 2 1 183 0 37 0 0 0 2 0 278 1 33 1 1 2 2 1
89 1 38 1 1 1 2 1 184 3 37 0 0 0 2 0 279 2 36 1 1 2 2 0
90 1 38 1 1 1 2 1 185 0 43 0 0 0 2 0 280 0 31 0 0 0 2 0
91 0 32 1 1 1 2 0 186 0 42 0 0 0 2 0 281 0 18 0 0 0 2 0
92 1 3 1 0 1 3 1 187 0 42 0 0 0 2 0 282 1 32 1 0 2 2 0
93 0 26 1 0 0 2 1 188 0 38 0 0 0 2 0 283 0 22 1 1 2 2 1
94 0 35 1 0 0 2 0 189 0 36 1 0 0 2 0 284 0 35 0 0 0 2 1
95 3 37 1 0 0 2 0 190 0 39 0 1 0 2 0
;
proc genmod data=lri;
class ses race agegroup / param=ref;
model count = passive crowding ses race agegroup /
dist=poisson offset=logrisk type3;
run;
proc genmod data=lri;
class ses race agegroup / param=ref;
model count = passive crowding ses race agegroup /
dist=poisson offset=logrisk type3 scale=pearson;
run;
proc genmod data=lri;
class ses id race agegroup / param=ref;
model count = passive crowding ses race agegroup /
dist=nb offset=logrisk type3;
run;
data rotavirus;
input region $ treatment $ counts years_risk @@ ;
log_risk=log(years_risk);
datalines;
US Vaccine 3 7500 US Placebo 58 7250
LA Vaccine 1 1250 LA Placebo 10 1250
;
run;
proc genmod;
class region treatment/ param=ref;
model counts = treatment region / dist=poisson offset= log_risk type3;
estimate 'treatment' treatment 1 /exp;
exact treatment / estimate=odds cltype=exact;
run;
data rotavirus2;
input region $ treatment $ counts years_risk @@ ;
log_risk=log(years_risk);
datalines;
US Vaccine 3 7500 US Placebo 58 7250
;
proc genmod order=data;
class treatment/ param=ref;
model counts = treatment / dist=poisson offset= log_risk type3;
estimate 'treatment' treatment 1 /exp;
exact treatment / estimate=odds cltype=exact;
run;
data satisfy;
input management $ supervisor $ worker $ count;
datalines;
Bad Low Low 103
Bad Low High 87
Bad High Low 32
Bad High High 42
Good Low Low 59
Good Low High 109
Good High Low 78
Good High High 205
;
proc genmod order=data;
class management supervisor worker /param=effect;
model count= management|supervisor|worker /
link=log dist=poisson type3 wald;
run;
proc genmod order=data;
class management supervisor worker /param=effect;
model count= management|supervisor|worker@2 /
link=log dist=poisson type3 wald;
run;
proc genmod order=data;
class management supervisor worker /param=effect;
model count= management|supervisor management|worker /
link=log dist=poisson type3 wald;
run;
proc genmod order=data;
class management supervisor worker /param=effect;
model count= management|supervisor supervisor|worker /
link=log dist=poisson type3 wald;
run;
proc genmod order=data;
class management supervisor worker /param=effect;
model count= management|worker supervisor|worker /
link=log dist=poisson type3 wald;
run;
proc catmod order=data data=satisfy;
weight count;
model management*supervisor*worker=_response_ / p=freq;
loglin management|supervisor|worker@2;
run;
proc catmod order=data;
weight count;
model management*supervisor*worker=_response_
/ ml=ipf;
loglin management|supervisor|worker@2;
run;
proc logistic data=satisfy order=data;
class management supervisor /param=effect;
freq count;
model worker=management supervisor
/ link=logit;
run;