Search code examples
traminer

TSE_TO_STS application


I have 12 categorical sequence in TSE format. In the help page of this function tmax is specified as 12 based on the sequence data example used. How would I change this value if the maximum time length is 292 for one sequence and smaller than 292 for other sequences. Assume one of the sequence ends at time 25. using tmax=292, any state after 25 will use the same state till 292 which is wrong I believe. I would like to stop the sequence at time 25 and fill anything else on the right side with void.


Solution

  • TSE_to_STS is a function provided by the TraMineRextras package. It converts time stamped event sequences into state sequences. The resulting state sequences are in STS form, i.e., organized in a table with each sequence in a different row and the states in successive columns. tmaxis used to determine the number of columns of this table. Therefore, it should be fixed to the maximal state sequence length.

    To end a sequence at time 25 for example, you need to insert an end of sequence event at time 25. TSE_to_STS cannot guess when the sequence ends.

    ============ example

    Below I illustrate how to proceed using the actcal.tse data that ships with TraMineR. I consider the data for ids 2 and 4 and assume id 2 was observed up to the 8th month and id 4 up to the 10th month.

    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)
    

    We see the different length of the two resulting state sequences in the plot.

    enter image description here