# How to count the number of transitions between states in TraMineR?

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.

TraMineRhas 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.