我编写了这些函数来对基于序列的数据进行聚类:
library(TraMineR)
library(cluster)
clustering <- function(data){
data <- seqdef(data, left = "DEL", gaps = "DEL", right = "DEL")
couts <- seqsubm(data, method = "CONSTANT")
data.om <- seqdist(data, method = "OM", indel = 3, sm = couts)
clusterward <- agnes(data.om, diss = TRUE, method = "ward")
(clusterward)
}
rc <- clustering(rubinius_sequences)
cluster_cut <- function(data, clusterward, n_clusters, name_clusters){
data <- seqdef(data, left = "DEL", gaps = "DEL", right = "DEL")
cluster4 <- cutree(clusterward, k = n_clusters)
cluster4 <- factor(cluster4, labels = c("Type 1", "Type 2", "Type 3", "Type 4"))
(data[cluster4==name_clusters,])
}
rc1 <- cluster_cut(project_sequences, rc, 4, "Type 1")
然而,这里集群的数量是任意分配的。有什么方法可以证明一定数量的集群捕获的方差量(或某种类似的度量)在一定数量的集群上开始达到收益递减点?我正在想象类似于因子分析中的碎石图。