楼主: ReneeBK
1667 4

[博文精选]Computing and visualizing PCA in R [推广有奖]

  • 1关注
  • 62粉丝

VIP

已卖:4897份资源

学术权威

14%

还不是VIP/贵宾

-

TA的文库  其他...

R资源总汇

Panel Data Analysis

Experimental Design

威望
1
论坛币
49635 个
通用积分
55.6937
学术水平
370 点
热心指数
273 点
信用等级
335 点
经验
57805 点
帖子
4005
精华
21
在线时间
582 小时
注册时间
2005-5-8
最后登录
2023-11-26

楼主
ReneeBK 发表于 2016-1-24 02:16:55 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
Following my introduction to PCA, I will demonstrate how to apply and visualize PCA in R. There are many packages and functions that can apply PCA in R. In this post I will use the function prcomp from the stats package. I will also show how to visualize PCA in R using Base R graphics. However, my favorite visualization function for PCA is ggbiplot, which is implemented byVince Q. Vu and available on github. Please, let me know if you have better ways to visualize PCA in R.

本帖隐藏的内容

Computing and Visualizing PCA in R.pdf (444.05 KB)

  1. # Load data
  2. data(iris)
  3. head(iris, 3)
复制代码
  1. # log transform
  2. log.ir <- log(iris[, 1:4])
  3. ir.species <- iris[, 5]

  4. # apply PCA - scale. = TRUE is highly
  5. # advisable, but default is FALSE.
  6. ir.pca <- prcomp(log.ir,
  7.                  center = TRUE,
  8.                  scale. = TRUE)
复制代码
  1. # print method
  2. print(ir.pca)
复制代码
  1. # summary method
  2. summary(ir.pca)
复制代码
  1. # Predict PCs
  2. predict(ir.pca,
  3.         newdata=tail(log.ir, 2))
复制代码
  1. library(devtools)
  2. install_github("ggbiplot", "vqv")

  3. library(ggbiplot)
  4. g <- ggbiplot(ir.pca, obs.scale = 1, var.scale = 1,
  5.               groups = ir.species, ellipse = TRUE,
  6.               circle = TRUE)
  7. g <- g + scale_color_discrete(name = '')
  8. g <- g + theme(legend.direction = 'horizontal',
  9.                legend.position = 'top')
  10. print(g)
复制代码
  1. require(caret)
  2. trans = preProcess(iris[,1:4],
  3.                    method=c("BoxCox", "center",
  4.                             "scale", "pca"))
  5. PC = predict(trans, iris[,1:4])
  6. # Retained PCs
  7. head(PC, 3)
复制代码


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Visualizing computing Comput Visual comp available function package better

本帖被以下文库推荐

沙发
0jzhang 发表于 2016-1-24 07:37:41
Computing and visualizing PCA in R

藤椅
fengyg 企业认证  发表于 2016-1-24 08:35:07
kankan

板凳
lionli 发表于 2016-1-24 19:45:48
thanks for sharing

报纸
tamtam701013 发表于 2016-4-21 03:11:26
thanks for your sharing.

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-31 02:07