将 HCPC 对象强制为 hclust 以使用库(猿)

Coerce HCPC object to hclust to use library(ape)

我目前正在执行分层集群。我选择使用 FactoMineR 是因为它有很好的数据探索管道:data->MFA->HCPC。

data("wine")
names(wine)
res<-MFA(wine,group = c(2,5,3,10,9,2),type=c("n",rep("s",5)),
         ncp=5,name.group = c("orig","olf","vis","olfag","gust","ens"),
         num.group.sup = c(1,6))

res.hcpc<-HCPC(res, nb.clust=0, consol=F, iter.max=10, min=3, 
           max=NULL, metric="euclidean", method="ward", order=TRUE,
           graph.scale="sqrt-inertia", nb.par=5, graph=TRUE, proba=0.05, 
           cluster.CA="rows",kk=Inf)

#Now for some nice plots
plot(res.hcpc,draw.tree = T,choice = "tree")
plot(res.hcpc,draw.tree = T,choice = "bar")

当想要提取答案时,这些已经绰绰有余,但我希望展示这些树。即我希望通过 library(ape) - examples

对它们进行一些修饰

问题是这些函数需要一个 hclust 对象。我的一个选择是使用 MFA 结果并使用 hclust 函数作为: res.hc<-hclust(dist(res$global.pca$ind$coord),method = "ward.D2") 构建一个 hclust 对象。

这确实有效,但我发现 HCPC 提供的信息更丰富(答案与 hclust 不同)。因此我想使用 HCPC 对象而不是 hclust,但仍然能够使用 library(ape) 中的函数。 知道如何将 HCPC 强制为 hclust 吗?

图书馆(猿)

hcpcTree<-res.hcpc$call$t$tree
apeTree<-as.phylo(hcpcTree)

图书馆(统计)

dendextendTree<-as.phylo.dendrogram(hcpcTree)