如何防止 TraMineR 状态分布图 (seqdplot) 删除缺失状态

发布于 2025-01-11 17:31:44 字数 1268 浏览 0 评论 0原文

我正在分析一些序列数据,并希望能够看到所有序列图中缺失的状态。然而,我注意到 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")

enter image description here

State Distribution Plot (missing data removed)

# Create state distribution plot
seqdplot(mvad.seq, sortv = "from.start", with.legend = "right")

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

溺ぐ爱和你が 2025-01-18 17:31:44

要显示缺失值,只需使用参数 with.missing=TRUE

seqdplot(mvad.seq, sortv = "from.start", with.legend = "right",
         with.missing=TRUE, border=NA)

默认情况下,seqdef 将右侧缺失值设置为空,即,它假定序列在最后一个有效状态处结束。如果您还想将(显示)右侧缺失视为缺失标记,请在 seqdef 命令中设置 right=NA(即 right="DEL"代码>默认):

mvad.seq <- seqdef(mvad[, 17:86], right=NA)

To display missing values, simply use the argument with.missing=TRUE

seqdplot(mvad.seq, sortv = "from.start", with.legend = "right",
         with.missing=TRUE, border=NA)

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, set right=NA in the seqdef command (it is right="DEL" by default):

mvad.seq <- seqdef(mvad[, 17:86], right=NA)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文