Categorical Data Analysis: Chapter 6
data operate;
input hospital trt $ severity $ wt @@;
datalines;
1 v+d none 23 1 v+d slight 7 1 v+d moderate 2
1 v+a none 23 1 v+a slight 10 1 v+a moderate 5
1 v+h none 20 1 v+h slight 13 1 v+h moderate 5
1 gre none 24 1 gre slight 10 1 gre moderate 6
2 v+d none 18 2 v+d slight 6 2 v+d moderate 1
2 v+a none 18 2 v+a slight 6 2 v+a moderate 2
2 v+h none 13 2 v+h slight 13 2 v+h moderate 2
2 gre none 9 2 gre slight 15 2 gre moderate 2
3 v+d none 8 3 v+d slight 6 3 v+d moderate 3
3 v+a none 12 3 v+a slight 4 3 v+a moderate 4
3 v+h none 11 3 v+h slight 6 3 v+h moderate 2
3 gre none 7 3 gre slight 7 3 gre moderate 4
4 v+d none 12 4 v+d slight 9 4 v+d moderate 1
4 v+a none 15 4 v+a slight 3 4 v+a moderate 2
4 v+h none 14 4 v+h slight 8 4 v+h moderate 3
4 gre none 13 4 gre slight 6 4 gre moderate 4
;
proc freq order=data;
weight wt;
tables hospital*trt*severity / cmh;
tables hospital*trt*severity / cmh scores=modridit;
run;
data shoulder;
input area $ location $ size $ usage $ count @@;
datalines;
coast urban large no 174 coast urban large yes 69
coast urban medium no 134 coast urban medium yes 56
coast urban small no 150 coast urban small yes 54
coast rural large no 52 coast rural large yes 14
coast rural medium no 31 coast rural medium yes 14
coast rural small no 25 coast rural small yes 17
piedmont urban large no 127 piedmont urban large yes 62
piedmont urban medium no 94 piedmont urban medium yes 63
piedmont urban small no 112 piedmont urban small yes 93
piedmont rural large no 35 piedmont rural large yes 29
piedmont rural medium no 32 piedmont rural medium yes 30
piedmont rural small no 46 piedmont rural small yes 34
mountain urban large no 111 mountain urban large yes 26
mountain urban medium no 120 mountain urban medium yes 47
mountain urban small no 145 mountain urban small yes 68
mountain rural large no 62 mountain rural large yes 31
mountain rural medium no 44 mountain rural medium yes 32
mountain rural small no 85 mountain rural small yes 43
;
proc freq;
weight count;
tables size*usage / cmh scores=modridit;
tables area*location*size*usage / cmh scores=modridit;
tables area*size*usage / noprint cmh scores=modridit;
tables location*size*usage / noprint cmh scores=modridit;
run;
data school;
input school program $ style $ count @@;
datalines;
1 regular self 10 1 regular team 17 1 regular class 26
1 after self 5 1 after team 12 1 after class 50
2 regular self 21 2 regular team 17 2 regular class 26
2 after self 16 2 after team 12 2 after class 36
3 regular self 15 3 regular team 15 3 regular class 16
3 after self 12 3 after team 12 3 after class 20
;
proc freq;
weight count;
tables school*program*style / cmh chisq;
run;
data pump;
input subject time $ response $ @@;
datalines;
1 before no 1 after no 2 before no 2 after no
3 before no 3 after no 4 before no 4 after no
5 before no 5 after no 6 before no 6 after no
7 before no 7 after no 8 before no 8 after no
9 before no 9 after no 10 before no 10 after no
11 before no 11 after no 12 before no 12 after no
13 before no 13 after no 14 before no 14 after no
15 before no 15 after no 16 before no 16 after no
17 before no 17 after no 18 before no 18 after no
19 before no 19 after no 20 before no 20 after no
21 before no 21 after no 22 before no 22 after no
23 before no 23 after no 24 before no 24 after no
25 before no 25 after no 26 before no 26 after no
27 before no 27 after no 28 before no 28 after no
29 before no 29 after no 30 before no 30 after no
31 before no 31 after no 32 before no 32 after no
33 before no 33 after no 34 before no 34 after no
35 before no 35 after no 36 before no 36 after no
37 before no 37 after no 38 before no 38 after no
39 before no 39 after no 40 before no 40 after no
41 before no 41 after no 42 before no 42 after no
43 before no 43 after no 44 before no 44 after no
45 before no 45 after no 46 before no 46 after no
47 before no 47 after no 48 before no 48 after no
49 before no 49 after yes 50 before no 50 after yes
51 before no 51 after yes 52 before no 52 after yes
53 before no 53 after yes 54 before no 54 after yes
55 before no 55 after yes 56 before no 56 after yes
57 before no 57 after yes 58 before no 58 after yes
59 before no 59 after yes 60 before no 60 after yes
61 before no 61 after yes 62 before no 62 after yes
63 before no 63 after yes 64 before yes 64 after no
65 before yes 65 after no 66 before yes 66 after no
67 before yes 67 after no 68 before yes 68 after no
69 before yes 69 after yes 70 before yes 70 after yes
71 before yes 71 after yes 72 before yes 72 after yes
73 before yes 73 after yes 74 before yes 74 after yes
75 before yes 75 after yes 76 before yes 76 after yes
77 before yes 77 after yes 78 before yes 78 after yes
79 before yes 79 after yes 80 before yes 80 after yes
81 before yes 81 after yes 82 before yes 82 after yes
83 before yes 83 after yes 84 before yes 84 after yes
85 before yes 85 after yes 86 before yes 86 after yes
87 before yes 87 after yes
;
proc freq;
tables subject*time*response/ noprint cmh;
run;
data shoes;
input before $ after $ count;
datalines;
yes yes 19
yes no 5
no yes 15
no no 48
;
proc freq;
weight count;
tables before*after / agree;
run;
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
;
run;
data drug2; set drug;
keep patient drug response;
retain patient 0;
do i=1 to count;
patient=patient+1;
drug='A'; response=druga; output;
drug='B'; response=drugb; output;
drug='C'; response=drugc; output;
end;
proc freq;
tables patient*drug*response / noprint cmh;
run;
data cold;
keep id day drainage;
input id day1-day4;
day=1; drainage=day1; output;
day=2; drainage=day2; output;
day=3; drainage=day3; output;
day=4; drainage=day4; output;
datalines;
1 1 1 2 2
2 0 0 0 0
3 1 1 1 1
4 1 1 1 1
5 0 2 2 0
6 2 0 0 0
7 2 2 1 2
8 1 1 1 0
9 3 2 1 1
10 2 2 2 3
11 1 0 1 1
12 2 3 2 2
13 1 3 2 1
14 2 1 1 1
15 2 3 3 3
16 2 1 1 1
17 1 1 1 1
18 2 2 2 2
19 3 1 1 1
20 1 1 2 1
21 2 1 1 2
22 2 2 2 2
23 1 1 1 1
24 2 2 3 1
25 2 0 0 0
26 1 1 1 1
27 0 1 1 0
28 1 1 1 1
29 1 1 1 0
30 3 3 3 3
;
proc glm;
class day;
model drainage=id day;
lsmeans day;
estimate 'direction' day -3 -1 1 3 / divisor=6;
run;
proc freq;
tables id*day*drainage / cmh2 noprint;
tables id*day*drainage / cmh2 noprint scores=rank;
run;
data animals;
keep id pulse severity;
input id sev2 sev4 sev6 sev8 sev10;
pulse=2; severity=sev2; output;
pulse=4; severity=sev4; output;
pulse=6; severity=sev6; output;
pulse=8; severity=sev8; output;
pulse=10; severity=sev10; output;
datalines;
6 0 0 5 0 3
7 0 3 3 4 5
8 0 3 4 3 2
9 2 2 3 0 4
10 0 0 4 4 3
12 0 0 0 4 4
13 0 4 4 4 0
15 0 4 0 0 0
16 0 3 0 1 1
17 . . 0 1 0
19 0 0 1 1 0
20 . 0 0 2 2
21 0 0 2 3 3
22 . 0 0 3 0
;
proc glm;
class pulse;
model severity = id pulse;
lsmeans pulse;
estimate 'direction' pulse -4 -2 0 2 4 / divisor=10;
run;
proc freq;
tables id*pulse*severity / noprint cmh2;
tables id*pulse*severity / noprint cmh2 scores=rank;
tables id*pulse*severity / noprint cmh2 scores=ridit;
tables id*pulse*severity / noprint cmh2 scores=modridit;
run;
proc freq data=animals;
where id notin(17,20,22);
tables id*pulse*severity / noprint cmh2;
tables id*pulse*severity / noprint cmh2 scores=rank;
run;