SAS常用基础代码例子

您所在的位置:网站首页 sas基础代码 SAS常用基础代码例子

SAS常用基础代码例子

2023-08-25 07:34| 来源: 网络整理| 查看: 265

SAS常用基础代码例子-聚类分析

考察1985年至2000年全国如下价格指数: X1 :商品零售价格指数; X2:居民消费价格指数; X3:城市居民消费价格指数; X4: 农村居民消费价格指数;X5 :农产品收购价格指数;X6 :农村工业零售价格指数; 根据观测数据,按年份进行如下谱系聚类分析,并画出谱系图: (1) 最长距离法,给出聚为3类的结果; (2) 类平均距离法,给出聚为3类的结果; (3) 将数据标准化,再按上述方法聚类,情况又如何? 解:(1)运行一下程序: proc cluster data =prices method=complete nonorm outtree=a ; var x1-x6; id year; proc tree data=a graphics horizontal spaces=2 out=tree1 nclusters=3; id year; run; proc print data=tree1; run; 在这里插入图片描述(2)运行一下程序: proc cluster data =prices method=average nonorm outtree=a2 ; var x1-x6; id year; proc tree data=a2 graphics horizontal spaces=2 out=tree2 nclusters=3; id year; run; proc print data=tree2; run; 在这里插入图片描述(3)距离过程对数据进行标准化,运行一下程序: /最长距离法/ proc cluster data =prices method=complete std nonorm outtree=a ; var x1-x6; id year; proc tree data=a graphics horizontal spaces=2 out=tree1 nclusters=3; id year; run; proc print data=tree1; run;

最长距离法聚类过程如下: 在这里插入图片描述在这里插入图片描述聚为3类的结果为: 第一类:1994,1995,1996,1997,1998,1999,2000,它们属于各指标均较高的变量类; 第二类:1989,1990,1991,1992,1993,它们属于各指标偏中等的变量类; 第三类:1985,1986,1987,1988,它们属于各指标偏低的变量类。 最长距离法谱系图如下: 在这里插入图片描述(2)proc cluster data =prices method=average std nonorm outtree=a2 ; var x1-x6; id year; proc tree data=a2 graphics horizontal spaces=2 out=tree2 nclusters=3; id year; run; proc print data=tree2; run; 在这里插入图片描述

代码块:

data prices; input year x1-x6 @@; cards; 1985 128.1 100.0 134.2 100.0 166.8 111.1 1986 135.8 106.5 143.6 106.1 177.5 114.7 1987 145.7 114.3 156.2 112.7 198.8 120.2 1988 172.7 135.8 188.5 132.4 244.5 138.5 1989 203.4 160.2 219.2 157.9 281.2 164.4 1990 207.7 162.2 222.0 165.1 273.9 172.0 1991 213.7 170.8 233.3 168.9 268.4 177.2 1992 225.7 181.7 253.4 176.8 277.5 182.7 1993 254.9 208.4 294.2 201.0 314.7 204.3 1994 310.2 258.6 367.8 248.0 440.3 239.4 1995 356.1 302.8 429.6 291.4 527.9 274.6 1996 377.8 327.9 467.4 314.4 550.1 291.6 1997 380.8 337.1 481.9 322.3 525.3 294.8 1998 370.9 334.4 479.0 319.1 483.3 288.3 1999 359.8 329.7 472.8 314.3 424.3 280.5 2000 354.4 331.0 476.6 314.0 409.0 277.1 run; /最长距离法/ proc cluster data =prices noprint method=complete std nonorm outtree=a ; var x1-x6; id year; proc tree data=a graphics horizontal spaces=2 out=tree1 nclusters=3; id year; run; proc print data=tree1; run; /类平均距离法/ proc cluster data =prices method=average std nonorm outtree=a2 ; var x1-x6; id year; proc tree data=a2 graphics horizontal spaces=2 out=tree2 nclusters=3; id year; run; proc print data=tree2; run; /最短距离法/ proc cluster data =prices method=single std nonorm outtree=a3 ; var x1-x6; id year; proc tree data=a3 graphics horizontal spaces=2 out=tree3 nclusters=3; id year; run; proc print data=tree3; run;



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3