Sas tutorial 0524

15
SAS tutorial 0524

description

review and some dummies

Transcript of Sas tutorial 0524

Page 1: Sas tutorial 0524

SAS tutorial 0524

Page 2: Sas tutorial 0524

proc anova;

class A B S;

model y=S|A|B;

test h=A e= S*A;

run;

The same as glm (但是比較沒用 ...)

Page 3: Sas tutorial 0524

Example

title 'Unbalanced Two-Way Analysis of Variance';

data a;

input drug disease @;

do i=1 to 6;

input y @;

output;

end;

datalines;

1 1 42 44 36 13 19 22

1 2 33 . 26 . 33 21

1 3 31 -3 . 25 25 24

2 1 28 . 23 34 42 13

2 2 . 34 33 31 . 36

2 3 3 26 28 32 4 16

3 1 . . 1 29 . 19

3 2 . 11 9 7 1 -6

3 3 21 1 . 9 3 .

4 1 24 . 9 22 -2 15

4 2 27 12 12 -5 16 15

4 3 22 7 25 5 12 .

;

Page 4: Sas tutorial 0524

4x3 2-way

Page 5: Sas tutorial 0524

code

ods graphics on;

proc glm;

class drug disease;

model y=drug disease drug*disease /ss3;

contrast 'drug 1 vs 2' drug 1 -1 0 0;

contrast 'drug 1 vs 3' drug 1 0 -1 0;

contrast 'drug 1 vs 4' drug 1 0 0 -1;

lsmeans drug/ pdiff=all adjust=tukey;

run;

ods graphics off;

Page 6: Sas tutorial 0524

Result

Page 7: Sas tutorial 0524

Interaction plot

Page 8: Sas tutorial 0524
Page 9: Sas tutorial 0524
Page 10: Sas tutorial 0524

Dummy variable

• Category variable• Set reference group• Set N-1 d.variables:

– 1 if xij belongs to the group specified

– 0 if xij belongs to other groups

• E.g. variable drug in the example:– 0 0 0 => drug=1– 1 0 0 => drug=2– 0 1 0 => drug=3– 0 0 1 => drug=4

Page 11: Sas tutorial 0524

Data

Page 12: Sas tutorial 0524

Result (is the same)

Page 13: Sas tutorial 0524

Why use d.v. coding?

http://www.sas.com/offices/NA/canada/downloads/presentations/VancouverMay11/Variable.pdf

Page 14: Sas tutorial 0524
Page 15: Sas tutorial 0524

If you cannot run contrast analysis──

• Check coefficients• Separate main effects and interactions into

different models.• e.g. 2-way ANOVA with interaction:

– model y = A B;(contrasts for main effects)

– model y = A*B;(contrasts for interaction)