R语言主成分分析——prcomp VS princomp

最简单的主成分分析函数,prcomp 和 princomp 都是自带的函数,不需要额外的包

http://strata.uga.edu/software/pdf/pcaTutorial.pdf很好的一个介绍

http://gastonsanchez.wordpress.com/2012/06/17/principal-components-analysis-in-r-part-1/很好的一个介绍

主成分分析的结果包含特征根集,PC scores表,(变量和PC)相关系数表(table of loadings)

特征根包含了数据变化度的信息,scores提供了观测结构的信息,相关系数表提供了变量之间,以及和PC之间的关系的大致感官概念


描述:

prcomp : Performs a principalcomponents analysis on the givendata matrix and returns the results as anobject of class prcomp.

princomp : Performs a principal components analysison the givennumeric data matrix and returns the results as an object of class princomp.

使用:

以下使用内置数据集USArrests

> str(USArrests)
'data.frame': 50 obs. of  4 variables:
 $ Murder  : num  13.2 10 8.1 8.8 9 7.9 3.3 5.9 15.4 17.4 ...
 $ Assault : int  NA 263 294 190 276 204 110 238 335 211 ...
 $ UrbanPop: int  58 48 80 50 91 78 77 72 80 60 ...
 $ Rape    : num  21.2 44.5 31 19.5 40.6 38.7 11.1 15.8 31.9 25.8 ...

prcomp :

prcomp(x, ...)

prcomp(formula, data = NULL, subset, na.action, ...)

prcomp(x, retx = TRUE, center = TRUE, scale. = FALSE,  tol = NULL, ...)

prcomp(USArrests)  #inappropriate,没有scale不太合适

prcomp(USArrests, scale = TRUE) #直接数据矩阵

prcomp(~ Murder + Assault + Rape, data = USArrests, scale = TRUE) #直接方程

plot(prcomp(USArrests))

  • 4
    点赞
  • 48
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值