4

reorder.dendrogramを使用して樹状図を並べ替えたいのですが、パラメーターの設定方法について頭を曲げることができません。

樹状図には「外れ値」の分岐が1つあり、これを反対側に移動します。

このカット/マージ呼び出しでそれを行うことができますが、確かに再注文で可能ですか?

樹状図は次のとおりです。

tdro <- structure(list(structure(9L, members = 1L, height = 0, label = "leaf1", leaf = TRUE, class = "dendrogram"), 
structure(list(structure(list(structure(list(structure(list(
    structure(15L, label = "leaf2", members = 1L, height = 0, leaf = TRUE, class = "dendrogram"), 
    structure(14L, label = "leaf3", members = 1L, height = 0, leaf = TRUE, class = "dendrogram")), members = 2L, midpoint = 0.5, height = 24.8381484584436, class = "dendrogram"), 
    structure(list(structure(13L, label = "leaf4", members = 1L, height = 0, leaf = TRUE, class = "dendrogram"), 
        structure(12L, label = "leaf5", members = 1L, height = 0, leaf = TRUE, class = "dendrogram")), members = 2L, midpoint = 0.5, height = 24.3975287023022, class = "dendrogram")), members = 4L, midpoint = 1.5, height = 33.1101361501252, class = "dendrogram"), 
    structure(list(structure(10L, members = 1L, height = 0, label = "leaf6", leaf = TRUE, class = "dendrogram"), 
        structure(list(structure(11L, label = "leaf7", members = 1L, height = 0, leaf = TRUE, class = "dendrogram"), 
            structure(8L, label = "leaf8", members = 1L, height = 0, leaf = TRUE, class = "dendrogram")), members = 2L, midpoint = 0.5, height = 30.9363490461899, class = "dendrogram")), members = 3L, midpoint = 0.75, height = 32.3912839969328, class = "dendrogram")), members = 7L, midpoint = 3.125, height = 36.9011152635297, class = "dendrogram"), 
    structure(list(structure(5L, members = 1L, height = 0, label = "leaf9", leaf = TRUE, class = "dendrogram"), 
        structure(list(structure(list(structure(4L, members = 1L, height = 0, label = "leaf10", leaf = TRUE, class = "dendrogram"), 
            structure(list(structure(2L, label = "leaf11", members = 1L, height = 0, leaf = TRUE, class = "dendrogram"), 
              structure(6L, label = "leaf12", members = 1L, height = 0, leaf = TRUE, class = "dendrogram")), members = 2L, midpoint = 0.5, height = 20.537001267289, class = "dendrogram")), members = 3L, midpoint = 0.75, height = 27.9153607968991, class = "dendrogram"), 
            structure(list(structure(list(structure(7L, label = "leaf13", members = 1L, height = 0, leaf = TRUE, class = "dendrogram"), 
              structure(3L, label = "leaf14", members = 1L, height = 0, leaf = TRUE, class = "dendrogram")), members = 2L, midpoint = 0.5, height = 19.3278637150999, class = "dendrogram"), 
              structure(1L, members = 1L, height = 0, label = "leaf15", leaf = TRUE, class = "dendrogram")), members = 3L, midpoint = 1.25, height = 27.6624008548179, class = "dendrogram")), members = 6L, midpoint = 2.5, height = 30.8706298846279, class = "dendrogram")), members = 7L, midpoint = 1.75, height = 41.426993488228, class = "dendrogram")), members = 14L, midpoint = 5.9375, height = 41.7600747862578, class = "dendrogram")), members = 15L, midpoint = 3.46875, height = 66.2893195420674, class = "dendrogram")
plot(tdro)

これが私が求めているものです:

ddr_cut <- cut(tdro, 50)
want_tdro <- merge(ddr_cut$lower[[2]],
                   ddr_cut$lower[[1]],
                   height=attr(ddr_cut$upper, "height"))
plot(want_tdro)

問題は、次の呼び出しがどのように見えるかです。

plot(reorder(tdro, c(15,1:14)))

なるようにwant_tdro?そして、なぜですか?

4

1 に答える 1

5

関数に提供する重みはreorder.dendrogram()、樹状図の作成に元のデータが使用されたのと同じ順序である必要があります。"leaf1"これは、( 〜に)ラベルを付けた葉と必ずしも同じ順序ではありません"leaf15"。最も単純な重み、、を使用し、1:15各リーフに割り当てられた値を確認することで、基になる順序を確認できます。

tdro2 <- reorder(tdro, 1:15, mean)
str(tdro2)

関数からの出力を見るとstr()、報告された値は、割り当てた単純な重みに対応しています。このことから、データの基本的な順序は、leaf15、leaf11、leaf14、leaf10、leaf9、leaf12、leaf13、leaf8、leaf1、leaf6、leaf7、leaf5、leaf4、leaf3、leaf2であると推測されます。

葉の順序をleaf2-leaf15、leaf1にする必要があるため、leaf2に重み1、leaf3に重み2、...、leaf15に重み14、leaf1に重み15を指定する必要がありますが、これらの重みを指定する必要があります。このように、葉の基本的な順序で:

tdro3 <- reorder(tdro, c(14, 10, 13, 9:8, 11:12, 7, 15, 5:6, 4:1), mean)
plot(tdro3)
于 2013-05-07T13:06:19.350 に答える