際際滷

際際滷Share a Scribd company logo
SAS tutorial: GLM (1)
Example 1




? xx効yy議PS頁焚N
Generalized Linear Model
Example 1
yy=xx




yy=xx*xx
Code of example 1
D                         PROC GLM
ods graphics on;           proc glm data=ex1;
proc sgscatter data=ex1;   model yy=xx;
plot yy*xx;
run;                       proc glm data=ex1;
ods graphics off;          model yy=xx*xx;
                           run;
PROC GLM┨δ棕
?   Simple / multiple regression
?   ANOVA / MANOVA
?   ANOVA for repeated measures
?   ANCOVA
?   Weighted regression
?   Partial correlation
?   Polynomial regression
PROC GLM (syntax)
PROC GLM <options> ;
CLASS variables </ option> ;
MODEL dependents=independents </ options> ;
RUN;
            Nominal or ordinal scale



? CONTRAST、TEST、ESTIMATE、RANDOM
? 凪麿 statement 効 PROC ANOVA 餓音謹
Some statements
? CONTRAST祭Ρ鳩嵶
 C CONTRAST ¨label¨ effect values <...effect values>
   </ options> ;
 C E.g. CONTRAST `A1B1 vs A2B2¨          A*B 1 0 0 -1;


? TEST砦原丼惚c餓恬Fz協
 C TEST <H=effects> E=effect </ options> ;
 C E.g. TEST h=A*B e=S*A*B;


? CONTRAST駅[壓MODEL岻瘁TEST、
  MANOVA、REPEATED、RANDOM岻念
Some statements
? ESTIMATE差績亀直來M栽
 C ESTIMATE ¨label¨ effect values <...effect values >
   < / options > ;
 C Z隈効CONTRAST匯咤孔嬬匆餓音謹


? RANDOM砦原陳乂頁 random effect
 C RANDOM effects < / options > ;
 C E.g. RANDOM A B;
Example: unbalanced
      ANOVA
    data exp;
    input A $ B $ Y @@;
    datalines;
    A1 B1 12 A1 B1 14 A1 B2 11
    A1 B2 9 A2 B1 20 A2 B1 18
    A2 B2 17
    ;
    proc glm data=exp;
    class A B;
    model Y=A B A*B;
    run;
Result
勣議|廉
? N-way ANOVA (with interaction)
? Unbalanced ANOVA
? Polynomial regression
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

More Related Content

Sas tutorial glm1

  • 5. Code of example 1 D PROC GLM ods graphics on; proc glm data=ex1; proc sgscatter data=ex1; model yy=xx; plot yy*xx; run; proc glm data=ex1; ods graphics off; model yy=xx*xx; run;
  • 6. PROC GLM┨δ棕 ? Simple / multiple regression ? ANOVA / MANOVA ? ANOVA for repeated measures ? ANCOVA ? Weighted regression ? Partial correlation ? Polynomial regression
  • 7. PROC GLM (syntax) PROC GLM <options> ; CLASS variables </ option> ; MODEL dependents=independents </ options> ; RUN; Nominal or ordinal scale ? CONTRAST、TEST、ESTIMATE、RANDOM ? 凪麿 statement 効 PROC ANOVA 餓音謹
  • 8. Some statements ? CONTRAST祭Ρ鳩嵶 C CONTRAST ¨label¨ effect values <...effect values> </ options> ; C E.g. CONTRAST `A1B1 vs A2B2¨ A*B 1 0 0 -1; ? TEST砦原丼惚c餓恬Fz協 C TEST <H=effects> E=effect </ options> ; C E.g. TEST h=A*B e=S*A*B; ? CONTRAST駅[壓MODEL岻瘁TEST、 MANOVA、REPEATED、RANDOM岻念
  • 9. Some statements ? ESTIMATE差績亀直來M栽 C ESTIMATE ¨label¨ effect values <...effect values > < / options > ; C Z隈効CONTRAST匯咤孔嬬匆餓音謹 ? RANDOM砦原陳乂頁 random effect C RANDOM effects < / options > ; C E.g. RANDOM A B;
  • 10. Example: unbalanced ANOVA data exp; input A $ B $ Y @@; datalines; A1 B1 12 A1 B1 14 A1 B2 11 A1 B2 9 A2 B1 20 A2 B1 18 A2 B2 17 ; proc glm data=exp; class A B; model Y=A B A*B; run;
  • 12. 勣議|廉 ? N-way ANOVA (with interaction) ? Unbalanced ANOVA ? Polynomial regression
  • 13. 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 ;
  • 14. 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;