虽然TraMineR
对子串没有特定的功能,但你可以通过玩时间限制来获得类似子串的结果。
例如,maxGap=1
在您的约束参数中进行设置,seqefsub
可以获得由在两个连续时间点发生的事件形成的频繁子序列。我在下面actcal
用TraMineR
.
library(TraMineR)
data(mvad)
data(actcal)
## creating a state sequence object
actcal.seq <- seqdef(actcal,13:24,
labels=c("> 36 hours", "19 to 36 hours", "< 19 hours", "no work"))
## transforming into an event sequence object
actcal.seqe <- seqecreate(actcal.seq, tevent="state")
## frequent subsequences without constraints
fsubs <- seqefsub(actcal.seqe, pMinSupport=.01)
library(TraMineRextras)
fsubsn <- seqentrans(fsubs)
## displaying only subsequences with at least 2 events
fsubsn[fsubsn$data$nevent>1]
## Now with the maxGap=1 constraint
cstr <- seqeconstraint(maxGap=1)
fsstr <- seqefsub(actcal.seqe, pMinSupport=.01, constraint=cstr)
fsstrn <- seqentrans(fsstr)
fsstrn[fsstrn$data$nevent>1]
在该示例中,您将获得在连续位置发生事件的子序列。要获得独立于它们之间经过的时间的连续事件的子序列,请使用定义为连续数字的时间戳定义事件序列,例如
id event timestamp
1 A 1
1 C 2
1 B 3
2 C 1
2 B 2
3 A 1
3 B 2
...
希望这可以帮助