前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >主成分分析 factoextra

主成分分析 factoextra

作者头像
用户1359560
发布2018-08-27 11:27:05
1.8K0
发布2018-08-27 11:27:05
举报
文章被收录于专栏:生信小驿站

factoextra是一个R软件包,可以轻松提取和可视化探索性多变量数据分析的输出,其中包括: 主成分分析(PCA),用于通过在不丢失重要信息的情况下减少数据的维度来总结连续(即定量)多变量数据中包含的信息。 对应分析(CA),它是适用于分析由两个定性变量(或分类数据)形成的大型列联表的主成分分析的扩展。 多重对应分析(MCA),它是将CA改编为包含两个以上分类变量的数据表格。 多因素分析(MFA)专用于数据集,其中变量按组(定性和/或定量变量)组织。 分层多因素分析(HMFA):在数据组织为分层结构的情况下,MFA的扩展。 混合数据因子分析(FAMD)是MFA的一个特例,致力于分析包含定量和定性变量的数据集。 有许多R包实现主要组件方法。这些软件包包括:FactoMineR,ade4,stats,ca,MASS和ExPosition。

  • 为什么使用

  • R package factoextra具有灵活且易于使用的方法,可以用人类可读的标准数据格式快速提取上述不同软件包的分析结果。
  • 它以较少的输入产生了基于ggplot2的优雅数据可视化。
  • 它还包含许多便于聚类分析和可视化的功能。
  • factoextra R软件包可以处理来自多个软件包的PCA,CA,MCA,MFA,FAMD和HMFA的结果,用于提取和可视化数据中包含的最重要信息。
  • 在PCA,CA,MCA,MFA,FAMD和HMFA之后,可以使用以下高亮显示最重要的行/列元素: 它们的cos2值对应于它们在因子图上的表示质量 他们对主要维度定义的贡献。 如果你想这样做,factoextra包提供了一个方便的解决方案。

  • 如果您想使用PCA / MCA进行预测并使用ggplot2可视化补充变量/个体在因子图上的位置:那么factoextra可以为您提供帮助。
代码语言:javascript
复制
library("factoextra")
data("decathlon2")
df <- decathlon2[1:23, 1:10]
library("FactoMineR")
res.pca <- PCA(df,  graph = T)
get_eig(res.pca)
fviz_screeplot(res.pca, addlabels = TRUE, ylim = c(0, 50))
代码语言:javascript
复制
# Extract the results for variables
var <- get_pca_var(res.pca)
var
#> Principal Component Analysis Results for variables
#>  ===================================================
#>   Name       Description                                    
#> 1 "$coord"   "Coordinates for the variables"                
#> 2 "$cor"     "Correlations between variables and dimensions"
#> 3 "$cos2"    "Cos2 for the variables"                       
#> 4 "$contrib" "contributions of the variables"
# Coordinates of variables
head(var$coord)
#>                   Dim.1       Dim.2      Dim.3       Dim.4      Dim.5
#> X100m        -0.8506257 -0.17939806  0.3015564  0.03357320 -0.1944440
#> Long.jump     0.7941806  0.28085695 -0.1905465 -0.11538956  0.2331567
#> Shot.put      0.7339127  0.08540412  0.5175978  0.12846837 -0.2488129
#> High.jump     0.6100840 -0.46521415  0.3300852  0.14455012  0.4027002
#> X400m        -0.7016034  0.29017826  0.2835329  0.43082552  0.1039085
#> X110m.hurdle -0.7641252 -0.02474081  0.4488873 -0.01689589  0.2242200
# Contribution of variables
head(var$contrib)
#>                  Dim.1      Dim.2     Dim.3       Dim.4     Dim.5
#> X100m        17.544293  1.7505098  7.338659  0.13755240  5.389252
#> Long.jump    15.293168  4.2904162  2.930094  1.62485936  7.748815
#> Shot.put     13.060137  0.3967224 21.620432  2.01407269  8.824401
#> High.jump     9.024811 11.7715838  8.792888  2.54987951 23.115504
#> X400m        11.935544  4.5799296  6.487636 22.65090599  1.539012
#> X110m.hurdle 14.157544  0.0332933 16.261261  0.03483735  7.166193
# Graph of variables: default plot
fviz_pca_var(res.pca, col.var = "black")
  • 可以使用它们对主轴的贡献(“contrib”)来控制变量颜色:
代码语言:javascript
复制
# Control variable colors using their contributions
fviz_pca_var(res.pca, col.var="contrib",
             gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),
             repel = TRUE # Avoid text overlapping
             )
  • 对主轴的可变贡献:
代码语言:javascript
复制
# Extract the results for individuals
ind <- get_pca_ind(res.pca)
ind
#> Principal Component Analysis Results for individuals
#>  ===================================================
#>   Name       Description                       
#> 1 "$coord"   "Coordinates for the individuals" 
#> 2 "$cos2"    "Cos2 for the individuals"        
#> 3 "$contrib" "contributions of the individuals"
# Coordinates of individuals
head(ind$coord)
#>                Dim.1      Dim.2      Dim.3       Dim.4       Dim.5
#> SEBRLE     0.1955047  1.5890567  0.6424912  0.08389652  1.16829387
#> CLAY       0.8078795  2.4748137 -1.3873827  1.29838232 -0.82498206
#> BERNARD   -1.3591340  1.6480950  0.2005584 -1.96409420  0.08419345
#> YURKOV    -0.8889532 -0.4426067  2.5295843  0.71290837  0.40782264
#> ZSIVOCZKY -0.1081216 -2.0688377 -1.3342591 -0.10152796 -0.20145217
#> McMULLEN   0.1212195 -1.0139102 -0.8625170  1.34164291  1.62151286
# Graph of individuals
# 1\. Use repel = TRUE to avoid overplotting
# 2\. Control automatically the color of individuals using the cos2
    # cos2 = the quality of the individuals on the factor map
    # Use points only
# 3\. Use gradient color
fviz_pca_ind(res.pca, col.ind = "cos2", 
             gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),
             repel = TRUE # Avoid text overlapping (slow if many points)
             )

[图片上传失败...(image-6a6139-1529602238838)]

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018.06.22 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档