读入数据
pca = read.table("714_1.txt",header = T)
head(pca)
image.png
去除第一列
pca1 = pca[,2:9]
head(pca1)
image.png
PCA分析
pcadev=princomp(pca1,cor=T)
summary(pcadev,loadings = T)
comp1=pcadev$loadings[,1]
comp2=pcadev$loadings[,2]
comp3=pcadev$loadings[,3]
image.png
Propotion of Variance就是我们要的主成分,Comp.1和Comp.2分别为第一和第二主成分,解释度分别为80.72%和10.34%。推测前三个主成分即可解释90%以上差异。因此选择前三组即可。
出图
因为有八组数据所有需要提供八种颜色,每种颜色从前往后以此对应。
plot3d(comp1,comp2,comp3,col=c("red","gray0","blue","cyan","darkblue","green","darkgreen","lightpink"),size = 10,xlab="PC1",ylab="PC2",zlab="PC3")
rgl.spheres(comp1,comp2,comp3,r=0.03,col=c("red","gray0","blue","cyan","darkblue","green","darkgreen","lightpink"))
网友评论