1

我正在尝试进行一些分组并遇到此错误。

Evaluation error: the 'height' component of 'tree' is not sorted (increasingly).

我的输入是:

library(stringdist)
name <- c("luke,abcdef","luke,abcdeh","luke,abcdeg")
a<-stringdistmatrix(name, method="jw")
clusts <- hclust(a, method="ward.D2")

但是当我尝试剪切它时,它给了我一个错误:

> cutree(clusts, h = 0.155)
Error in cutree(clusts, h = 0.155) : 
  the 'height' component of 'tree' is not sorted (increasingly)

但是如果我使用

a<-stringdistmatrix(name, method="jw", p=0.05)

一切正常。

我一直在寻找解决方案,但找不到。我应该怎么做,以防止这种情况发生并保持工作?

我还注意到,如果我有相同的距离矩阵,但是是手动生成的(所以集群中没有距离参数。

4

1 回答 1

3

如果你比较diff(clusts$height)这两个例子,第一个是一个很小的负数,第二个正好是零。所以问题是由应该相等的值的二进制表示舍入差异引起的。

如果您在计算后将高度四舍五入,它应该可以工作clusts......

clusts$height <- round(clusts$height, 6) 
于 2017-10-15T06:25:04.563 回答