Is there any way of getting a matrix with the count of transitions between states?. Something similar to the "seqtrate()" but containing the number of transitions instead of just the transitions rate?
Thank you.
Cross Validated is a question and answer site for people interested in statistics, machine learning, data analysis, data mining, and data visualization. It only takes a minute to sign up.
Sign up to join this communityTraMineR
has no such function. However you can easily get a matrix of the count of transitions from the matrix TRATE
of the transition probabilities by premultiplying this matrix by the vector of the total number of occurrences of the states in the L-1 first positions.
I illustrate using the the first 10 sequences of the actcal
data set that ships with TraMineR
.
data(actcal)
## The sequence data are in columns 13 to 24
actcal.seq <- seqdef(actcal[,13:24])
s <- actcal.seq[1:10,]
## dropping last position in the sequences
s1 <- seqdef(s[,1:ncol(s)-1], alphabet=alphabet(s))
n1 <- colSums(seqistatd(s1)) # number of occurrence of each state
## and now the matrix of transition counts
n1*seqtrate(s)
This works for sequences of equal length. You will have to adapt the code if your sequences have different lengths because the last valid state in each sequence would not all be in the same column.
Hope this helps.