给定距离矩阵256x256的聚类

Vah*_*ili 3 r cluster-analysis hierarchical-clustering matrix hclust

所以,我有256个物体,并计算了它们之间的距离矩阵(成对距离).我的距离矩阵的子集如下:

> dm[1:10, 1:10]
      V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
 [1,]  0  1  1  1  1  2  2  2  1   2
 [2,]  1  0  1  1  2  1  2  2  2   1
 [3,]  1  1  0  1  2  2  1  2  2   2
 [4,]  1  1  1  0  2  2  2  1  2   2
 [5,]  1  2  2  2  0  1  1  1  1   2
 [6,]  2  1  2  2  1  0  1  1  2   1
 [7,]  2  2  1  2  1  1  0  1  2   2
 [8,]  2  2  2  1  1  1  1  0  2   2
 [9,]  1  2  2  2  1  2  2  2  0   1
[10,]  2  1  2  2  2  1  2  2  1   0

> str(dm)
 int [1:256, 1:256] 0 1 1 1 1 2 2 2 1 2 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:256] "V1" "V2" "V3" "V4" ...
Run Code Online (Sandbox Code Playgroud)

现在,我想使用此距离矩阵相应地聚类这256个对象.因此,我使用了hclust,但出现了错误:

> hclust(dm, method="single")
Error in if (is.na(n) || n > 65536L) stop("size cannot be NA nor exceed 65536") : 
  missing value where TRUE/FALSE needed


> hclust(dm, method="complete")
Error in if (is.na(n) || n > 65536L) stop("size cannot be NA nor exceed 65536") : 
  missing value where TRUE/FALSE needed
Run Code Online (Sandbox Code Playgroud)

所以,即使我使用矩阵的较小子集,我仍然会得到相同的错误:

> hclust(dm[1:10,1:10], method="complete")
Error in if (is.na(n) || n > 65536L) stop("size cannot be NA nor exceed 65536") : 
  missing value where TRUE/FALSE needed
Run Code Online (Sandbox Code Playgroud)

知道我的分析有什么问题吗?

And*_*lva 5

dm需要成为"dist"类的对象hclust.

因此,您可以使用dist函数计算不相似度矩阵,然后使用内部对象hclust.

m_trix = matrix(data=1:2,nrow=10,ncol=10)

dm = dist(m_trix,method="euclidean")
cluster = hclust(dm, method="single")
plot(cluster)
Run Code Online (Sandbox Code Playgroud)

或者你可以dist(m_trix)直接在里面使用hclust:

cluster = hclust(dist(m_trix), method="single")
plot(cluster)
Run Code Online (Sandbox Code Playgroud)