我正在做一个名为pvclust
的R包的层次聚类,它通过引入bootstrapping来计算获得的聚类的显着性水平而建立在hclust
上。R中多尺度层次聚类的错误
考虑下面的数据与3个维度和10个观察组:
mat <- as.matrix(data.frame("A"=c(9000,2,238),"B"=c(10000,6,224),"C"=c(1001,3,259),
"D"=c(9580,94,51),"E"=c(9328,5,248),"F"=c(10000,100,50),
"G"=c(1020,2,240),"H"=c(1012,3,260),"I"=c(1012,3,260),
"J"=c(984,98,49)))
当我独自使用hclust
,聚类两个欧几里德措施和相关措施运行良好:
# euclidean-based distance
dist1 <- dist(t(mat),method="euclidean")
mat.cl1 <- hclust(dist1,method="average")
# correlation-based distance
dist2 <- as.dist(1 - cor(mat))
mat.cl2 <- hclust(dist2, method="average")
然而,当使用pvclust
的每个设置时,如下:
library(pvclust)
# euclidean-based distance
mat.pcl1 <- pvclust(mat, method.hclust="average", method.dist="euclidean", nboot=1000)
# correlation-based distance
mat.pcl2 <- pvclust(mat, method.hclust="average", method.dist="correlation", nboot=1000)
...我收到以下错误:
- 欧几里得:
Error in hclust(distance, method = method.hclust) : must have n >= 2 objects to cluster
- 相关:
Error in cor(x, method = "pearson", use = use.cor) : supply both 'x' and 'y' or a matrix-like 'x'
。
请注意,距离的计算方法是pvclust
,因此不需要预先计算距离。还请注意,hclust
方法(平均值,中位数等)不会影响问题。
当我将数据集的维度增加到4时,pvclust
现在可以正常运行。为什么我在3维和以下版本中获得pvclust
的这些错误,但不是hclust
?此外,当我使用4维以上的数据集时,为什么这些错误会消失?
这很棒。改变'r'就能做到这一点。谢谢。 – oisyutat