1

I'm using TraMineR to analyze the transitions between states over a 30 minute trial. There are 10 states, and then missing values, for the entire 108,000 frames. When I get the subsequences, it includes even one transition as a subsequence, and for my purposes, that isn't helpful. I know there's a way to cap how long the subsequences can be, but is there also a way to cap how many transitions it needs to be considered a subsequence?

# defines the STS object
seq.d <- seqdef(seq, informat="STS", stsep=NULL,
   alphabet=alph, states=bet, weights=NULL, 
   left=NA, right="DEL", void="%", nr="*",
   cnames=NULL, xtstep=1, tick.last=FALSE, cpal=NULL, 
   missing.color="darkgrey", labels=NULL)
# creates a seqelist object 
seq.e <- seqecreate(data=seq.d, id=NULL, timestamp=NULL,
                event=NULL, end.event=NULL, tevent="transition", use.labels = TRUE,
                weighted = NULL)
# subsequences ordered by frequency
seq.s <- seqefsub(seq.e, pmin.support = 0.10, constraint=seqeconstraint(max.gap = 30,
window.size = 300, age.min = -1, age.max = -1,age.max.end = -1, count.method = "CDIST"), max.k = 10)

1 Answer 1

0

The seqentrans function from TraMineRextras completes the table returned by seqefsub with the number of transitions and of events in the subsequences. Using this info it is easy to filter out subsequences which do not have the minimum number of transitions or events.

The example below is based on the example in the help page of seqentrans.

library(TraMineRextras)
data(actcal.tse)
actcal.seqe <- seqecreate(actcal.tse[1:500,])

##Searching for frequent subsequences appearing at least 10 times
fsubseq <- seqefsub(actcal.seqe, min.support=10)
fsubseq
##                         Subsequence    Support Count
## 1                        (FullTime) 0.45592705   150
## 2                      (NoActivity) 0.34042553   112
## 3                        (PartTime) 0.22492401    74
## 4                     (LowPartTime) 0.15197568    50
## 5                           (Start) 0.10334347    34
## 6                            (Stop) 0.10334347    34
## 7              (NoActivity)-(Start) 0.07902736    26
## 8                    (Start)-(Stop) 0.04863222    16
## 9                 (FullTime)-(Stop) 0.04863222    16
## 10             (LowPartTime)-(Stop) 0.04863222    16
## 11              (Start,LowPartTime) 0.04559271    15
## 12      (NoActivity)-(Start)-(Stop) 0.03951368    13
## 13              (NoActivity)-(Stop) 0.03951368    13
## 14       (NoActivity)-(LowPartTime) 0.03951368    13
## 15                       (Increase) 0.03951368    13
## 16                       (Decrease) 0.03951368    13
## 17 (NoActivity)-(Start,LowPartTime) 0.03647416    12
## 18          (NoActivity)-(FullTime) 0.03343465    11
## 19                 (Start,FullTime) 0.03343465    11
## 20                 (PartTime,Start) 0.03039514    10
## 21    (NoActivity)-(Start,FullTime) 0.03039514    10
## 
## Computed on 329 event sequences
##    Constraint Value
##  count.method  COBJ

Adding columns ntrans and nevent

fsubseq <- seqentrans(fsubseq)
## dispaying only those with at least 2 transitions
fsubseq[fsubseq$data$ntrans>1]
##                         Subsequence    Support Count ntrans nevent
## 1              (NoActivity)-(Start) 0.07902736    26      2      2
## 2                    (Start)-(Stop) 0.04863222    16      2      2
## 3                 (FullTime)-(Stop) 0.04863222    16      2      2
## 4              (LowPartTime)-(Stop) 0.04863222    16      2      2
## 5       (NoActivity)-(Start)-(Stop) 0.03951368    13      3      3
## 6               (NoActivity)-(Stop) 0.03951368    13      2      2
## 7        (NoActivity)-(LowPartTime) 0.03951368    13      2      2
## 8  (NoActivity)-(Start,LowPartTime) 0.03647416    12      2      3
## 9           (NoActivity)-(FullTime) 0.03343465    11      2      2
## 10    (NoActivity)-(Start,FullTime) 0.03039514    10      2      3

## dispaying only those with at least 3 events
fsubseq[fsubseq$data$nevent>2]
##                        Subsequence    Support Count ntrans nevent
## 1      (NoActivity)-(Start)-(Stop) 0.03951368    13      3      3
## 2 (NoActivity)-(Start,LowPartTime) 0.03647416    12      2      3
## 3    (NoActivity)-(Start,FullTime) 0.03039514    10      2      3

Not the answer you're looking for? Browse other questions tagged or ask your own question.