Categorical Data Analysis: Chapter 5
data neighbor;
length party $ 11 neighborhood $ 10;
input party $ neighborhood $ count @@;
datalines;
democrat longview 360 democrat bayside 221
democrat sheffeld 140 democrat highland 160
republican longview 316 republican bayside 208
republican sheffeld 97 republican highland 106
independent longview 160 independent bayside 200
independent sheffeld 311 independent highland 291
;
ods graphics on;
proc freq ;
weight count;
tables party*neighborhood /
plots=mosaicplot chisq cmh nocol nopct;
run;
ods graphics off;
data pain;
input treatment $ hours count @@;
datalines;
placebo 0 6 placebo 1 9 placebo 2 6 placebo 3 3 placebo 4 1
standard 0 1 standard 1 4 standard 2 6 standard 3 6 standard 4 8
test 0 2 test 1 5 test 2 6 test 3 8 test 4 6
;
proc freq;
weight count;
tables treatment*hours/ cmh nocol nopct;
run;
proc means;
freq count;
class treatment;
var hours;
run;
data wash;
input treatment $ washability $ count @@;
datalines;
water low 27 water medium 14 water high 5
standard low 10 standard medium 17 standard high 26
super low 5 super medium 12 super high 50
;
proc freq order=data;
weight count;
tables treatment*washability / chisq cmh nocol nopct;
tables treatment*washability / scores=modridit cmh
noprint nocol nopct;
run;
data market;
length AdSource $ 9. ;
input car $ AdSource $ count @@;
datalines;
sporty paper 3 sporty radio 4 sporty tv 0 sporty magazine 3
sedan paper 0 sedan radio 2 sedan tv 4 sedan magazine 0
utility paper 2 utility radio 2 utility tv 5 utility magazine 5
;
proc freq;
weight count;
table car*AdSource / norow nocol nopct;
exact fisher pchi lrchi;
run;
data disorder;
input dose outcome count @@;
datalines;
25 0 1 25 1 1 25 2 1 25 3 0
50 0 1 50 1 2 50 2 1 50 3 1
75 0 0 75 1 0 75 2 2 75 3 2
100 0 0 100 1 0 100 2 7 100 3 0
;
proc freq;
weight count;
tables dose*outcome / nocol norow nopct measures;
exact mhchi;
run;
data wash;
input treatment $ washability $ count @@;
datalines;
water low 27 water medium 14 water high 5
standard low 10 standard medium 17 standard high 26
super low 5 super medium 12 super high 50
;
proc freq order=data;
weight count;
tables treatment*washability / measures noprint nocol nopct cl;
tables treatment*washability / measures scores=rank noprint cl;
run;
data soccer;
input grades $ degree $ count @@;
datalines;
1-2 low 3 1-2 medium 1 1-2 high 0
3-4 low 3 3-4 medium 2 3-4 high 1
5-6 low 1 5-6 medium 3 5-6 high 2
;
proc freq order=data;
weight count;
tables grades*degree / nocol nopct norow;
exact scorr;
run;
data neighbor;
length party $ 11 neighborhood $ 10;
input party $ neighborhood $ count @@;
datalines;
democrat longview 360 democrat bayside 221
democrat sheffeld 140 democrat highland 160
republican longview 316 republican bayside 208
republican sheffeld 97 republican highland 106
independent longview 160 independent bayside 200
independent sheffeld 311 independent highland 291
;
proc freq ;
weight count;
tables party*neighborhood / chisq measures nocol nopct;
run;
data classify;
input no_rater w_rater count @@;
datalines;
1 1 38 1 2 5 1 3 0 1 4 1
2 1 33 2 2 11 2 3 3 2 4 0
3 1 10 3 2 14 3 3 5 3 4 6
4 1 3 4 2 7 4 3 3 4 4 10
;
ods graphics on;
proc freq;
weight count;
tables no_rater*w_rater / agree norow nocol nopct;
run;
ods graphics off;
data pilot;
input rater1 rater2 count @@;
datalines;
1 1 4 1 2 0 1 3 1 1 4 0
2 1 0 2 2 2 2 3 6 2 4 1
3 1 1 3 2 0 3 3 2 3 4 1
4 1 0 4 2 2 4 3 1 4 4 3
;
proc freq;
weight count;
tables rater1*rater2 /norow nocol nopct;
exact kappa;
run;
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 trt*severity / chisq scores=rank norow nocol nopct jt;
run;