《统计软件SAS简介及程序示例.ppt》由会员分享,可在线阅读,更多相关《统计软件SAS简介及程序示例.ppt(84页珍藏版)》请在三一文库上搜索。
1、统计软件SAS简介及程序范例,1. SAS 2. 试验统计方法教材例题的SAS程序及运行结果,1. SAS简介,SAS (Statistical Analysis System,统计分析系统)是当今国际上著名的数据分析软件系统,其基本部分是SAS/BASE软件。20世纪60年代末期,由美国北卡罗纳州州立大学(North Carolina State University)的A. J. Barr和J. H. Goodnight两位教授开始开发,1975年创建了美国SAS研究所(SAS Institute Inc.)。之后,推出的SAS系统,始终以领先的技术和可靠的支持著称于世,通过不断发展和完善
2、,目前已成为大型集成应用软件系统。,SAS系统具有统计分析方法丰富、信息储存简单、语言编程能力强、能对数据连续处理、使用简单等特点。SAS是一个出色的统计分析系统,它汇集了大量的统计分析方法,从简单的描述统计到复杂的多变量分析,编制了大量的使用简便的统计分析过程。,SAS系统运行的几个重要前提条件,(一)SAS系统运行时要同时打开的文件较多,因此在微型计算机的系统配置文件CONFIG.SYS中应指定FILES=50或以上; (二)SAS系统软件有时间租期限制,因此只有机器时间(DATE)在软件有效期内才能运行。时间租期取决于SAS出售版本日期,即所谓的SAS诞生日(BIRTHDAY)。 (三)
3、SAS系统应全部安装到硬盘的SAS子目录下,硬盘应至少有10M空间。,SAS for Windows的启动与退出,(一)启动 SAS for Windows的启动,按如下步骤进行。开机后,直接用鼠标双击桌面上SAS系统的快捷键图标,自动显示主画面,即可进入SAS系统。,(二)退出 当用完SAS for Windows,需要退出时,可以单击【File】,选择【Exit】,或者,单击(关闭)按钮,立即显示。 如果确认需要退出SAS for Windows,单击确定按钮;如果需要继续使用SAS for Windows,单击取消按钮。,2. 试验统计方法教材例题的SAS程序及运行结果,t测验 方差分析
4、 直线回归分析 协方差分析,t检验,样本平均数与总体平均数的差异显著性检验 配对试验资料的t检验 非配对试验资料的t检验,样本平均数与总体平均数的差异显著性检验(例4.3),data testt1; input x; differ=x-27.5; cards; 32.5 28.6 28.4 24.7 29.1 27.2 29.8 33.3 29.7 ; proc means n mean stderr t prt; run;,运行结果,The MEANS Procedure Variable N Mean Std Error t Value Pr |t| x 9 29.2555556 0.86
5、23468 33.93 .0001 differ 9 1.7555556 0.8623468 2.04 0.0762,配对试验资料的t检验(例4.7),data testt2; input treat x1 x2; differ=x1-x2; cards; 1 2722.2 951.4 2 2866.7 1417.0 3 2675.9 1275.3 4 2169.2 2228.5 5 2253.9 2462.6 6 2415.1 2715.4 ; proc means mean stderr t prt; var differ; run;,运行结果,The MEANS Procedure An
6、alysis Variable : differ Mean Std Error t Value Pr |t| 675.4666667 391.5253952 1.73 0.1451,非配对试验资料的t检验(例4.5),data testt3; input variety x; cards; 1 18.68 1 20.67 1 18.42 1 18.00 1 17.44 1 15.95 2 18.68 2 23.22 2 21.42 2 19.00 2 18.92 ; proc ttest; class variety; var x; run;,运行结果,The TTEST Procedure
7、T-Tests Variable Method Variances DF t Value Pr |t| x Pooled Equal 9 -1.92 0.0868 x Satterthwaite Unequal 7.51 -1.87 0.1001 Equality of Variances Variable Method Num DF Den DF F Value Pr F x Folded F 4 5 1.66 0.5880,方差分析,单因素完全随机化试验重复数相等资料 单因素完全随机化试验重复数不等资料 两因素交叉分组试验单独观测值资料 两因素交叉分组试验有重复观测值资料 次级样本含量相等
8、的二因素系统分组资料 单因素随机区组设计试验资料 拉丁方设计试验结果 两因素随机区组设计试验资料 两因素裂区设计试验资料,单因素完全随机化试验重复数相等资料的方差分析(教材【例5.3】),data anova1; input variety x; cards; 1 12 1 10 1 14 1 16 1 12 1 18 2 8 2 10 2 12 2 14 2 12 2 16 3 14 3 16 3 13 3 16 3 10 3 15 4 16 4 18 4 20 4 16 4 14 4 16 ; proc anova; class variety; model x=variety; mean
9、s variety/duncan; run;,运行结果,The ANOVA Procedure Class Level Information Class Levels Values variety 4 1 2 3 4 Number of observations 24,The ANOVA Procedure Dependent Variable: x Sum of Source DF Squares Mean Square F Value Pr F Model 3 67.1666667 22.3888889 3.43 0.0369 Error 20 130.6666667 6.5333333
10、 Corrected Total 23 197.8333333 R-Square Coeff Var Root MSE x Mean 0.339511 18.14939 2.556039 14.08333 Source DF Anova SS Mean Square F Value Pr F variety 3 67.16666667 22.38888889 3.43 0.0369,The ANOVA Procedure Duncans Multiple Range Test for x NOTE: This test controls the Type I comparisonwise er
11、ror rate, not the experimentwise error rate. Alpha 0.05 Error Degrees of Freedom 20 Error Mean Square 6.533333 Number of Means 2 3 4 Critical Range 3.078 3.231 3.328,Means with the same letter are not significantly different. Duncan Grouping Mean N variety A 16.667 6 4 A B A 14.000 6 3 B A B A 13.66
12、7 6 1 B B 12.000 6 2,单因素完全随机化试验重复数不等资料的方差分析(教材【例5.4】),data anova2; input variety x; cards; 1 21.5 1 19.5 1 20.0 1 22.0 1 18.0 1 20.0 2 16.0 2 18.5 2 17.0 2 15.5 2 20.0 2 16.0 3 19.0 3 17.5 3 20.0 3 18.0 3 17.0 4 21.0 4 18.5 4 19.0 4 20.0 5 15.5 5 18.0 5 17.0 5 16.0 ; proc glm; class variety; model x
13、=variety; means variety/duncan; run;,运行结果,The GLM Procedure Class Level Information Class Levels Values variety 5 1 2 3 4 5 Number of observations 25,The GLM Procedure Dependent Variable: x Sum of Source DF Squares Mean Square F Value Pr F Model 4 46.49833333 11.62458333 5.99 0.0025 Error 20 38.8416
14、6667 1.94208333 Corrected Total 24 85.34000000 R-Square Coeff Var Root MSE x Mean 0.544860 7.565616 1.393587 18.42000 Source DF Type I SS Mean Square F Value Pr F variety 4 46.49833333 11.62458333 5.99 0.0025 Source DF Type III SS Mean Square F Value Pr F variety 4 46.49833333 11.62458333 5.99 0.002
15、5,The GLM Procedure Duncans Multiple Range Test for x NOTE: This test controls the Type I comparisonwise error rate, not the experimentwise error rate. Alpha 0.05 Error Degrees of Freedom 20 Error Mean Square 1.942083 Harmonic Mean of Cell Sizes 4.83871 NOTE: Cell sizes are not equal. Number of Mean
16、s 2 3 4 5 Critical Range 1.869 1.962 2.021 2.062,Means with the same letter are not significantly different. Duncan Grouping Mean N variety A 20.1667 6 1 A A 19.6250 4 4 A B A 18.3000 5 3 B B 17.1667 6 2 B B 16.6250 4 5,两因素交叉分组试验单独观测值资料的方差分析(教材【例5.5】),data anova3; input field method x; cards; 1 1 71
17、 1 2 73 1 3 77 2 1 90 2 2 90 2 3 92 3 1 59 3 2 70 3 3 80 4 1 75 4 2 80 4 3 82 5 1 65 5 2 60 5 3 67 6 1 82 6 2 86 6 3 85 ; proc anova; class field method; model x=field method; means field method/duncan; run;,运行结果,The ANOVA Procedure Class Level Information Class Levels Values field 6 1 2 3 4 5 6 met
18、hod 3 1 2 3 Number of observations 18,The ANOVA Procedure Dependent Variable: x Sum of Source DF Squares Mean Square F Value Pr F Model 7 1576.555556 225.222222 13.97 0.0002 Error 10 161.222222 16.122222 Corrected Total 17 1737.777778 R-Square Coeff Var Root MSE x Mean 0.907225 5.222144 4.015249 76.
19、88889 Source DF Anova SS Mean Square F Value Pr F field 5 1435.111111 287.022222 17.80 0.0001 method 2 141.444444 70.722222 4.39 0.0429,The ANOVA Procedure Duncans Multiple Range Test for x NOTE: This test controls the Type I comparisonwise error rate, not the experimentwise error rate. Alpha 0.05 E
20、rror Degrees of Freedom 10 Error Mean Square 16.12222 Number of Means 2 3 4 5 6 Critical Range 7.305 7.633 7.827 7.951 8.033,Means with the same letter are not significantly different. Duncan Grouping Mean N field A 90.667 3 2 A B A 84.333 3 6 B B C 79.000 3 4 C D C 73.667 3 1 D D E 69.667 3 3 E E 6
21、4.000 3 5,The ANOVA Procedure Duncans Multiple Range Test for x NOTE: This test controls the Type I comparisonwise error rate, not the experimentwise error rate. Alpha 0.05 Error Degrees of Freedom 10 Error Mean Square 16.12222 Number of Means 2 3 Critical Range 5.165 5.398,Means with the same lette
22、r are not significantly different. Duncan Grouping Mean N method A 80.500 6 3 A B A 76.500 6 2 B B 73.667 6 1,两因素交叉分组试验有重复观测值资料的方差分析(教材【例5.6】),data anova4; input density fert x; cards; 1 1 27 1 2 26 1 3 31 1 4 30 1 5 25 1 1 29 1 2 25 1 3 30 1 4 30 1 5 25 1 1 26 1 2 24 1 3 30 1 4 31 1 5 26 1 1 26 1 2
23、 29 1 3 31 1 4 30 1 5 24 2 1 30 2 2 28 2 3 31 2 4 32 2 5 28 2 1 30 2 2 27 2 3 31 2 4 34 2 5 29 2 1 28 2 2 26 2 3 30 2 4 33 2 5 28 2 1 29 2 2 25 2 3 32 2 4 32 2 5 27 3 1 33 3 2 33 3 3 35 3 4 35 3 5 30 3 1 33 3 2 34 3 3 33 3 4 34 3 5 29 3 1 34 3 2 34 3 3 37 3 4 33 3 5 31 3 1 32 3 2 35 3 3 35 3 4 35 3
24、5 30 ; proc anova; class density fert; model x=density fert density*fert; means density fert/duncan; means density*fert/lsd; run;,运行结果,The ANOVA Procedure Class Level Information Class Levels Values density 3 1 2 3 fert 5 1 2 3 4 5 Number of observations 60,The ANOVA Procedure Dependent Variable: x
25、Sum of Source DF Squares Mean Square F Value Pr F Model 14 573.3333333 40.9523810 33.51 F density 2 315.8333333 157.9166667 129.20 .0001 fert 4 207.1666667 51.7916667 42.38 .0001 density*fert 8 50.3333333 6.2916667 5.15 0.0001,The ANOVA Procedure Duncans Multiple Range Test for x NOTE: This test con
26、trols the Type I comparisonwise error rate, not the experimentwise error rate. Alpha 0.05 Error Degrees of Freedom 45 Error Mean Square 1.222222 Number of Means 2 3 Critical Range .7041 .7405,Means with the same letter are not significantly different. Duncan Grouping Mean N density A 33.2500 20 3 B
27、29.5000 20 2 C 27.7500 20 1,The ANOVA Procedure Duncans Multiple Range Test for x NOTE: This test controls the Type I comparisonwise error rate, not the experimentwise error rate. Alpha 0.05 Error Degrees of Freedom 45 Error Mean Square 1.222222 Number of Means 2 3 4 5 Critical Range 0.909 0.956 0.9
28、87 1.009,Means with the same letter are not significantly different. Duncan Grouping Mean N fert A 32.4167 12 4 A A 32.1667 12 3 B 29.7500 12 1 C 28.8333 12 2,The ANOVA Procedure Level of Level of -x- density fert N Mean Std Dev 1 1 4 27.0000000 1.41421356 1 2 4 26.0000000 2.16024690 1 3 4 30.500000
29、0 0.57735027 1 4 4 30.2500000 0.50000000 1 5 4 25.0000000 0.81649658 2 1 4 29.2500000 0.95742711 2 2 4 26.5000000 1.29099445 2 3 4 31.0000000 0.81649658 2 4 4 32.7500000 0.95742711 2 5 4 28.0000000 0.81649658 3 1 4 33.0000000 0.81649658 3 2 4 34.0000000 0.81649658 3 3 4 35.0000000 1.63299316 3 4 4 3
30、4.2500000 0.95742711 3 5 4 30.0000000 0.81649658,次级样本含量相等的二因素系统分组资料的方差分析【例5.7】,data anova5; input plant leaf x; cards; 1 1 12.1 1 1 12.1 1 2 12.8 1 2 12.8 2 1 14.4 2 1 14.4 2 2 14.7 2 2 14.5 3 1 23.1 3 1 23.4 3 2 28.1 3 2 28.8 ; proc anova; class plant leaf; model x=plant leaf(plant); means plant/du
31、ncan; run;,运行结果,The ANOVA Procedure Class Level Information Class Levels Values plant 3 1 2 3 leaf 2 1 2 Number of observations 12,The ANOVA Procedure Dependent Variable: x Sum of Source DF Squares Mean Square F Value Pr F Model 5 444.3500000 88.8700000 1720.06 F plant 2 416.7800000 208.3900000 4033
32、.35 .0001 leaf(plant) 3 27.5700000 9.1900000 177.87 .0001,The ANOVA Procedure Duncans Multiple Range Test for x NOTE: This test controls the Type I comparisonwise error rate, not the experimentwise error rate. Alpha 0.05 Error Degrees of Freedom 6 Error Mean Square 0.051667 Number of Means 2 3 Criti
33、cal Range .3933 .4076,Means with the same letter are not significantly different. Duncan Grouping Mean N plant A 25.8500 4 3 B 14.5000 4 2 C 12.4500 4 1,单因素随机区组设计试验资料的分析(教材【例10.1】),data anova6; input variety$ block x; cards; A 1 15.3 B 1 18.0 C 1 16.6 D 1 16.4 E 1 13.7 F 1 17.0 D 2 17.3 F 2 17.6 E 2
34、 13.6 C 2 17.8 A 2 14.9 B 2 17.6 C 3 17.6 A 3 16.2 F 3 18.2 B 3 18.6 D 3 17.3 E 3 13.9 B 4 18.3 D 4 17.8 A 4 16.2 E 4 14.0 F 4 17.5 C 4 17.8 ; proc glm; class variety block; model x=variety block; means variety/duncan; run;,运行结果,The GLM Procedure Class Level Information Class Levels Values variety 6
35、 A B C D E F block 4 1 2 3 4 Number of observations 24,The GLM Procedure Dependent Variable: x Sum of Source DF Squares Mean Square F Value Pr F Model 8 55.05833333 6.88229167 51.75 F variety 5 52.37833333 10.47566667 78.76 .0001 block 3 2.68000000 0.89333333 6.72 0.0043,The GLM Procedure Duncans Mu
36、ltiple Range Test for x NOTE: This test controls the Type I comparisonwise error rate, not the experimentwise error rate. Alpha 0.05 Error Degrees of Freedom 15 Error Mean Square 0.133 Number of Means 2 3 4 5 6 Critical range .5496 .5762 .5927 .6039 .6120,Means with the same letter are not significa
37、ntly different. Duncan Grouping Mean N variety A 18.1250 4 B B 17.5750 4 F B B 17.4500 4 C B B 17.2000 4 D C 15.6500 4 A D 13.8000 4 E,拉丁方设计试验结果的分析(教材【例10.3】),data anova7; input nd$ row col x; cards; C 1 1 10.1 A 1 2 7.9 B 1 3 9.8 E 1 4 7.1 D 1 5 9.6 A 2 1 7.0 D 2 2 10.0 E 2 3 7.0 C 2 4 9.7 B 2 5 9.
38、1 E 3 1 7.6 C 3 2 9.7 D 3 3 10.0 B 3 4 9.3 A 3 5 6.8 D 4 1 10.5 B 4 2 9.6 C 4 3 9.8 A 4 4 6.6 E 4 5 7.9 B 5 1 8.9 E 5 2 8.9 A 5 3 8.6 D 5 4 10.6 C 5 5 10.1 ; proc glm; class nd row col; model x=nd row col; means nd/duncan; run;,运行结果,The GLM Procedure Class Level Information Class Levels Values nd 5
39、A B C D E row 5 1 2 3 4 5 col 5 1 2 3 4 5 Number of observations 25,The GLM Procedure Dependent Variable: x Sum of Source DF Squares Mean Square F Value Pr F Model 12 35.50320000 2.95860000 10.88 0.0001 Error 12 3.26320000 0.27193333 Corrected Total 24 38.76640000 R-Square Coeff Var Root MSE x Mean
40、0.915824 5.867150 0.521472 8.888000 Source DF Type I SS Mean Square F Value Pr F nd 4 32.20640000 8.05160000 29.61 .0001 row 4 2.17040000 0.54260000 2.00 0.1594 col 4 1.12640000 0.28160000 1.04 0.4286,The GLM Procedure Duncans Multiple Range Test for x NOTE: This test controls the Type I comparisonw
41、ise error rate, not the experimentwise error rate. Alpha 0.05 Error Degrees of Freedom 12 Error Mean Square 0.271933 Number of Means 2 3 4 5 Critical Range .7186 .7522 .7725 .7860,Means with the same letter are not significantly different. Duncan Grouping Mean N nd A 10.1400 5 D A B A 9.8800 5 C B B
42、 9.3400 5 B C 7.7000 5 E C C 7.3800 5 A,两因素随机区组设计试验资料的方差分析(【例10.5】),data anova7; input a b block x; cards; 3 2 1 10.0 1 2 1 11.0 2 1 1 19.0 4 1 1 17.0 2 2 1 20.0 1 1 1 12.0 3 1 1 19.0 4 2 1 11.0 2 2 2 19.0 1 1 2 13.0 4 1 2 16.0 1 2 2 10.0 3 2 2 8.0 2 1 2 16.0 4 2 2 9.0 3 1 2 18.0 4 1 3 15.0 3 2 3 7.0 2 1 3 12.0 3 1 3 16.0 1 1 3 13.0 1 2 3 13.0 2 2 3 17.0 4 2 3 8.0 ; proc glm; class a b block; model x=a b block a*b; means a b a*b/duncan; run;,运行结果,The GLM Procedur