Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
594 views
in Technique[技术] by (71.8m points)

r - Plot Event sequences / Event Sequences Clustering

Perhaps this is a veru dull question, but I did my research on it and couldn't find an answer.

I want to plot my event sequences in the same way we plot sequences of states using seqIplot, seqfplot, seqdplot and seqmtplot. seqplot in general.

when I try to do so I get the message :

Error: data is not a sequence object, use seqdef function to create one

Leading me to believe that those functions only apply to sequence of states.

In the user's guide section 10 on they only give examples of plots of subsequences. But those are not quite the same.

1) Is there a way to generate the mentioned plots for event sequences ? in which the states would be the transitions.

Also when I try to compute a distance matrix I get a similar error:

Error:  [!] data is not a state sequence object, use 'seqdef' function to create one

2) Isn't it possible to compute distance matrices and then apply clustering methods to event sequences ?

thanks !

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...