我有12个TSE格式的分类序列。在此函数的帮助页面中,根据使用的序列数据示例,tmax被指定为12。如果一个序列的最大时间长度为292,而其他序列的最大时间长度小于292,我该如何更改此值。假设其中一个序列在时间25结束。使用tmax=292,25之后的任何状态都将使用相同的状态,直到292,我认为这是错误的。我想在时间25处停止该序列,并用void填充右侧的任何其他内容。
发布于 2018-02-13 16:54:04
TSE_to_STS是由TraMineRextras包提供的函数。它将带有时间戳的事件序列转换为状态序列。所得到的状态序列是STS形式的,即组织在表格中,其中每个序列在不同的行中,而状态在连续的列中。tmax用于确定该表的列数。因此,它应该固定为最大状态序列长度。
例如,要在时间25结束序列,需要在时间25插入序列结束事件。TSE_to_STS无法猜测序列何时结束。
============示例
下面我将演示如何继续使用TraMineR附带的actcal.tse数据。我考虑id2和id4的数据,并假设id2观察到第8个月,id4观察到第10个月。
data(actcal.tse)
## Consider the data for id 2 and 4 and
## insert "endobs" event to indicate end of observation
subset <- rbind(actcal.tse[2:4,], data.frame(id=2,time=8,event="endobs"),
actcal.tse[7:9,], data.frame(id=4,time=10,event="endobs"))
subset
## id time event
## 2 2 0 NoActivity
## 3 2 4 Start
## 4 2 4 FullTime
## 1 2 8 endobs
## 7 4 0 LowPartTime
## 8 4 9 Increase
## 9 4 9 PartTime
## 11 4 10 endobs
## Define list of events of interest
events <- c("PartTime", "NoActivity", "FullTime", "LowPartTime", "endobs")
## Dropping all previous events
stm <- seqe2stm(events, dropList=list(PartTime=events[-1], NoActivity=events[-2],
FullTime=events[-3], LowPartTime=events[-4], endobs=events[-5]))
mysts <- TSE_to_STS(subset, id=1, timestamp=2, event=3,
stm=stm, tmin=1, tmax=12, firstState="None")
## replacing "endobs" with NAs
mysts[mysts=="endobs"] <- NA
seq <- seqdef(mysts)
seqiplot(seq)我们在图中看到两个结果状态序列的不同长度。

https://stackoverflow.com/questions/48758896
复制相似问题