我的R程序如下:
hcluster <- function(dmatrix) {
imatrix <- NULL
hc <- hclust(dist(dmatrix), method="average")
for(h in sort(unique(hc$height))) {
hc.index <- c(h,as.vector(cutree(hc,h=h)))
imatrix <- cbind(imatrix, hc.index)
}
return(imatrix)
}
dmatrix_file = commandArgs(trailingOnly = TRUE)[1]
print(paste('Reading distance matrix from', dmatrix_file))
dmatrix <- as.matrix(read.csv(dmatrix_file,header=FALSE))
imatrix <- hcluster(dmatrix)
imatrix_file = paste("results",dmatrix_file,sep="-")
print(paste('Wrinting results to', imatrix_file))
write.table(imatrix, file=imatrix_file, sep=",", quote=FALSE, row.names=FALSE, col.names=FALSE)
print('done!')我的输入是一个距离矩阵(当然是对称的)。当我执行上面的程序时,距离矩阵大于大约数千条记录(几百条记录没有发生任何事情),它给出了错误消息:
Error in cutree(hc, h = h) :
the 'height' component of 'tree' is not sorted
(increasingly); consider applying as.hclust() first
Calls: hcluster -> as.vector -> cutree
Execution halted我的机器有大约16 be的RAM和4CPU,所以它不会是资源的问题。
有谁能告诉我出了什么问题吗?谢谢!!
发布于 2012-04-04 18:57:16
发布于 2012-12-18 04:42:08
看一下这里的cutree函数http://code.ohloh.net/file?fid=QM4q0tWQlv2VywAoSr2MfgcNjnA&cid=ki3UJjFJ8jA&s=cutree%20component%20of%20is%20not%20sorted&mp=1&ml=1&me=1&md=1&browser=Default#L1
您可以尝试为组的数量添加k定标器,这将覆盖高度参数。如果不是,你可以看看hc$height是什么,因为如果它不是数值、复数、字符或逻辑向量,is.unsorted将返回true并给你这个错误。
if(is.null(k)) {
if(is.unsorted(tree$height))
stop("the 'height' component of 'tree' is not sorted (increasingly)")
## h |--> k
## S+6 help(cutree) says k(h) = k(h+), but does k(h-) [continuity]
## h < min() should give k = n;
k <- n+1L - apply(outer(c(tree$height,Inf), h, ">"), 2, which.max)
if(getOption("verbose")) message("cutree(): k(h) = ", k, domain = NA)
}https://stackoverflow.com/questions/9457473
复制相似问题