【问题标题】:How to print the order of hierarchical clustering in R?如何在R中打印层次聚类的顺序?
【发布时间】:2013-08-15 10:17:26
【问题描述】:

使用以下 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.

重要的是我得到一个数字输出而不是从树状图中读取它。

【问题讨论】:

    标签: r dendrogram hclust


    【解决方案1】:

    我不知道您的问题的完整解决方案,但也许您可以使用 hclust 返回的 merge 值。

    来自?hclust

    合并:一个 n-1 x 2 矩阵。 “合并”的第 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
    

    【讨论】:

    • 谢谢。我需要它,以便我可以决定同时对哪些集群进行分组。我知道 cutree 会告诉你每个集群中有哪些元素,但是,如果几个集群在同一高度加入,它会“随机”拆分这个集群。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-12
    • 2021-03-10
    • 2017-12-31
    • 1970-01-01
    • 2021-02-04
    • 1970-01-01
    相关资源
    最近更新 更多