从 hclust(层次聚类)对象中提取距离

Extract distances from hclust (hierarchical clustering) object

我想计算一下我的聚类分析解决方案对实际距离分数的拟合程度。为此,我需要提取要聚类的刺激之间的距离。我知道在查看 dendrogram 时我可以提取距离,例如 5 和 -14 之间的距离是 .219(它们连接处的高度),但是是否有一种自动提取距离的方法hclust 对象中的信息?

List of 7
 $ merge      : int [1:14, 1:2] -5 -1 -6 -4 -10 -2 1 -9 -12 -3 ...
 $ height     : num [1:14] 0.219 0.228 0.245 0.266 0.31 ...
 $ order      : int [1:15] 3 11 5 14 4 1 8 12 10 15 ...
 $ labels     : chr [1:15] "1" "2" "3" "4" ...
 $ method     : chr "ward.D"
 $ call       : language hclust(d = as.dist(full_naive_eucAll, diag = F, upper = F), method = "ward.D")
 $ dist.method: NULL
 - attr(*, "class")= chr "hclust"

是的。 你问的是共生距离。

d_USArrests <- dist(USArrests)
hc <- hclust(d_USArrests, "ave")
par(mfrow = c(1,2))
plot(hc)
plot(cophenetic(hc) ~ d_USArrests)
cor(cophenetic(hc), d_USArrests)

同样的方法也可以用于比较两种层次聚类方法,并在dendextend R package中实现(该函数确保两个距离矩阵有序匹配)。例如:

# install.packages('dendextend')
library("dendextend")

d_USArrests <- dist(USArrests)
hc1 <- hclust(d_USArrests, "ave")
hc2 <- hclust(d_USArrests, "single")
cor_cophenetic(hc1, hc2)
#  0.587977