2010-06-13 3 views
4

hclust 개체에서 "하위 트리"를 만들고 싶습니다.거기 hclust에서 "하위 트리"를 얻을 수있는 방법은 무엇입니까? (R)

내가 그것을 어떻게

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 
을 에 액세스 할 수 :

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 

가 지금은 그것에서 추출에게 다음과 같은 하위 트리를 기원합니다 : 예를 들어

, 이제 나는 다음과 같은 객체가 있다고 가정 해 보자?

답변

6

이 확실하지 않음이 무엇입니까

탈, 어떤 도움을

감사합니다 (I는 cutree 실제 hclust 객체를 생성 나에게 서브 트리의 객체를 얻을 수 있지만, 수 없다는 것을 알고) 당신이 찾고있는,하지만 당신은 거리 행렬이있는 경우는

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

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

내가 찾고있는 것. 고마워 니코. –

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) 
관련 문제