我正在分析一些序列数据,并希望能够在我的所有序列图中看到缺失的状态。但是,我注意到TraMineR的状态分布图函数seqdplot会自动删除缺失的序列状态。我在下面列举了一个可复制的例子。如您所见,缺少的数据在序列索引图seqIplot的绘图和图例中可见。但是,它会自动从状态分布图seqdplot中删除。
如何阻止seqdplot删除这些缺失的值?
创建和格式化数据
# Import required libraries
library(TraMineR)
library(tidyverse)
# Set seed for reproducibility
set.seed(123)
# Read in TraMineR sample data
data(mvad)
# For loop which generates missing data within the sequences
for (col in 17:86) {
mvad[sample(1:nrow(mvad),(round(nrow(mvad)*0.1))),col] <- NA
}
# Create sequence object
mvad.seq <- seqdef(mvad[, 17:86])
序列索引图(缺失数据可见)
# Create sequence index plot
seqIplot(mvad.seq, sortv = "from.start", with.legend = "right")

状态分布图(删除丢失数据)
# Create state distribution plot
seqdplot(mvad.seq, sortv = "from.start", with.legend = "right")

发布于 2022-03-05 08:01:23
要显示缺少的值,只需使用参数with.missing=TRUE
seqdplot(mvad.seq, sortv = "from.start", with.legend = "right",
with.missing=TRUE, border=NA)默认情况下,seqdef将右缺失设置为空,即假设序列结束于最后一个有效状态。如果还想将(显示)右缺失视为缺少的tockens,请在seqdef命令中设置seqdef(默认情况下是right="DEL" ):
mvad.seq <- seqdef(mvad[, 17:86], right=NA)https://stackoverflow.com/questions/71355609
复制相似问题