SlideShare a Scribd company logo
SAS tutorial : GLM
two-way anova
&
repeated measure
游如淇
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之前
2-way ANOVA
Example 39.1
title ‟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.1
proc 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;
Result-1
Result-2
Result-3
Result-4
Repeated measure
Repeated measures
• 如果每個參與者都作了某些作業/回答某
些題目。
• 那麼這些題目/作業便稱為重複量數
(repeated measures)。
– 或受試者內(within subject)設計。
• 可以去除來自個體差異的variance。
Example:
2-way repeated ANOVA
Source SS df MS F
A 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
Result (between) :
Interaction plot
Result (between)
Result (within)
DF 被model用完了,
沒有error可以除?
Result
Between
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;
Dummy coding
Dummy coding
Dummy coding – proc reg
Dummy coding – proc reg
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;
end
cards;
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;
2-way effect coding
data k;
input area ses ncases @@;
x1=0;y1=0;y2=0;
if area=1 then x1=1;
if area=2 then do; x1=-1; end;
if ses=1 then y1=1;
if ses=2 then y2=1;
If ses=3 then do; y1=-1;y2=-1;
end;
x1y1=x1*y1
x1y2=x1*y2
cards;
………………………………
;
proc print;
proc reg;
model ncases = x1 y1 y2
x1y1 x1y2;
run;

More Related Content

Viewers also liked

Foundations of Experimental Design
Foundations of Experimental DesignFoundations of Experimental Design
Foundations of Experimental Design
J P Verma
 
What is a one-way repeated measures ANOVA?
What is a one-way repeated measures ANOVA?What is a one-way repeated measures ANOVA?
What is a one-way repeated measures ANOVA?
Ken Plummer
 
Repeated Measures ANOVA - Overview
Repeated Measures ANOVA - OverviewRepeated Measures ANOVA - Overview
Repeated Measures ANOVA - Overview
Sr Edith Bogue
 
Analysis of Variance and Repeated Measures Design
Analysis of Variance and Repeated Measures DesignAnalysis of Variance and Repeated Measures Design
Analysis of Variance and Repeated Measures Design
J P Verma
 
Introduction to Analysis of Variance
Introduction to Analysis of VarianceIntroduction to Analysis of Variance
Introduction to Analysis of Variance
jasondroesch
 
Repeated anova measures ppt
Repeated anova measures pptRepeated anova measures ppt
Repeated anova measures ppt
Aamna Haneef
 
Two-way Repeated Measures ANOVA
Two-way Repeated Measures ANOVATwo-way Repeated Measures ANOVA
Two-way Repeated Measures ANOVA
J P Verma
 
Reporting a single sample t-test
Reporting a single sample t-testReporting a single sample t-test
Reporting a single sample t-test
Ken Plummer
 
Reporting a one way repeated measures anova
Reporting a one way repeated measures anovaReporting a one way repeated measures anova
Reporting a one way repeated measures anova
Ken Plummer
 
Writing up your results – apa style guidelines
Writing up your results – apa style guidelinesWriting up your results – apa style guidelines
Writing up your results – apa style guidelines
Marialena Kostouli
 
Repeated-Measures and Two-Factor Analysis of Variance
Repeated-Measures and Two-Factor Analysis of VarianceRepeated-Measures and Two-Factor Analysis of Variance
Repeated-Measures and Two-Factor Analysis of Variance
jasondroesch
 

Viewers also liked (11)

Foundations of Experimental Design
Foundations of Experimental DesignFoundations of Experimental Design
Foundations of Experimental Design
 
What is a one-way repeated measures ANOVA?
What is a one-way repeated measures ANOVA?What is a one-way repeated measures ANOVA?
What is a one-way repeated measures ANOVA?
 
Repeated Measures ANOVA - Overview
Repeated Measures ANOVA - OverviewRepeated Measures ANOVA - Overview
Repeated Measures ANOVA - Overview
 
Analysis of Variance and Repeated Measures Design
Analysis of Variance and Repeated Measures DesignAnalysis of Variance and Repeated Measures Design
Analysis of Variance and Repeated Measures Design
 
Introduction to Analysis of Variance
Introduction to Analysis of VarianceIntroduction to Analysis of Variance
Introduction to Analysis of Variance
 
Repeated anova measures ppt
Repeated anova measures pptRepeated anova measures ppt
Repeated anova measures ppt
 
