Plot Event Sequences/Event Sequences Clustering

Plot Event sequences / Event Sequences Clustering

You are right. The seqplot family of functions are for state sequences only.

To plot event sequences as state sequences, you have to first transform them into state sequences.

Assuming your event sequences are in the TSE format (vertical time-stamped event form) as the actcal.tse example file provided by TraMineR, you can convert them into state sequences using TSE_to_STS of the companion TraMineRextras package.

For the transformation , you have to specify in which state you are after each event. You do that by creating a transformation matrix with the seqe2stm function. Each cell of that matrix should give the new state which results when the column event (column name) occurs while we are in the corresponding row state (row name).

To illustrate, here is the example from the help page of TSE_to_STS

data(actcal.tse)
events <- c("PartTime", "NoActivity", "FullTime", "LowPartTime")

## States defined by last occurred event (forgetting all previous events).
stm <- seqe2stm(events, dropList=list("PartTime"=events[-1],
NoActivity=events[-2], FullTime=events[-3],
LowPartTime=events[-4]))

mysts <- TSE_to_STS(actcal.tse[1:100,], id=1, timestamp=2, event=3,
stm=stm, tmin=1, tmax=12, firstState="None")

Once you have your state sequences in STS form, you can create the state sequence object and plot them.

my.seq <- seqdef(mysts)
seqdplot(my.seq)

Alternatively, you can make a parallel coordinate plot of your event sequence using the seqpcplot function. There are plenty of example on the help page of that function. For details on the plot refer to

Bürgin, R. & Ritschard, G. (2014), "A decorated parallel coordinate plot for categorical longitudinal data", The American Statistician. Vol. 68(2), pp. 98-103. doi

Hope this helps.

How to create a state sequence from an event sequence in TraMineR?

Look at this answer for how to convert event sequences in time stamped event (TSE) format to state sequences. And here you will find a solution for putting the outcome of seqefsub into TSE form.

Note that plots for state sequences may not be suited for rendering the outcome of seqefsub. The returned subsequences have no time stamp, which will result in an state alignment without sound meaning.
Why not simply using plot(subs), or the seqpcplot function if you are interested in the order of the events. seqpcplot accepts directly event sequences objects as input, and the outcome of seqefsub is such an object.

Transforming states sequences into event sequences

So in the sequence I used I set a code for missing values, the missing="Z" option in the seqdef() function.

I managed to make it work by not setting the missing option and creating a "dummy" state Z, that I added to the alphabet and a label "Z-missing". Also I set the options left="Z" and right="Z" .

still looks like a bug to me though.

how to represent multichannel event sequences

This is actually similar to the question asked here (although they did not know to reference "multi-channel" and the title was vague): Multiple events in traminer

TraMineR has support for dealing with multichannel sequences with functions like:
seqdistmc

The general approach, I believe, is to do exactly what I outlined as our "flatten" solution. In this case you combine the values for each channel into one event type. e.g. in my example dog.hound.female would be one event with one channel/field to replace the first event in my example that has 3 separate fields/channels. You then use the typical functions for finding distances, subsequences, etc. You do have options for setting up substitution costs and finding distances though, so it has some extra options for doing this multi-channel approach. It also deals with missing values in case you have channels that are different length or have gaps.

This is also similar to what's suggested in the answer to the topic linked above, using the native R function interaction.

Parallel coordinate plot (seqpcplot) using TraMineR: How are event sequences without any transition represented?

Empty zero-event sequences are represented with a black square south-west of the bottom left translation zone.

However, the two event sequences given in your example are NOT zero-event sequences. They each have a start event, namely full_time and part_time. Such patterns are represented with a square on the first coordinate axis, respectively in regard of full_time and part_time.

If you don't use the embedding trick, they will appear as isolated squares with size proportional to their frequencies. With option ltype = "non-embeddable", the pattern will be embedded in some other pattern starting with the same event. This is reflected with the start square bigger than the next one on the same path.

So in your case, if say the first one is the most frequent pattern: With ltype = "unique", you should have a relatively large isolated square next to full_time on the first coordinate. With ltype = "non-embeddable", you should have an even bigger square next to full_time, but with a path continuing to some point on the second coordinate where you should observe a smaller square (where it represents fewer cases than at the start point).

Hope this helps.



Related Topics



Leave a reply



Submit