4

hclustオブジェクトから「サブツリー」を作成したいと思います。

たとえば、次のオブジェクトがあるとします。

a <- list()  # initialize empty object
a$merge <- matrix(c(-1, -2,
                    -3, -4,
                     1,  2,
             -5,-6,
             3,4), nc=2, byrow=TRUE ) 
a$height <- c(1, 1.5, 3,4,4.5)    # define merge heights
a$order <- 1:6              # order of leaves(trivial if hand-entered)
a$labels <- 1:6# LETTERS[1:4]    # labels of leaves
class(a) <- "hclust"        # make it an hclust object
plot(a)                     # look at the result   

今、私はそれから次のサブツリーを抽出したいと思います:

a <- list()  # initialize empty object
a$merge <- matrix(c(-1, -2,
                    -3, -4,
                     1,  2
                ), nc=2, byrow=TRUE ) 
a$height <- c(1, 1.5, 3)    # define merge heights
a$order <- 1:4             # order of leaves(trivial if hand-entered)
a$labels <- 1:4# LETTERS[1:4]    # labels of leaves
class(a) <- "hclust"        # make it an hclust object
plot(a)                     # look at the result   

どうすればアクセスできますか?

(cutreeはサブツリーのオブジェクトを取得できますが、実際のhclustオブジェクトは作成できません)

助けてくれてありがとう、

タル

4

2 に答える 2

6

これがあなたが探しているものかどうかはわかりませんが、

a <- as.dendrogram(a)
branch1 <- a[[1]]
branch2 <- a[[2]]

par(mfrow=c(1,3))
plot(a)
plot(branch1)
plot(branch2)
于 2010-06-14T06:56:16.317 に答える
0

距離行列がある場合は、次のようなことを行うことができます。

subtree <- function(d, idx) {
  hclust(dist(d[idx, idx]))
}
d <- matrix(rnorm(50 * 50), 50)
s <- subtree(d, sample(1:50, 20))
plot(s)
于 2016-11-07T12:55:05.293 に答える