替换状态代码序列中的 NA 值

Replacing NA values within sequences for a state code

我使用的数据集是一个已经制作好的长形数据集。它包括年轻人的工作状态,无论是兼职还是全职合同。所有 NA 值都被视为另一种状态:失业。 正在检查 TramineR user's guide and seqdef() help seems like this could be possible to do directly when creating the STS object by seqdef(), as it is explained briefly in the supporting documents

left:
the behavior for missing values appearing before the first (leftmost) valid state in each sequence. See Gabadinho et al. (2010) for more details on the options for handling missing values when defining sequence objects. By default, left missing values are treated as 'real' missing values and converted to the internal missing value code defined by the nr option. Other options are "DEL" to delete the positions containing missing values or a state code (belonging to the alphabet or not) to replace the missing values.

我尝试用新的状态代码替换 *% 值,但没有成功,在实际情况下(例如,在绘制序列时)无论如何都将其视为缺失。在检查了 leftrightgaps 参数后,它似乎也不是关键。

有人可以提示如何指定州代码,以便 NA 值实际上被视为包含在字母表中的州吗?非常感谢!

这是一个示例,其中左、间隙和右 NA 被新状态 ne 替换(不是在教育中)。请注意我们如何将元素 ne 添加到字母表中。

lab <- seqstatl(eduSTS.age)
long.lab <- c(lab, "not in education")
alphabet <- c(lab, "ne")
short.lab <- c("AP", "CS", "EV", "MA", "HS", "OT", "TV", "HV", "ne")
edu.seq <- seqdef(eduSTS.age, informat = "STS", alphabet = long.lab,
       states = short.lab, label = long.lab, missing = NA, left = "ne",
       gaps = "ne", right = "ne")

实际上,正如您在上面的示例中看到的,作为 leftgapsright 参数传递的字符串应该是 states (短标签)。如果这不是现有状态,则必须将其添加到 states,但您还需要将相应的元素添加到 alphabet,如果使用它,则添加到长 [=19] =].

希望这对您有所帮助。