r - FactomineR 中的 HCPC:如何计算集群中的个体?
问题描述
标题说明了一切。我在 FactomineR 中使用 factoshiny 进行了多重对应分析 (MCA),然后进行了 HPCP。我现在在我的 2 个维度上有 3 个集群。虽然 factoshiny 界面确实有助于轻松可视化和导航分析,但我无法找到一种方法来计算集群中的个体。此外,我很想将集群变量分配给我的数据集上的个人。使用 hclust 可以轻松执行这些操作,但它们的算法不适用于分类数据。
##dummy dataset
x <- as.factor(c(1,1,2,1,3,4,3,2,1))
y <- as.factor(c(2,3,1,4,4,2,1,1,1))
z <- as.factor(c(1,2,1,1,3,4,2,1,1))
data <- data.frame(x,y,z)
# used packages
library(FactoMineR)
library(Factoshiny)
# the function used to open factoshiny in your browser
res.MCA <- Factoshiny(data)
# factoshiny code:
# res.MCA<-MCA(data,graph=FALSE)
# hcpc code in factoshiny
res.MCA<-MCA(data,ncp=8,graph=FALSE)
res.HCPC<-HCPC(res.MCA,nb.clust=3,consol=FALSE,graph=FALSE)
plot.HCPC(res.HCPC,choice='tree',title='Hierarchical tree')
plot.HCPC(res.HCPC,choice='map',draw.tree=FALSE,title='Factor map')
plot.HCPC(res.HCPC,choice='3D.map',ind.names=FALSE,centers.plot=FALSE,angle=60,title='Hierarchical tree on the factor map')
我现在想要一个具有 3 个级别的变量 data$cluster,以便我可以计算集群中的个人。
解决方案
对于遇到类似问题的任何人,这都有帮助:
res.HCPC$data.clust # returns all values and cluster membership for every individual
res.HCPC$data.clust[1,]$clust # for the first individual
table(res.HCPC$data.clust$clust) # gives table of frequencies per cluster
推荐阅读
- python - ProcessPoolExecutor 工作人员具有相同的“线程 ID”?
- k-means - 如何为 kmeans 聚类在某些点设置初始质心?
- xml - xsd 验证失败 - 引用本地 xsd 文件
- powershell - 使用相同代码的 Powershell 5.1 和 Powershell 7 证书加密之间的区别
- typescript - TypeScript中基于字符串的类型条件参数
- ruby-on-rails - 有人可以提供一个带有多个图像的神社/铁轨示例吗?
- python - 为什么会打印出这么多回复?
- c# - C#在自动驾驶仪上将httpclient post转换为restsharp post而没有异步方法
- google-sheets - 带有列选择的查询 + 导入范围以显示匹配未显示的条件
- visual-studio-code - 有没有办法通过智能感知在 vs 代码中获取悬停时提供的文本?