2010-06-13 51 views
4

我希望从hclust对象创建一个“子树”。有没有办法从hclust中获得“子树”? (R)

例如,假设我有以下对象:

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对象)的任何帮助

感谢,

塔尔

回答

6

不知道这是什么你要找的,但你可以

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

par(mfrow=c(1,3)) 
plot(a) 
plot(branch1) 
plot(branch2) 
+0

正是我在找的东西。谢谢尼科。 – 2010-06-14 10:53:28

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) 
相关问题