Sas tutorial glm1
-
Upload
wensheng-chang -
Category
Technology
-
view
1.843 -
download
3
description
Transcript of Sas tutorial glm1
SAS tutorial: GLM (1)
Example 1
• xx 跟 yy 的關係是什麼?
Generalized Linear Model• X : Matrix of independent variables• Y : Matrix of dependent variables• g : vector of link functions
Example 1• Compare
– Model 1 :– Model 2 :
yy=xx
yy=xx*xx
Code of example 1畫圖ods graphics on;proc sgscatter data=ex1;plot yy*xx;run;ods graphics off;
PROC GLMproc glm data=ex1;model yy=xx;
proc glm data=ex1;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;
• CONTRAST 、 TEST 、 ESTIMATE 、 RANDOM• 其他 statement 跟 PROC ANOVA 差不多
Nominal or ordinal scale
Some statements• CONTRAST :作對比分析
– CONTRAST ’label’ effect values <...effect values> </ options> ;
– E.g. CONTRAST ‘A1B1 vs A2B2’ A*B 1 0 0 -1;
• TEST :指定效果項與殘差項作 F 檢定– TEST <H=effects> E=effect </ options> ;– E.g. TEST h=A*B e=S*A*B;
CONTRAST 必須擺在 MODEL 之後, TEST 、 MANOVA 、 REPEATED 、 RANDOM 之前
Some statements• ESTIMATE :估計參數的線性組合
– ESTIMATE ’label’ effect values <...effect values > < / options > ;
– 語法跟 CONTRAST 一樣,功能也差不多
• RANDOM :指定哪些變項是 random effect– RANDOM effects < / options > ;– E.g. RANDOM A B;
Example: unbalanced ANOVAdata 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.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.5Clinton 32.1 29.7 29.1Knox 35.7 35.9 33.1O’Neill 36.0 34.2 31.2Compost 31.8 28.0 29.2Wabash 38.2 37.8 31.9Webster 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;
Result-1
Result-2
Result-3
Result-4