r - 如何识别每个簇内的序列?

标签 r cluster-analysis data-manipulation traminer

使用作为 TraMineR 一部分提供的 biofam 数据集:

library(TraMineR)
data(biofam)
lab <- c("P","L","M","LM","C","LC","LMC","D")
biofam.seq <- seqdef(biofam[,10:25], states=lab)
head(biofam.seq)
     Sequence                                    
1167 P-P-P-P-P-P-P-P-P-LM-LMC-LMC-LMC-LMC-LMC-LMC
514  P-L-L-L-L-L-L-L-L-L-L-LM-LMC-LMC-LMC-LMC    
1013 P-P-P-P-P-P-P-L-L-L-L-L-LM-LMC-LMC-LMC      
275  P-P-P-P-P-L-L-L-L-L-L-L-L-L-L-L             
2580 P-P-P-P-P-L-L-L-L-L-L-L-L-LMC-LMC-LMC       
773  P-P-P-P-P-P-P-P-P-P-P-P-P-P-P-P 

我可以执行聚类分析:

library(cluster)
couts <- seqsubm(biofam.seq, method = "TRATE")
biofam.om <- seqdist(biofam.seq, method = "OM", indel = 3, sm = couts)
clusterward <- agnes(biofam.om, diss = TRUE, method = "ward")
cluster3 <- cutree(clusterward, k = 3)
cluster3 <- factor(cluster3, labels = c("Type 1", "Type 2", "Type 3"))

但是,在此过程中,biofam.seq 中的唯一 ID 已被数字 1 到 N 的列表替换:

head(cluster3, 10)
[1] Type 1 Type 2 Type 2 Type 2 Type 2 Type 3 Type 3 Type 2 Type 1
[10] Type 2
Levels: Type 1 Type 2 Type 3

现在,我想知道每个簇内有哪些序列,以便我可以应用其他函数来获取每个簇内的平均长度、熵、子序列、相异性等。我需要做的是:

  1. 将旧 ID 映射到新 ID
  2. 将每个簇中的序列插入到单独的序列对象中
  3. 对每个新序列对象运行我想要的统计数据

如何完成上面列表中的 2 和 3?

最佳答案

例如,第一个集群的状态序列对象可以简单地通过以下方式获得

bio1.seq <- biofam.seq[cluster3=="Type 1",]
summary(bio1.seq)

关于r - 如何识别每个簇内的序列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21342706/

相关文章:

R:如何在x轴上仅打印时间而不打印日期

r - 根据类别分析多项选择题和多项选择答案

R:除了 nstart 和 iter.max 的设置不同之外,k 均值中的集群相同

machine-learning - 模糊 c- 表示分类数据

javascript - 如何访问和处理嵌套对象,数组或JSON?

r - 对新数据集进行评分时保留 ID key (或任何其他列)?

R:多次对带有替换的向量进行采样

r - 在向量 R 中的值分隔符处拆分元素

R Shiny 仪表板+ highcharter : arguments are not named in hc_add_series

r - 如何创建一个 "Clustergram"的情节? (在 R 中)