r - R中的双聚类

标签 r cluster-analysis binary-matrix

我想在 R 中的二进制矩阵上应用 byclustering。有一个名为“biclust”的不错的包可用,但它确实并没有显示我想要的所有内容。

我有一个二进制矩阵,如下所示:

1 0 0 1 0 1 0
0 0 0 0 0 0 0
0 0 1 0 1 0 0
1 0 0 1 0 1 0
0 0 1 0 1 0 0
1 0 0 1 0 1 0
0 0 0 0 0 0 0

我的目标是按如下方式进行双聚类(并显示)(可能是彩色的):
1 1 1 0 0 0 0
1 1 1 0 0 0 0
1 1 1 0 0 0 0
0 0 0 1 1 0 0
0 0 0 1 1 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0

设置代码:
# install.packages("biclust") (if necessary)
library("biclust")

testMatrix <- matrix(c(1,0,0,1,0,1,0,
                       0,0,0,0,0,0,0,
                       0,0,1,0,1,0,0,
                       1,0,0,1,0,1,0,
                       0,0,1,0,1,0,0,
                       1,0,0,1,0,1,0,
                       0,0,0,0,0,0,0),
                     nrow = 7,
                     ncol = 7,
                     byrow = TRUE)

我应用了“biclust”R包的biclust函数:
testCluster <- biclust(x = testMatrix, method=BCBimax())

事实上,我得到了预期的两个集群:
An object of class Biclust 
call:
biclust(x = testMatrix, method = BCBimax())
Number of Clusters found:  2 
First  2  Cluster sizes:
                      BC 1  BC 2
Number of Rows:       3     2
Number of Columns:    3     2

我可以通过以下方式分别显示集群:
drawHeatmap(x = testMatrix, bicResult = testCluster, number = 1) # shown in picture below
drawHeatmap(x = testMatrix, bicResult = testCluster, number = 2)

Picture

我可以通过以下方式显示整个集群矩阵(左上角的一个集群):
drawHeatmap2(x = testMatrix, bicResult = testCluster, number = 1) # shown in picture below
drawHeatmap2(x = testMatrix, bicResult = testCluster, number = 2)

Picture

到目前为止一切顺利,但我想要:
  • 显示颜色切换。现在 1 是红色,0 是绿色。
  • 我想查看原始矩阵的行和列。现在只显示了特定集群的行号和列号(使用 drawHeatMap),并且在整个集群矩阵(drawHeatMap2)上没有显示行号和列号。
  • 我想要一个有序的聚集矩阵。现在只有 drawHeatmap2 中指定的簇显示在左上角,但对于矩阵的其余部分,我还希望其他簇从左上角到右下角排列整齐。

  • 这些更改是否可能(使用“biclust”包)?还是用 R 以另一种方式做更好?

    最佳答案

    更改 biclust 源包中的 drawHeatmap() 函数:

  • 跟踪(“绘制热图”,编辑=真)
  • 更改以下内容:
    (a) 切换红色和绿色 - 在调用 rgb() 中切换 rvect 和 gvect
    (b) 原始行名而不是​​新行 - 将 'labels=' 更改为 '=bicCols' 和 '=bicRows'。
  • 打印 rownumbers: before axis about rows: cat(bicRows)。
  • 将行号保存到文件 - 在关于行的轴之前: write(bicRows, file="FILENAME.txt")
  • 关于r - R中的双聚类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38497520/

    相关文章:

    r - 层次聚类 : Determine optimal number of cluster and statistically describe Clusters

    algorithm - 二进制 n x m 矩阵的模 c 数,每列最多 k 个连续的 1

    r - 对于每一行,将特定列(由另一个数据框定义)中的值替换为向量中的值

    java - RNetLogo 类错误

    r - 试图确定为什么我的热图使用 heatmap.2 并在 R 中使用中断是不对称的

    algorithm - 在数学上如何将分类结果与聚类结果进行比较

    c++ - 使用 HUGE 二进制矩阵的最有效方法?

    r - to.minutes 使用自定义端点

    r - 使用 dcast.data.table 仅针对列值的子集从长转换为宽