6

私の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

私のマシンには約16GBのRAMと4CPUがあるので、リソースの問題にはなりません。

誰かが私に何が問題なのか教えてもらえますか?ありがとう!!

4

2 に答える 2

6

私はRウィザードではありませんが、まさにこの問題に遭遇しました。

考えられる答えはここに記述されています:

https://stat.ethz.ch/pipermail/r-help/2008-May/163409.html

于 2012-04-04T10:57:15.763 に答える
1

ここでcutree関数を 見る

グループ数の k スケーラーを追加してみてください。これにより、高さの引数が上書きされます。そうでない場合は、 hc$height が数値、複素数、文字、または論理ベクトルでない場合、 is.unsorted が true を返し、このエラーが発生するため、 hc$height を確認できます。

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)
}
于 2012-12-17T20:42:07.713 に答える