0530 sas實習課
TRANSCRIPT
PROC GLM ( 複習 )
PROC GLM 選項串 ;
CLASS 變相名稱串 ;
MODEL 依變項 = 實驗效果串 / 選項串 ;
MEANS 實驗效果串 / 選項串 ;
CONTRAST “ 標題” 效果名稱串 各組效果係數 / 選項串 TEST H= 效果項 E= 殘差項RUN;
• 還有 ESTIMATE、RANDOM、 LSMEAN… 等其他 statement ,跟 PROC ANOVA 差不多
Nominal or ordinal scale
Some statements ( 複習 )• CONTRAST :作對比分析
– CONTRAST “ 標題” 效果名稱串 各組效果係數 / 選項串 ;• “ 標題”: 20 字內,不能有“ ;”• 效果名稱: 要在 model 中出現過,界定所要比較的效果• 係數:總合為 0 以空格隔開
– E.g. CONTRAST ‘A1B1 vs A2B2’ A*B 1 0 0 -1;– E.g. CONTRAST ‘b at a1’ a*b 3 3 -2 -2 -2 0 0 0 0 0;
• 選項串: e, ss3……
• TEST :指定效果項與殘差項作 F 檢定– TEST H= 效果項 E= 殘差項 ;– E.g. TEST h=A*B e=S*A*B;
• CONTRAST 必須擺在 MODEL 之後, TEST、MANOVA、REPEATED、RANDOM 之前
• CLASS 需擺在 MODEL 之前
Example 39.1title ’Balanced Data from Randomized Complete Block’;
data plants;
input Type $ @;
do Block = 1 to 3;
input StemLength @;
output;
end;
datalines;
Clarion 32.7 32.3 31.5
Clinton 32.1 29.7 29.1
Knox 35.7 35.9 33.1
O’Neill 36.0 34.2 31.2
Compost 31.8 28.0 29.2
Wabash 38.2 37.8 31.9
Webster 32.5 31.1 29.7
;
Example 39.1proc glm;
class Block Type;
model StemLength = Block Type;
run;
proc glm order=data;
class Block Type;
model StemLength = Block Type / solution;
/*----------------------------------clrn-cltn-knox-onel-cpst-wbsh-wstr */
contrast 'Compost vs. others' Type -1 -1 -1 -1 6 -1 -1;
contrast 'River soils vs. non' Type -1 -1 -1 -1 0 5 -1,
Type -1 4 -1 -1 0 0 -1;
contrast 'Glacial vs. drift' Type -1 0 1 1 0 0 -1;
contrast 'Clarion vs. Webster' Type -1 0 0 0 0 0 1;
contrast 'Knox vs. O’Neill' Type 0 0 1 -1 0 0 0;
run;
means Type / waller regwq;
run;
Repeated measures
• 如果每個參與者都作了某些作業/回答某些題目。
• 那麼這些題目/作業便稱為重複量數( repeated measures )。– 或受試者內( within subject )設計。
• 可以去除來自個體差異的 variance 。
Example: 2-way repeated ANOVA
Source SS df MS FA A / (S*A)
B B / (S*B)
A*B A*B / (S*A*B)
S
S*A
S*B
S*A*B
Error
data aaa;
do S= 1 to 3;
do A=1 to 2;
do B=1 to 2;
input x @@;
output;
end;
end;
end;
datalines;
5 10 20 10
6 11 22 13
4 12 24 9
;
GLM for repeated measures
GLM for repeated measures: code
Between
proc glm data=AAA;
class A B S;
model x=A|B|S;
test h=A e=A*S;
test h=B e=B*S;
test h=A*B e=A*B*S;
mean A B A*B/tukey alpha=.5
run;
要考慮的變項( 分子 )
要比較的值
要知道的變項( 分母 )error
Dummy coding
data k;input factor ncases @@;x0=1;x1=0;x2=0;x3=0;x4=0;if factor=1 then x1=1;if factor=2 then x2=1;if factor=3 then x3=1;if factor=4 then x4=1;cards;1 12 1 18 2 14 2 12 2 13 3 19 3 17 3 21 4 24 4 30;proc print;var factor ncases x0 x1 x2 x3 x4;
proc glm;class factor;model ncases=factor;run;proc reg;model ncases=x1 x2 x3 x4;run;proc reg;model ncases=x1 x2 x3;run;
Effect coding
data k;input factor ncases @@;x1=0;x2=0;x3=0;if factor=1 then x1=1;if factor=2 then x2=1;if factor=3 then x3=1;if factor=4 then do; x1=-1;x2=-1;x3=-1; endcards;1 12 1 18 2 14 2 12 2 13 3 19 3 17 3 21 4 24 4 30;
proc glm;class factor;model ncases=factor;run;proc reg;model ncases=x1 x2 x3 x4;run;proc reg;model ncases=x1 x2 x3;run;