繁体   English   中英

FactomineR 中的 HCPC:如何计算集群中的个体?

[英]HCPC in FactomineR: How to count individuals in Clusters?

标题说明了一切。 我在 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM