seqeconstraint中max.gap和window.size的区别

The difference between max.gap and window.size in seqeconstraint

我很难理解 max.gap 和 window.size 之间的区别以及它们的工作原理。

假设我有以下序列:947-(SP6)-992-(CP2)-2-(SP6)-4-(SP10),其中事件之间的数字表示分钟数(SP6 和 SP10 之间为 4 分钟)。

max.gap=2 约束下,我得到以下结果(尽管我预计结果中只有 (CP2)-(SP6),因为它们之间有 -2-):

> seqefsub(peer_data.seqe[30], min.support = 1, constraint = seqeconstraint(max.gap = 2))
         Subsequence Support Count
1              (CP2)       1     1
2        (CP2)-(SP6)       1     1
3 (CP2)-(SP6)-(SP10)       1     1
4             (SP10)       1     1
5              (SP6)       1     1
6       (SP6)-(SP10)       1     1

我不明白为什么结果中有 (SP6)-(SP10)。在这里,window.size 将如何改变这些东西?如果有人清楚地解释这一点,我将不胜感激。我将其用于我的研究,我不想错误地使用它。

max.gap=k条件意味着我们搜索子序列中两个连续事件之间最多k个时间单位的子序列。

window.size=w条件意味着我们搜索第一个事件和最后一个事件之间的持续时间不超过w.

的子序列

因此 max.gap 指的是子序列中连续事件之间的时间,window.size 指的是子序列的总持续时间。

我用你的示例序列来说明。

library(TraMineR)
dat <- read.table(header=TRUE, text = "
  id timestamp event
  30 947 'sp6'
  30 1939 'cp2'
  30 1941 'sp6'
  30 1945 'sp10'
  ")

(eseq <- seqecreate(dat)  )
# [1] 947-(sp6)-992-(cp2)-2-(sp6)-4-(sp10)

seqefsub(eseq, min.support = 1, constraint = seqeconstraint(max.gap = 2))
#   Subsequence Support Count
# 1       (cp2)       1     1
# 2 (cp2)-(sp6)       1     1
# 3      (sp10)       1     1
# 4       (sp6)       1     1
#
# Computed on 1 event sequences
# Constraint Value
# max.gap     2
# count.method  COBJ

如您所见,使用 max.gap=2 我们得到具有单个事件的子序列和子序列 (cp2)-(sp6),因为 sp6 发生在 cp2 之后 2 分钟。任何其他子序列在两个连续事件之间至少会有大于 2 的间隙。 (这个结果与你的不一致,我认为 peer_data.seqe[30] 不是所示的示例序列)。

现在,使用 window.size=6,我们又得到三个子序列。

seqefsub(eseq, min.support = 1, constraint = seqeconstraint(window.size = 6))

#          Subsequence Support Count
# 1              (cp2)       1     1
# 2       (cp2)-(sp10)       1     1
# 3        (cp2)-(sp6)       1     1
# 4 (cp2)-(sp6)-(sp10)       1     1
# 5             (sp10)       1     1
# 6              (sp6)       1     1
# 7       (sp6)-(sp10)       1     1
# 
# Computed on 1 event sequences
# Constraint Value
# window.size     6
# count.method  COBJ

特别是 (cp2)-(sp6)-(sp10) 的总持续时间为 6,(cp2)-(sp10) 的两个事件之间的总时间也是 6。减少 window.size 将消除这两个序列。同样,(sp6)-(sp10) 将被删除,window 大小小于 4。

作为最后一个示例,我将 window.size=6max.gap=4 结合使用。

seqefsub(eseq, min.support = 1, constraint = seqeconstraint(window.size = 6, max.gap=4))
#          Subsequence Support Count
# 1              (cp2)       1     1
# 2        (cp2)-(sp6)       1     1
# 3 (cp2)-(sp6)-(sp10)       1     1
# 4             (sp10)       1     1
# 5              (sp6)       1     1
# 6       (sp6)-(sp10)       1     1
#
# Computed on 1 event sequences
# Constraint Value
# max.gap     4
# window.size     6
# count.method  COBJ

这里我们得到的子序列比前面的例子少一个,即(cp2)-(sp10),因为两个事件之间有 6 分钟的间隔。