#データ読み込み enq=read.csv("enquete.csv",row.name="name") #ライブラリ読み込み install.packages("psych") install.packages("GPArotation") library(psych) library(GPArotation) #スクリープロットと初回分析 fa.parallel(enq) res1=fa(enq,nfactors=2,fm="ml",rotate="none") print(res1,digit=3) #Q3削除と2回目の分析 enq2=enq[,-3] res2=fa(enq2,nfactors=2,fm="uls",rotate="none") print(res2,digit=3) #軸の回転と検証因子分析 res3=fa(enq2, nfactors=2, fm="uls", rotate="varimax", score="Anderson") print(res3,digit=3) plot(res3$loadings,xlim=c(-0.1,1),ylim=c(-0.1,1),type="n",xlab="Factor 1",ylab="Factor 2") arrows(0,0,res3$loadings[,1],res3$loadings[,2],length=0.1) text(res3$loadings[,1],res3$loadings[,2],labels=rownames(res3$loadings)) fa.diagram(res3,digit=3) plot(res3$scores,type="n",xlab="Factor 1",ylab="Factor 2") text(res3$scores[,1],res3$scores[,2],labels=rownames(res3$scores)) #クラスター分析 dist1=dist(enq) clust1=hclust(dist1,method="ward.D2") plot(clust1,hang=-1) rect.hclust(clust1,k=3) gr1=cutree(clust1,k=3) #因子得点グラフの反映(カラー) plot(res3$scores,xlab="Factor 1",ylab="Factor 2",type="n") text(res3$scores[,1],res3$scores[,2],labels=rownames(res3$scores),col=c(gr1)) arrows(0,0,res3$loadings[,1],res3$loadings[,2],length=0.1) text(res3$loadings[,1],res3$loadings[,2],labels=rownames(res3$loadings))