在状态序列中忽略时间

时间:2019-01-21 13:52:56

标签: r time range sequence traminer

我有一系列的事件在很长一段时间内发生(123)。有200多个州。样本由110家公司组成。有8种不同的事件。

时间范围如此之大,以至于产生了无用状态的负载。考虑到每个事件之间的时间为1,我试图忽略时间的影响。这给出了非常有趣且可解释的结果,但这有意义吗?

library(TraMineRextras)
head(seq.tse.data)
seq.tse.data <- structure(list(
ID = c(1L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 
     4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 
     6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L),
Year = c(2008L, 2010L, 2012L, 2007L, 2009L, 2010L, 2012L,
       2013L, 1996L, 1997L, 1999L, 2003L, 2006L, 2008L, 
       2012L, 2007L, 2007L, 2008L, 2003L, 2007L, 2007L,
       2009L, 2009L, 2011L, 2014L, 2016L, 2006L, 2009L, 
       2011L, 2013L, 2013L, 2015L, 2015L, 2016L), 
Event = c(5L, 4L, 5L, 3L, 1L, 5L, 5L, 5L, 3L,3L,3L,3L,3L,5L, 1L, 5L,
5L,5L,4L,5L, 5L, 5L, 5L, 5L, 5L,5L,5L,5L, 4L, 4L, 1L, 4L, 1L,5L)), 
      class = "data.frame", row.names = c(NA, -34L)
      )
    seq.sts <- TSE_to_STS(seq.tse.data,
                     id = 1, timestamp = 2, event = 3, 
                     stm =NULL, tmin = 1935, tmax = 2018,
                     firstState = "None")
seq.SPS <- seqformat(seq.sts, 1:84, from = "STS", to = "SPS")
seq.obj <- seqdef(seq.SPS)
> head(seq.tse.data)
  ID Year Event
1  1 2008     5
2  2 2010     4
3  2 2012     5
4  3 2007     3
5  3 2009     1
6  3 2010     5
> head(seq.obj)
    Sequence                            
[1] (None,74)-(5,10)-1                  
[2] (None,76)-(4,2)-(5.4,6)-2           
[3] (None,73)-(3,2)-(3.1,1)-(5.3.1,8)-3 
[4] (None,62)-(3,12)-(5.3,4)-(5.3.1,6)-3
[5] (None,73)-(5,11)-1                  
[6] (None,69)-(4,4)-(5.4,11)-2  

> head(alphabet(seq.obj),10)
 [1] "(1,1)"  "(1,10)" "(1,11)" "(1,12)" "(1,14)" "(1,19)" "(1,2)"  "(1,21)" "(1,25)" "(1,3)" 
...
[145] "(5.4.3.1,5)"   "(5.4.3.1,6)"   "(5.4.3.1,7)"   "(5.4.3.1,8)"   "(5.4.3.1.2,9)" "(None,1)"      "(None,11)"     "(None,20)"    
[153] "(None,26)"     "(None,30)"     "(None,38)"     "(None,41)"     "(None,42)"     "(None,44)"     "(None,45)"     "(None,49)"    
[161] "(None,51)"     "(None,53)"     "(None,55)"     "(None,57)"     "(None,58)"     "(None,59)"     "(None,60)"     "(None,61)"    
[169] "(None,62)"     "(None,64)"     "(None,65)"     "(None,66)"     "(None,67)"     "(None,68)"     "(None,69)"     "(None,7)"     
[177] "(None,70)"     "(None,71)"     "(None,72)"     "(None,73)"     "(None,74)"     "(None,75)"     "(None,76)"     "(None,77)"    
[185] "(None,78)"     "(None,79)" 

预先感谢

Antonin

1 个答案:

答案 0 :(得分:1)

按照您的方法,字母的元素是拼写(state, duration)。那真的是你想要的吗?

默认情况下,seqdef函数(来自TraMineR包)期望以STS形式输入。如果要使用状态字母而不是(state, duration)对,只需使用seq.sts作为seqdef的第一个参数即可。

seq.obj <- seqdef(seq.sts)

或者,如果您要使用SPS形式的数据

seq.obj <- seqdef(seq.sps, informat = "SPS")

在两种情况下,字母都是

alphabet(seq.obj)
## [1] "3"     "5"     "5.1"   "7"     "8"     
## [6] "8.1.3" "8.3"   "8.5.1" "8.7"   "8.7.6"
## [11] "None"