R语言聚类分析因子分析t检验程序

R语言聚类分析因子分析t检验程序

ID:43033648

大小:328.85 KB

页数:11页

时间:2019-09-24

R语言聚类分析因子分析t检验程序_第1页
R语言聚类分析因子分析t检验程序_第2页
R语言聚类分析因子分析t检验程序_第3页
R语言聚类分析因子分析t检验程序_第4页
R语言聚类分析因子分析t检验程序_第5页
资源描述:

《R语言聚类分析因子分析t检验程序》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库

1、R语言聚类分析、因子分析.t检验相关程序及程序运行结果相关程序:#####读入数据x=read.delim("G:\I:机考试数据.txt",header=TRUE,row.names=1)####作系统聚类d=dist(scale(x))hcl=hclust(d);hclhc2=hclust(d/averageu)hc3=hclust(d/,centroidH)hc4=hclust(d,"ward")####绘出谱系图和聚类情况(最长距离法、类平均法)opar=par(mfrow=c(2,1),mar=c(5.2,4,0,0))plclust

2、(hc1,hang=-1)rc1=rcct.hclust(hc1,k=3,border=,lredn)plclust(hc2,hang=-1)re2=rect.hclust(hc2,k=3,border=HredM)par(opar)####绘出谱系图和聚类情况(重心法和Ward法)opar<-par(mfrow=c(2,1),mauc(524,0,0))plclust(hc3,hang=-1)re3=rect.hclust(hc3,k=3,border=HredM)plclust(hc4,hang=-1)re4=rect.hclust(hc4,

3、k=3,border=HredH)par(opar)####动态聚类法km<-kmeans(scale(x),3,nstart=35);kmsort(kmScluster)####因子分析y=read.delim("G:\j2机考试数据.txt",header=TRUE,row.names=1)R=cov(scale(y))fa<-factanal(factors=4,covmat=R);fa####计算因子得分y=read.delim("G:\上机考试数据.txt",header=TRUE,row.names=l)fa<-factanal(

4、~.,factors=4,data=y,scores="Bartlett");fafa$scores####输出因了得分####画出散点图plot(fa$scorcs[,1:2],type="n")text(fa$scores[,1],fa$scores[,2])plot(fa$scores[,3:4],type=nn")text(fa$scores[,3],fa$scores[,4])####t检验al=fa$scores[J]a2=fa$scores[,2]a3=fa$scoresf,31a4=fa$scorcs[,4]t.test(a1,a

5、2,alternative』greater”)t.test(a1,a3,altemative=Hgreatern)t.test(a1,a4,alternative=Hgreatern)t・test(a2,a3,altemative=°'greateF‘)t.test(a2,a4,altemative=,lgreaterH)t.test(a3,a4,alternative』greater”)程序运行结果:>rm(list=ls(all=TRUE))>#####读入数据>x=read.delim(nG:\上机考试数据.txt'*,header=TR

6、UE,row.names=1)>####作系统聚类>d=dist(scale(x))>hcl=hclust(d);hclCall:hclust(d=d)Clustermethod:completeDistance:euclideanNumberofobjects:35>hc2=hclust(d,MaverageH)>hc3=hclust(d,nccntroid,f)>hc4=hclust(d/'ward")>####绘出谱系图和聚类情况(最长距离法、类平均法)>opar=par(mfrow=c(2,1),mar=c(5.2,4,0,0))>plc

7、lust(hc1?hang=-1)>rc1=rcct.hclust(hc1,k=3,border=MredK)>plclust(hc2,hang=-1)>re2=rect.hclust(hc2,k=3,border=Mredn)>par(opar)>####绘出谱系图和聚类情况(重心法和Ward法)>opar<-par(mfrow=c(2,1),mar=c(5・2,4,0,0))>plclust(hc3,hang=-1)>re3=rect.hclust(hc3,k=3,border=MredM)>plclust(hc4,hang=-1)>re4=

8、rect.hclust(hc4,k=3,border=MredH)>par(opar)>####动态聚类法>km<-kmeans(sca

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。