Categorical Data Analysis: Chapter 14
options nodate nonumber ps=200 ls=80 formdlim=' ';
data drug;
input druga $ drugb $ drugc $ count;
datalines;
F F F 6
F F U 16
F U F 2
F U U 4
U F F 2
U F U 4
U U F 6
U U U 6
;
proc catmod;
weight count;
response marginals;
model druga*drugb*drugc=_response_ / oneway cov;
repeated drug 3 / _response_=drug;
run;
proc catmod;
weight count;
response marginals;
model druga*drugb*drugc=_response_ / oneway cov;
repeated drug 3 / _response_=drug;
contrast 'A versus C' all_parms 0 2 1;
run;
data church;
input gender $ attend0 $ attend3 $ attend6 $ count;
datalines;
F Y Y Y 904
F Y Y N 88
F Y N Y 25
F Y N N 51
F N Y Y 33
F N Y N 22
F N N Y 30
F N N N 158
M Y Y Y 391
M Y Y N 36
M Y N Y 12
M Y N N 26
M N Y Y 15
M N Y N 21
M N N Y 18
M N N N 143
;
proc catmod order=data;
weight count;
response marginals;
model attend0*attend3*attend6=gender|_response_ / oneway;
repeated year;
run;
proc freq;
weight count;
by gender;
tables attend0 attend3 attend6;
run;
proc catmod order=data;
weight count;
response marginals;
model attend0*attend3*attend6=gender _response_ / noprofile;
repeated year;
run;
data vision;
input gender $ right left count;
datalines;
F 1 1 1520
F 1 2 266
F 1 3 124
F 1 4 66
F 2 1 234
F 2 2 1512
F 2 3 432
F 2 4 78
F 3 1 117
F 3 2 362
F 3 3 1772
F 3 4 205
F 4 1 36
F 4 2 82
F 4 3 179
F 4 4 492
M 1 1 821
M 1 2 112
M 1 3 85
M 1 4 35
M 2 1 116
M 2 2 494
M 2 3 145
M 2 4 27
M 3 1 72
M 3 2 151
M 3 3 583
M 3 4 87
M 4 1 43
M 4 2 34
M 4 3 106
M 4 4 331
;
proc catmod;
weight count;
response marginals;
model right*left=gender _response_(gender='F')
_response_(gender='M');
repeated eye 2;
run;
proc catmod;
weight count;
response marginals;
model right*left=gender _response_(gender='F')
_response_(gender='M');
repeated eye 2;
contrast 'Interaction' all_parms 0 0 0 0 0 0 1 0 0 -1 0 0,
all_parms 0 0 0 0 0 0 0 1 0 0 -1 0,
all_parms 0 0 0 0 0 0 0 0 1 0 0 -1;
run;
proc catmod;
weight count;
response means;
model right*left=gender _response_(gender='F')
_response_(gender='M') / noprofile;
repeated eye;
run;
proc catmod;
weight count;
response means;
model right*left=gender _response_(gender='F')
_response_(gender='M') / noprofile;
repeated eye;
contrast 'Interaction' all_parms 0 0 1 -1;
run;
data diagnos;
input std1 $ test1 $ std2 $ test2 $ count;
datalines;
Neg Neg Neg Neg 509
Neg Neg Neg Pos 4
Neg Neg Pos Neg 17
Neg Neg Pos Pos 3
Neg Pos Neg Neg 13
Neg Pos Neg Pos 8
Neg Pos Pos Neg 0
Neg Pos Pos Pos 8
Pos Neg Neg Neg 14
Pos Neg Neg Pos 1
Pos Neg Pos Neg 17
Pos Neg Pos Pos 9
Pos Pos Neg Neg 7
Pos Pos Neg Pos 4
Pos Pos Pos Neg 9
Pos Pos Pos Pos 170
;
proc catmod;
weight count;
response marginals;
model std1*test1*std2*test2=_response_ / oneway;
repeated time 2, trtment 2 / _response_=time|trtment;
run;
proc catmod;
weight count;
response marginals;
model std1*test1*std2*test2=_response_ / noprofile;
repeated time 2, trtment 2 / _response_=trtment;
run;
data wheeze;
input wheeze9 $ wheeze10 $ wheeze11 $ wheeze12 $ count;
datalines;
Present Present Present Present 94
Present Present Present Absent 30
Present Present Absent Present 15
Present Present Absent Absent 28
Present Absent Present Present 14
Present Absent Present Absent 9
Present Absent Absent Present 12
Present Absent Absent Absent 63
Absent Present Present Present 19
Absent Present Present Absent 15
Absent Present Absent Present 10
Absent Present Absent Absent 44
Absent Absent Present Present 17
Absent Absent Present Absent 42
Absent Absent Absent Present 35
Absent Absent Absent Absent 572
;
proc catmod order=data;
weight count;
response marginals;
model wheeze9*wheeze10*wheeze11*wheeze12=_response_ / oneway;
repeated age;
run;
proc catmod order=data;
weight count;
response marginals;
model wheeze9*wheeze10*wheeze11*wheeze12=(1 9,
1 10,
1 11,
1 12)
(1='Intercept',
2='Linear Age')
/ noprofile;
run;
proc catmod order=data;
weight count;
response logits;
model wheeze9*wheeze10*wheeze11*wheeze12=(1 9,
1 10,
1 11,
1 12)
(1='Intercept',
2='Linear Age') / noprofile;
run;
data resp;
input center id treatment $ sex $ age baseline visit1-visit4 @@;
cards;
1 1 P M 46 0 0 0 0 0 2 1 P F 39 0 0 0 0 0
1 2 P M 28 0 0 0 0 0 2 2 A M 25 0 0 1 1 1
1 3 A M 23 1 1 1 1 1 2 3 A M 58 1 1 1 1 1
1 4 P M 44 1 1 1 1 0 2 4 P F 51 1 1 0 1 1
1 5 P F 13 1 1 1 1 1 2 5 P F 32 1 0 0 1 1
1 6 A M 34 0 0 0 0 0 2 6 P M 45 1 1 0 0 0
1 7 P M 43 0 1 0 1 1 2 7 P F 44 1 1 1 1 1
1 8 A M 28 0 0 0 0 0 2 8 P F 48 0 0 0 0 0
1 9 A M 31 1 1 1 1 1 2 9 A M 26 0 1 1 1 1
1 10 P M 37 1 0 1 1 0 2 10 A M 14 0 1 1 1 1
1 11 A M 30 1 1 1 1 1 2 11 P F 48 0 0 0 0 0
1 12 A M 14 0 1 1 1 0 2 12 A M 13 1 1 1 1 1
1 13 P M 23 1 1 0 0 0 2 13 P M 20 0 1 1 1 1
1 14 P M 30 0 0 0 0 0 2 14 A M 37 1 1 0 0 1
1 15 P M 20 1 1 1 1 1 2 15 A M 25 1 1 1 1 1
1 16 A M 22 0 0 0 0 1 2 16 A M 20 0 0 0 0 0
1 17 P M 25 0 0 0 0 0 2 17 P F 58 0 1 0 0 0
1 18 A F 47 0 0 1 1 1 2 18 P M 38 1 1 0 0 0
1 19 P F 31 0 0 0 0 0 2 19 A M 55 1 1 1 1 1
1 20 A M 20 1 1 0 1 0 2 20 A M 24 1 1 1 1 1
1 21 A M 26 0 1 0 1 0 2 21 P F 36 1 1 0 0 1
1 22 A M 46 1 1 1 1 1 2 22 P M 36 0 1 1 1 1
1 23 A M 32 1 1 1 1 1 2 23 A F 60 1 1 1 1 1
1 24 A M 48 0 1 0 0 0 2 24 P M 15 1 0 0 1 1
1 25 P F 35 0 0 0 0 0 2 25 A M 25 1 1 1 1 0
1 26 A M 26 0 0 0 0 0 2 26 A M 35 1 1 1 1 1
1 27 P M 23 1 1 0 1 1 2 27 A M 19 1 1 0 1 1
1 28 P F 36 0 1 1 0 0 2 28 P F 31 1 1 1 1 1
1 29 P M 19 0 1 1 0 0 2 29 A M 21 1 1 1 1 1
1 30 A M 28 0 0 0 0 0 2 30 A F 37 0 1 1 1 1
1 31 P M 37 0 0 0 0 0 2 31 P M 52 0 1 1 1 1
1 32 A M 23 0 1 1 1 1 2 32 A M 55 0 0 1 1 0
1 33 A M 30 1 1 1 1 0 2 33 P M 19 1 0 0 1 1
1 34 P M 15 0 0 1 1 0 2 34 P M 20 1 0 1 1 1
1 35 A M 26 0 0 0 1 0 2 35 P M 42 1 0 0 0 0
1 36 P F 45 0 0 0 0 0 2 36 A M 41 1 1 1 1 1
1 37 A M 31 0 0 1 0 0 2 37 A M 52 0 0 0 0 0
1 38 A M 50 0 0 0 0 0 2 38 P F 47 0 1 1 0 1
1 39 P M 28 0 0 0 0 0 2 39 P M 11 1 1 1 1 1
1 40 P M 26 0 0 0 0 0 2 40 P M 14 0 0 0 1 0
1 41 P M 14 0 0 0 0 1 2 41 P M 15 1 1 1 1 1
1 42 A M 31 0 0 1 0 0 2 42 P M 66 1 1 1 1 1
1 43 P M 13 1 1 1 1 1 2 43 A M 34 0 1 1 0 1
1 44 P M 27 0 0 0 0 0 2 44 P M 43 0 0 0 0 0
1 45 P M 26 0 1 0 1 1 2 45 P M 33 1 1 1 0 1
1 46 P M 49 0 0 0 0 0 2 46 P M 48 1 1 0 0 0
1 47 P M 63 0 0 0 0 0 2 47 A M 20 0 1 1 1 1
1 48 A M 57 1 1 1 1 1 2 48 P F 39 1 0 1 0 0
1 49 P M 27 1 1 1 1 1 2 49 A M 28 0 1 0 0 0
1 50 A M 22 0 0 1 1 1 2 50 P F 38 0 0 0 0 0
1 51 A M 15 0 0 1 1 1 2 51 A M 43 1 1 1 1 0
1 52 P M 43 0 0 0 1 0 2 52 A F 39 0 1 1 1 1
1 53 A F 32 0 0 0 1 0 2 53 A M 68 0 1 1 1 1
1 54 A M 11 1 1 1 1 0 2 54 A F 63 1 1 1 1 1
1 55 P M 24 1 1 1 1 1 2 55 A M 31 1 1 1 1 1
1 56 A M 25 0 1 1 0 1
;
proc catmod data=resp;
population treatment center;
response logits;
model visit1*visit2*visit3*visit4 =
( 1 1 1 1 0 0 1 0 0 1 0 0 1,
1 1 1 0 1 0 0 1 0 0 1 0 1,
1 1 1 0 0 1 0 0 1 0 0 1 1,
1 1 1 0 0 0 0 0 0 0 0 0 1,
1 1 0 1 0 0 1 0 0 0 0 0 0,
1 1 0 0 1 0 0 1 0 0 0 0 0,
1 1 0 0 0 1 0 0 1 0 0 0 0,
1 1 0 0 0 0 0 0 0 0 0 0 0,
1 0 1 1 0 0 0 0 0 1 0 0 0,
1 0 1 0 1 0 0 0 0 0 1 0 0,
1 0 1 0 0 1 0 0 0 0 0 1 0,
1 0 1 0 0 0 0 0 0 0 0 0 0,
1 0 0 1 0 0 0 0 0 0 0 0 0,
1 0 0 0 1 0 0 0 0 0 0 0 0,
1 0 0 0 0 1 0 0 0 0 0 0 0,
1 0 0 0 0 0 0 0 0 0 0 0 0)
(1='Intercept', 2='treatment', 3='center',
4='visit1', 5='visit2', 6='visit3', 7='tr*visit1',
8='tr*visit2', 9='tr*visit3', 10='ct*visit1',
11='ct*visit2', 12='ct*visit3', 13='trt*ct');
contrast 'treatment'
all_parms 0 1 0 0 0 0 .25 .25 .25 0 0 0 .5;
contrast 'center'
all_parms 0 0 1 0 0 0 0 0 0 .25 .25 .25 .5;
contrast 'visit' all_parms 0 0 0 1 0 0 .5 0 0 .5 0 0 0,
all_parms 0 0 0 0 1 0 0 .5 0 0 .5 0 0,
all_parms 0 0 0 0 0 1 0 0 .5 0 0 .5 0;
contrast 'trt*visit' all_parms 0 0 0 0 0 0 1 0 0 0 0 0 0,
all_parms 0 0 0 0 0 0 0 1 0 0 0 0 0,
all_parms 0 0 0 0 0 0 0 0 1 0 0 0 0;
contrast 'ct*visit' all_parms 0 0 0 0 0 0 0 0 0 1 0 0 0,
all_parms 0 0 0 0 0 0 0 0 0 0 1 0 0,
all_parms 0 0 0 0 0 0 0 0 0 0 0 1 0;
contrast 'trt*ct' all_parms 0 0 0 0 0 0 0 0 0 0 0 0 1;
run;
proc catmod data=resp;
population treatment center;
response logits;
model visit1*visit2*visit3*visit4 =
( 1 1 1 1 0 0 ,
1 1 1 0 1 0 ,
1 1 1 0 0 1 ,
1 1 1 0 0 0 ,
1 1 0 1 0 0 ,
1 1 0 0 1 0 ,
1 1 0 0 0 1 ,
1 1 0 0 0 0 ,
1 0 1 1 0 0 ,
1 0 1 0 1 0 ,
1 0 1 0 0 1 ,
1 0 1 0 0 0 ,
1 0 0 1 0 0 ,
1 0 0 0 1 0 ,
1 0 0 0 0 1 ,
1 0 0 0 0 0 )
(1='Intercept', 2='treatment', 3='center',
4='visit1', 5='visit2', 6='visit3' );
contrast 'treatment' all_parms 0 1 0 0 0 0 ;
contrast 'center' all_parms 0 0 1 0 0 0 ;
contrast 'visit' all_parms 0 0 0 1 0 0,
all_parms 0 0 0 0 1 0,
all_parms 0 0 0 0 0 1;
run;
Statistics and Operations Research