1. 首页
  2. 自学中心
  3. 软件
  4. R

R:数据分析之主成分分析princomp

 x1=rnorm(100)
> x2=rnorm(100)
> x3=rnorm(100)
> data=data.frame(x1,x2,x3)
> data.pr=princomp(data,cor=TRUE)
> data.pr
Call:
princomp(x = data, cor = TRUE)
Standard deviations:
   Comp.1    Comp.2    Comp.3 
1.0919785 1.0120505 0.8850631 
 3  variables and  100 observations.
> summary(data.pr,loadings=TRUE)
Importance of components:
                          Comp.1    Comp.2    Comp.3
Standard deviation     1.0919785 1.0120505 0.8850631#主成分的标准差
Proportion of Variance 0.3974724 0.3414154 0.2611122#方差的贡献率
Cumulative Proportion  0.3974724 0.7388878 1.0000000#方差的累积贡献率
Loadings:
   Comp.1 Comp.2 Comp.3
x1  0.718 -0.152 -0.679
x2 -0.686 -0.317 -0.655
x3 -0.116  0.936 -0.332
三个主成分的是:
Comp.1=0.718×1-0.686×2-0.116×3
Comp.2=-0.152×1-0.317×20.936×3
Comp.3=-0.679×1-0.655×2-0.332×3
若是前面几个的贡献率很高比如0.99,则可以用这几个主成分降维;
 
biplot(data.pr)

原创文章,作者:xsmile,如若转载,请注明出处:http://www.17bigdata.com/r%ef%bc%9a%e6%95%b0%e6%8d%ae%e5%88%86%e6%9e%90%e4%b9%8b%e4%b8%bb%e6%88%90%e5%88%86%e5%88%86%e6%9e%90princomp/

联系我们

在线咨询:点击这里给我发消息

邮件:23683716@qq.com

跳至工具栏