[英]How to print the order of hierarchical clustering in R?
使用以下6个意大利城市之间的距离矩阵:
0 662 877 255 412 996
662 0 295 468 268 400
877 295 0 754 564 138
255 468 754 0 219 869
412 268 564 219 0 669
996 400 138 869 669 0
R将输出它聚类的顺序:例如,单链接会告诉您:
City 3 and City 6, followed by
City 4 and City 5, followed by
City 1 to City 4 and City 5, finally City 2 to City 3 and City 6.
重要的是我得到一个数字输出而不是从树形图中读取它。
我不知道你的问题的完整解决方案,但也许你可以使用hclust
返回的merge
值。
来自?hclust
:
合并:一个n-1乘2矩阵。 'merge'的第i行描述了在聚类的步骤i中聚类的合并。 如果行中的元素j为负,则在此阶段合并观察-j。 如果j为正,则合并与在算法的(较早的)阶段j处形成的聚类一起。 因此,“合并”中的否定条目表示单体的聚集,而正条目表示非单体的聚集。
你的例子:
d <- as.dist(read.table(textConnection("
0 662 877 255 412 996
662 0 295 468 268 400
877 295 0 754 564 138
255 468 754 0 219 869
412 268 564 219 0 669
996 400 138 869 669 0")))
hc <- hclust(d, method="single")
plot(hc)
hc$merge
# [,1] [,2] # from bottom up
#[1,] -3 -6 # City 3 and 6
#[2,] -4 -5 # City 4 and 5
#[3,] -1 2 # join City 1 and City 4/5
#[4,] -2 3 # join City 2 and City 1/4/5
#[5,] 1 4 # join City 3/6 and City 1/2/4/5
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.