我希望从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对象)
谢谢你的帮助
Tal
发布于 2010-06-14 14:56:16
不确定这就是你要找的,但你可以
a <- as.dendrogram(a)
branch1 <- a[[1]]
branch2 <- a[[2]]
par(mfrow=c(1,3))
plot(a)
plot(branch1)
plot(branch2)发布于 2016-11-07 20:55:05
如果您有距离矩阵,那么您可能会执行类似如下的操作:
subtree <- function(d, idx) {
hclust(dist(d[idx, idx]))
}
d <- matrix(rnorm(50 * 50), 50)
s <- subtree(d, sample(1:50, 20))
plot(s)https://stackoverflow.com/questions/3033261
复制相似问题