首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >有没有办法从hclust中获取“子树”?(R)

有没有办法从hclust中获取“子树”?(R)
EN

Stack Overflow用户
提问于 2010-06-14 01:47:40
回答 2查看 2.6K关注 0票数 4

我希望从hclust对象创建一个“子树”。

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

代码语言:javascript
复制
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   

现在我希望它的摘录是下面的子树:

代码语言:javascript
复制
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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-06-14 14:56:16

不确定这就是你要找的,但你可以

代码语言:javascript
复制
a <- as.dendrogram(a)
branch1 <- a[[1]]
branch2 <- a[[2]]

par(mfrow=c(1,3))
plot(a)
plot(branch1)
plot(branch2)
票数 6
EN

Stack Overflow用户

发布于 2016-11-07 20:55:05

如果您有距离矩阵,那么您可能会执行类似如下的操作:

代码语言:javascript
复制
subtree <- function(d, idx) {
  hclust(dist(d[idx, idx]))
}
d <- matrix(rnorm(50 * 50), 50)
s <- subtree(d, sample(1:50, 20))
plot(s)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3033261

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档