Two-way Repeated Measures ANOVA
Two-way Repeated Measures ANOVATwo-way Repeated Measures ANOVA
Two-way Repeated Measures ANOVA
 
Reporting a single sample t-test
Reporting a single sample t-testReporting a single sample t-test
Reporting a single sample t-test
 
Reporting a one way repeated measures anova
Reporting a one way repeated measures anovaReporting a one way repeated measures anova
Reporting a one way repeated measures anova
 
Writing up your results – apa style guidelines
Writing up your results – apa style guidelinesWriting up your results – apa style guidelines
Writing up your results – apa style guidelines
 
Repeated-Measures and Two-Factor Analysis of Variance
Repeated-Measures and Two-Factor Analysis of VarianceRepeated-Measures and Two-Factor Analysis of Variance
Repeated-Measures and Two-Factor Analysis of Variance
 

Similar to 0530 sas實習課

Design matrix and Contrast
Design matrix and ContrastDesign matrix and Contrast
Design matrix and Contrast
Gang Cui
 
SAS Notes
SAS NotesSAS Notes
SAS Notes
Yanli Liu
 
BU_FCAI_SCC430_Modeling&Simulation_Ch05-P2.pptx
BU_FCAI_SCC430_Modeling&Simulation_Ch05-P2.pptxBU_FCAI_SCC430_Modeling&Simulation_Ch05-P2.pptx
BU_FCAI_SCC430_Modeling&Simulation_Ch05-P2.pptx
MaiGaafar
 
Control Structures.pptx
Control Structures.pptxControl Structures.pptx
Control Structures.pptx
ssuserfb3c3e
 
presentation.pptx
presentation.pptxpresentation.pptx
presentation.pptx
raghav415187
 
Scalar expressions and control structures in perl
Scalar expressions and control structures in perlScalar expressions and control structures in perl
Scalar expressions and control structures in perl
sana mateen
 
Practical Examples using Eviews.ppt
Practical Examples using Eviews.pptPractical Examples using Eviews.ppt
Practical Examples using Eviews.ppt
dipadtt
 
vb.net.pdf
vb.net.pdfvb.net.pdf
vb.net.pdf
VimalSangar1
 
VTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in CVTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in C
Syed Mustafa
 
answer-model-qp-15-pcd13pcd
answer-model-qp-15-pcd13pcdanswer-model-qp-15-pcd13pcd
answer-model-qp-15-pcd13pcd
Syed Mustafa
 
PPS-UNIT4.pptx
PPS-UNIT4.pptxPPS-UNIT4.pptx
C Operators and Control Structures.pdf
C Operators and Control Structures.pdfC Operators and Control Structures.pdf
C Operators and Control Structures.pdf
MaryJacob24
 
Lecture05 abap on line
Lecture05 abap on lineLecture05 abap on line
Lecture05 abap on line
Milind Patil
 
Digital System Design-Switchlevel and Behavioural Modeling
Digital System Design-Switchlevel and Behavioural ModelingDigital System Design-Switchlevel and Behavioural Modeling
Digital System Design-Switchlevel and Behavioural Modeling
Indira Priyadarshini
 
1. linear model, inference, prediction
1. linear model, inference, prediction1. linear model, inference, prediction
1. linear model, inference, prediction
Malik Hassan Qayyum 🕵🏻‍♂️
 
C-Programming Control statements.pptx
C-Programming Control statements.pptxC-Programming Control statements.pptx
C-Programming Control statements.pptx
SKUP1
 
C-Programming Control statements.pptx
C-Programming Control statements.pptxC-Programming Control statements.pptx
C-Programming Control statements.pptx
LECO9
 
M2 (1).pptxisedepofengiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
M2 (1).pptxisedepofengiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiM2 (1).pptxisedepofengiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
M2 (1).pptxisedepofengiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
rakshithatan
 
Lecture13 control statementswitch.ppt
Lecture13 control statementswitch.pptLecture13 control statementswitch.ppt
Lecture13 control statementswitch.ppt
eShikshak
 
Control statments in c
Control statments in cControl statments in c
Control statments in c
CGC Technical campus,Mohali
 

Similar to 0530 sas實習課 (20)

Design matrix and Contrast
Design matrix and ContrastDesign matrix and Contrast
Design matrix and Contrast
 
SAS Notes
SAS NotesSAS Notes
SAS Notes
 
