問題涉及cluster
包。 (見http://stat.ethz.ch/R-manual/R-devel/library/cluster/html/agnes.object.html)的幫助頁面通過agnes
返回agnes.object
指出,這個對象包含order.lab
組件「類似order
,但含有觀察,而不是標籤觀察的數字。這部分是唯一可用的,如果原來的看法被標記。」
由TraMineR生成的不相似矩陣(您的情況爲twitter.om
)當前沒有將序列標籤保留爲行和列名稱。要獲得order.lab
組件,您必須手動將序列標籤分配爲twitter.om
矩陣的rownames
和colnames
。我在此用TraMineR軟件包提供的mvad
數據進行說明。
library(TraMineR)
data(mvad)
## attaching row labels
rownames(mvad) <- paste("seq",rownames(mvad),sep="")
mvad.seq <- seqdef(mvad[17:86])
## computing the dissimilarity matrix
dist.om <- seqdist(mvad.seq, method = "OM", indel = 1, sm = "TRATE")
## assigning row and column labels
rownames(dist.om) <- rownames(mvad)
colnames(dist.om) <- rownames(mvad)
dist.om[1:6,1:6]
## Hierarchical cluster with agnes library(cluster)
cward <- agnes(dist.om, diss = TRUE, method = "ward")
## here we can see that cward has an order.lab component
attributes(cward)
這是爲了獲得帶有序列標籤而不是數字的order
。但是現在我不清楚在文本/表格中你想要哪個結果。從樹形圖中,您決定要在哪裏剪切它,即您想要的組的數量,並用cutree
(例如, cl.4 <- cutree(clusterward1, k = 4)
。結果cl.4
是一個具有每個序列的羣集成員身份的向量,並且您將獲得羣組1成員的列表,例如rownames(mvad.seq)[cl.4==1]
。
或者,您可以使用identify
方法(請參見?identify.hclust
)從圖中交互式地選擇組,但需要將參數作爲as.hclust(cward)
傳遞。這裏是這個例子的代碼
## plot the dendrogram
plot(cward, which.plot = 2, labels=FALSE)
## and select the groups manually from the plot
x <- identify(as.hclust(cward)) ## Terminate with second mouse button
## number of groups selected
length(x)
## list of members of the first group
x[[1]]
希望這會有所幫助。
非常感謝!這非常有幫助! – histelheim 2012-08-14 22:25:59