Categorical Data Analysis: Chapter 7
options nodate nonumber ps=200 ls=80 formdlim=' ';
data sodium;
input group $ subject intake;
datalines;
Normal 1 10.2
Normal 2 2.2
Normal 3 0.0
Normal 4 2.6
Normal 5 0.0
Normal 6 43.1
Normal 7 45.8
Normal 8 63.6
Normal 9 1.8
Normal 10 0.0
Normal 11 3.7
Normal 12 0.0
Hyperten 1 92.8
Hyperten 2 54.8
Hyperten 3 51.6
Hyperten 4 61.7
Hyperten 5 250.8
Hyperten 6 84.5
Hyperten 7 34.7
Hyperten 8 62.2
Hyperten 9 11.0
Hyperten 10 39.1
;
proc freq;
tables group*intake / noprint cmh2 scores=rank;
run;
proc freq;
tables group*intake / noprint chisq scores=rank;
run;
proc npar1way wilcoxon;
class group;
var intake;
run;
data cortisol;
input group $ subject cortisol;
datalines;
I 1 262
I 2 307
I 3 211
I 4 323
I 5 454
I 6 339
I 7 304
I 8 154
I 9 287
I 10 356
II 1 465
II 2 501
II 3 455
II 4 355
II 5 468
II 6 362
III 1 343
III 2 772
III 3 207
III 4 1048
III 5 838
III 6 687
;
proc freq;
tables group*cortisol / noprint cmh2 scores=rank;
run;
proc npar1way wilcoxon;
class group;
var cortisol;
run;
data electrod;
input subject resist1-resist5;
type=1; resist=resist1; output;
type=2; resist=resist2; output;
type=3; resist=resist3; output;
type=4; resist=resist4; output;
type=5; resist=resist5; output;
datalines;
1 500 400 98 200 250
2 660 600 600 75 310
3 250 370 220 250 220
4 72 140 240 33 54
5 135 300 450 430 70
6 27 84 135 190 180
7 100 50 82 73 78
8 105 180 32 58 32
9 90 180 220 34 64
10 200 290 320 280 135
11 15 45 75 88 80
12 160 200 300 300 220
13 250 400 50 50 92
14 170 310 230 20 150
15 66 1000 1050 280 220
16 107 48 26 45 51
;
proc freq;
tables subject*type*resist / noprint cmh2 scores=rank;
run;
proc standard mean=0;
by subject;
var resist;
proc rank;
var resist;
proc freq;
tables subject*type*resist / noprint cmh2;
run;
data tracing;
keep subject angle time;
input subject angle1 angle2 time1 time2;
angle=angle1; time=time1; output;
angle=angle2; time=time2; output;
datalines;
1 0.0 22.5 7 15
2 0.0 45.0 20 72
3 0.0 67.5 8 26
4 0.0 90.0 33 36
5 22.5 0.0 16 7
6 22.5 45.0 68 67
7 22.5 67.5 33 64
8 22.5 90.0 34 12
9 45.0 0.0 96 10
10 45.0 22.5 59 29
11 45.0 67.5 17 9
12 45.0 90.0 100 15
13 67.5 0.0 32 16
14 67.5 22.5 32 19
15 67.5 45.0 39 36
16 67.5 90.0 44 54
17 90.0 0.0 38 16
18 90.0 22.5 12 17
19 90.0 45.0 11 37
20 90.0 67.5 6 56
;
proc freq;
tables subject*angle*time / noprint cmh2 scores=rank;
run;
data exercise;
input sex $ case duration vo2max @@;
datalines;
M 1 706 41.5 M 2 732 45.9 M 3 930 54.5 M 4 900 60.3
M 5 903 60.5 M 6 976 64.6 M 7 819 47.4 M 8 922 57.0
M 9 600 40.2 M 10 540 35.2 M 11 560 33.8 M 12 637 38.8
M 13 593 38.9 M 14 719 49.5 M 15 615 37.1 M 16 589 32.2
M 17 478 31.3 M 18 620 33.8 M 19 710 43.7 M 20 600 41.7
M 21 660 41.0 M 22 644 45.9 M 23 582 35.8 M 24 503 29.1
M 25 747 47.2 M 26 600 30.0 M 27 491 34.1 M 28 694 38.1
M 29 586 28.7 M 30 612 37.1 M 31 610 34.5 M 32 539 34.4
M 33 559 35.1 M 34 653 40.9 M 35 733 45.4 M 36 596 36.9
M 37 580 41.6 M 38 550 22.7 M 39 497 31.9 M 40 605 42.5
M 41 552 37.4 M 42 640 48.2 M 43 500 33.6 M 44 603 45.0
F 1 660 38.1 F 2 628 38.4 F 3 637 41.7 F 4 575 33.5
F 5 590 28.6 F 6 600 23.9 F 7 562 29.6 F 8 495 27.3
F 9 540 33.2 F 10 470 26.6 F 11 408 23.6 F 12 387 23.1
F 13 564 36.6 F 14 603 35.8 F 15 420 28.0 F 16 573 33.8
F 17 602 33.6 F 18 430 21.0 F 19 508 31.2 F 20 565 31.2
F 21 464 23.7 F 22 495 24.5 F 23 461 30.5 F 24 540 25.9
F 25 588 32.7 F 26 498 26.9 F 27 483 24.6 F 28 554 28.8
F 29 521 25.9 F 30 436 24.4 F 31 398 26.3 F 32 366 23.2
F 33 439 24.6 F 34 549 28.8 F 35 360 19.6 F 36 566 31.4
F 37 407 26.6 F 38 602 30.6 F 39 488 27.5 F 40 526 30.9
F 41 524 33.9 F 42 562 32.3 F 43 496 26.9
;
run;
proc rank out=ranks;
var duration vo2max;
run;
proc reg noprint;
model vo2max=duration;
output out=residual r=resid;
run;
proc freq;
tables sex*resid / noprint cmh2;
run;
data caries;
input center id group $ before after @@;
datalines;
1 1 W 7 11 1 2 W 20 24 1 3 W 21 25 1 4 W 1 2
1 5 W 3 7 1 6 W 20 23 1 7 W 9 13 1 8 W 2 4
1 9 SF 11 13 1 10 SF 15 18 1 11 APF 7 10 1 12 APF 17 17
1 13 APF 9 11 1 14 APF 1 5 1 15 APF 3 7 2 1 W 10 14
2 2 W 13 17 2 3 W 3 4 2 4 W 4 7 2 5 W 4 9
2 6 SF 15 18 2 7 SF 6 8 2 8 SF 4 6 2 9 SF 18 19
2 10 SF 11 12 2 11 SF 9 9 2 12 SF 4 7 2 13 SF 5 7
2 14 SF 11 14 2 15 SF 4 6 2 16 APF 4 4 2 17 APF 7 7
2 18 APF 0 4 2 19 APF 3 3 2 20 APF 0 1 2 21 APF 8 8
3 1 W 2 4 3 2 W 13 18 3 3 W 9 12 3 4 W 15 18
3 5 W 13 17 3 6 W 2 5 3 7 W 9 12 3 8 SF 4 6
3 9 SF 10 14 3 10 SF 7 11 3 11 SF 14 15 3 12 SF 7 10
3 13 SF 3 6 3 14 SF 9 12 3 15 SF 8 10 3 16 SF 19 19
3 17 SF 10 13 3 18 APF 10 12 3 19 APF 7 11 3 20 APF 13 12
3 21 APF 5 8 3 22 APF 1 3 3 23 APF 8 9 3 24 APF 4 5
3 25 APF 4 7 3 26 APF 14 14 3 27 APF 8 10 3 28 APF 3 5
3 29 APF 11 12 3 30 APF 16 18 3 31 APF 8 8 3 32 APF 0 1
3 33 APF 3 4
;
run;
proc rank nplus1 ties=mean out=ranks;
by center;
var before after;
run;
proc reg noprint;
by center;
model after=before;
output out=residual r=resid;
run;
proc freq;
tables center*group*resid / noprint cmh2;
run;
Statistics and Operations Research