4

階層クラスタリングを実行してヒートマップにプロットする次のコードがあります。

library(gplots)
set.seed(538)
# generate data
y <- matrix(rnorm(50), 10, 5, dimnames=list(paste("g", 1:10, sep=""), paste("t", 1:5, sep="")))
# the actual data is much larger that the above

# perform hiearchical clustering and plot heatmap
test <- heatmap.2(y)

これをプロットする: ここに画像の説明を入力

私がやりたいことは、プロットの各階層からクラスター メンバーを取得することです。

Clust 1: g3-g2-g4
Clust 2: g2-g4
Clust 3: g4-g7
etc
Cluster last: g1-g2-g3-g4-g5-g6-g7-g8-g9-g10

それを行う方法はありますか?

4

2 に答える 2

1

このソリューションでは、別のパッケージを使用してクラスター構造を計算する必要があります。

# Generate data
y = matrix(rnorm(50), 10, 5, dimnames=list(paste("g", 1:10, sep=""), paste("t", 1:5, sep="")))
# The new packags:
library(nnclust)
# Create the links between all pairs of points with 
#   squared euclidean distance less than threshold
links = nncluster(y, threshold = 2, fill = 1, give.up =1) 
# Assign a cluster number to each point
clusters=clusterMember(links, outlier = FALSE)
# Display the points that are "alone" in their own cluster:
nas = which(is.na(clusters))
print(rownames(y)[nas])
clusters = clusters[-nas]
# For each cluster (with at least two points), display the included points
for(i in 1:max(clusters, na.rm = TRUE)) print(rownames(y)[clusters == i])

明らかに、これを何らかの関数に変更して、よりユーザーフレンドリーにすることをお勧めします。特に、これは樹形図の 1 つのレベルでのみクラスターを提供します。他のレベルでクラスターを取得するには、thresholdパラメーターをいじる必要があります。

于 2013-08-21T13:14:34.160 に答える