5

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())

実際、期待される2つのクラスターを取得します。

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)

写真

クラスター化されたマトリックス全体 (左上隅にある 1 つのクラスター) を次のように表示できます。

drawHeatmap2(x = testMatrix, bicResult = testCluster, number = 1) # shown in picture below
drawHeatmap2(x = testMatrix, bicResult = testCluster, number = 2)

写真

ここまでは良いですが、私が欲しいのは:

  1. ディスプレイの色が切り替わりました。1 が赤、0 が緑になりました。
  2. 元の行列の行と列を見たいです。現在、特定のクラスターの行番号と列番号のみが表示され (drawHeatMap を使用)、クラスター化されたマトリックス全体 (drawHeatMap2) の行番号と列番号は表示されていません。
  3. 整然としたクラスター化されたマトリックスが必要です。これで、drawHeatmap2 で指定されたクラスターのみが左上隅に表示されますが、マトリックスの残りの部分については、残りのマトリックスの左上隅から右下隅まで他のクラスターも適切に並べたいと思います。

これらの変更は可能ですか (「biclust」パッケージを使用)? それとも、Rで別の方法で行う方が良いですか?

4

1 に答える 1

3

biclust ソース パッケージ パッケージの drawHeatmap() 関数を変更します。

  1. trace("drawHeatmap", edit = TRUE)
  2. 以下を変更します:
    (a) 赤と緑を切り替えます - rgb() 呼び出しで rvect と gvect を切り替えます
    (b) new ではなく元の行名 - 「labels=」を「=bicCols」と「=bicRows」に変更します。
  3. 行番号: 行の軸の前に出力: cat(bicRows)。
  4. 行番号をファイルに保存 - 行に関する軸の前: write(bicRows, file="FILENAME.txt")
于 2018-01-09T09:43:30.153 に答える