BU_FCAI_SCC430_Modeling&Simulation_Ch05-P2.pptx
BU_FCAI_SCC430_Modeling&Simulation_Ch05-P2.pptxBU_FCAI_SCC430_Modeling&Simulation_Ch05-P2.pptx
BU_FCAI_SCC430_Modeling&Simulation_Ch05-P2.pptx
 
Control Structures.pptx
Control Structures.pptxControl Structures.pptx
Control Structures.pptx
 
presentation.pptx
presentation.pptxpresentation.pptx
presentation.pptx
 
Scalar expressions and control structures in perl
Scalar expressions and control structures in perlScalar expressions and control structures in perl
Scalar expressions and control structures in perl
 
Practical Examples using Eviews.ppt
Practical Examples using Eviews.pptPractical Examples using Eviews.ppt
Practical Examples using Eviews.ppt
 
vb.net.pdf
vb.net.pdfvb.net.pdf
vb.net.pdf
 
VTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in CVTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in C
 
answer-model-qp-15-pcd13pcd
answer-model-qp-15-pcd13pcdanswer-model-qp-15-pcd13pcd
answer-model-qp-15-pcd13pcd
 
PPS-UNIT4.pptx
PPS-UNIT4.pptxPPS-UNIT4.pptx
PPS-UNIT4.pptx
 
C Operators and Control Structures.pdf
C Operators and Control Structures.pdfC Operators and Control Structures.pdf
C Operators and Control Structures.pdf
 
Lecture05 abap on line
Lecture05 abap on lineLecture05 abap on line
Lecture05 abap on line
 
Digital System Design-Switchlevel and Behavioural Modeling
Digital System Design-Switchlevel and Behavioural ModelingDigital System Design-Switchlevel and Behavioural Modeling
Digital System Design-Switchlevel and Behavioural Modeling
 
1. linear model, inference, prediction
1. linear model, inference, prediction1. linear model, inference, prediction
1. linear model, inference, prediction
 
C-Programming Control statements.pptx
C-Programming Control statements.pptxC-Programming Control statements.pptx
C-Programming Control statements.pptx
 
C-Programming Control statements.pptx
C-Programming Control statements.pptxC-Programming Control statements.pptx
C-Programming Control statements.pptx
 
M2 (1).pptxisedepofengiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
M2 (1).pptxisedepofengiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiM2 (1).pptxisedepofengiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
M2 (1).pptxisedepofengiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
 
Lecture13 control statementswitch.ppt
Lecture13 control statementswitch.pptLecture13 control statementswitch.ppt
Lecture13 control statementswitch.ppt
 
Control statments in c
Control statments in cControl statments in c
Control statments in c
 

0530 sas實習課

  • 1. SAS tutorial : GLM two-way anova & repeated measure 游如淇
  • 2. PROC GLM (複習) PROC GLM 選項串 ; CLASS 變相名稱串; MODEL 依變項=實驗效果串/選項串 ; MEANS 實驗效果串/選項串; CONTRAST “標題” 效果名稱串 各組效果係數/選項串 TEST H=效果項 E=殘差項 RUN; • 還有ESTIMATE、RANDOM、LSMEAN…等其他 statement,跟 PROC ANOVA 差不多 Nominal or ordinal scale
  • 3. 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之前
  • 5. Example 39.1 title ‟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 ;
  • 6. Example 39.1 proc 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;
  • 12. Repeated measures • 如果每個參與者都作了某些作業/回答某 些題目。 • 那麼這些題目/作業便稱為重複量數 (repeated measures)。 – 或受試者內(within subject)設計。 • 可以去除來自個體差異的variance。
  • 13. Example: 2-way repeated ANOVA Source SS df MS F A A / (S*A) B B / (S*B) A*B A*B / (S*A*B) S S*A S*B S*A*B Error
  • 14. 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
  • 15. 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
  • 20. 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;
  • 23. Dummy coding – proc reg
  • 24. Dummy coding – proc reg
  • 25. 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; end cards; 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;
  • 26. 2-way effect coding data k; input area ses ncases @@; x1=0;y1=0;y2=0; if area=1 then x1=1; if area=2 then do; x1=-1; end; if ses=1 then y1=1; if ses=2 then y2=1; If ses=3 then do; y1=-1;y2=-1; end; x1y1=x1*y1 x1y2=x1*y2 cards; ……………………………… ; proc print; proc reg; model ncases = x1 y1 y2 x1y1 x1y2; run;