I have a full set of sequences (432 observations to be precise) of 4 states $A-D$: eg

$$Y=\left(\begin{array}{c c c c c c c}
A& C& D&D & B & A &C\\
B& A& A&C & A&- &-\\
\vdots&\vdots&\vdots&\vdots&\vdots&\vdots&\vdots\\
B& C& A&D & A & B & A\\
 \end{array}\right)$$

**EDIT**: The observation sequences are of unequal lengths! Does this change anything?

Is there a way of calculating the transition matrix $$P\_{ij}(Y\_{t}=j|Y\_{t-1}=i)$$ in Matlab or R or similar? I think the HMM package might help. Any thoughts?

eg: [Estimating Markov chain probabilities](https://stats.stackexchange.com/questions/14360/estimating-markov-chain-probabilities)