如何防止 TraMineR 状态分布图 (seqdplot) 删除缺失状态
我正在分析一些序列数据,并希望能够看到所有序列图中缺失的状态。然而,我注意到 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")
I am analysing some sequence data and wish to be able to see missing states within all of my sequence plots. However, I have noticed that TraMineR's state distribution plot function seqdplot
automatically removes missing sequence states. I have included a reproducible example below. As you can see, the missing data is visible in the plot and legend of the sequence index plot seqIplot
. However, it is automatically removed from the state distribution plot seqdplot
.
How do I stop seqdplot
from removing these missing values?
Create & Format Data
# 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])
Sequence Index Plot (missing data visible)
# Create sequence index plot
seqIplot(mvad.seq, sortv = "from.start", with.legend = "right")
State Distribution Plot (missing data removed)
# Create state distribution plot
seqdplot(mvad.seq, sortv = "from.start", with.legend = "right")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要显示缺失值,只需使用参数
with.missing=TRUE
默认情况下,
seqdef
将右侧缺失值设置为空,即,它假定序列在最后一个有效状态处结束。如果您还想将(显示)右侧缺失视为缺失标记,请在seqdef
命令中设置right=NA
(即right="DEL"
代码>默认):To display missing values, simply use the argument
with.missing=TRUE
By default,
seqdef
sets right missings as voids, i.e., it assumes sequences end at the last valid state. If you want also to treat (display) right missings as missing tockens, setright=NA
in theseqdef
command (it isright="DEL"
by default):