对分类序列数据进行层次聚类分析的序列比对

问题描述 投票:0回答:1

我有 30 个人展示的短期行为数据集。

#Load packages
library(TraMineR)

# Function to generate a random non-numerical sequence
generate_random_sequence <- function(length) {
  alphabet <- c("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K")  
  return(sample(alphabet, length, replace = TRUE))
}

# Generate 15 sequences with lengths between 15 and 40
num_sequences <- 30
min_length <- 15
max_length <- 40

# Create a data frame
sequence_data <- as.data.frame(matrix(NA, ncol = max_length, nrow = num_sequences))

# Populate the data frame with random sequences
for (i in 1:num_sequences) {
  seq_length <- sample(min_length:max_length, 1)
  sequence_data[i, 1:seq_length] <- generate_random_sequence(seq_length)
}

# Create the sequence object using seqdef
sequences <- seqdef(sequence_data, informat = "STS")

我想执行层次聚类分析,看看连续变量

x
是否可以预测每个序列属于哪个聚类。 然而我的序列长度却截然不同。我尝试过运行动态时间扭曲,但我的理解是,由于 DTW 使用距离,它不能应用于分类数据。我不知所措 - 如何对齐我的序列以便我可以执行 HCA?

r sequence hierarchical-clustering sequence-analysis
1个回答
0
投票

对分类序列进行聚类是典型的序列分析(SA)(请参阅社会科学中的序列分析以及其中给出的许多参考文献)。

存在多种方法来测量分类序列之间的差异,包括不同长度的序列之间的差异。请参阅Studer 和 Ritschard (2016) 的评论。其中许多可以使用 TraMineR 包的

seqdist
函数来计算。

我在下面使用 INDELSLOG indel 的最佳匹配距离和替换成本(基于不同标记出现频率的成本)进行说明

dist.om <- seqdist(sequences, method="OM", sm="INDELSLOG")
hcl <- hclust(as.dist(dist.om))
plot(hcl)

© www.soinside.com 2019 - 2024. All rights reserved.