# Second order markov tranision probability matrix

I tried to find the second order Markov chain of the following sequence

Dat= A A B A B A A A B B A A B

I tried it on "Markov chain" package in R.

D=c("A", "A", "B", "A", "B", "A", "A", "A", "B", "B", "A", "A", "B")
fitHigherOrder(D,2)


I got this result

 $Q[[2]] A B A 0.3333333 0.75 B 0.6666667 0.25  But from Fit and evaluate a second order transition matrix (Markov Process) in R? discussion, I am little bit confused. Suppose, if I want to calculate AA-B, from the following formula for 2nd order, Tijk= Nijk/Nij  If I follow this formula, I got probability 1.0 for AA to B transition, as there are three times AA is followed by B and three times AA transition occurs. If I am right, then how to interpret the "Markov chain" package result? I mean what is the correct way to show/ calculate the 2nd order Markov chain? • Which part of the referenced thread are you following? The two answers given there are completely different and contradict each other. Could you explain what you understand a "second order" Markov chain to be? – whuber Commented Feb 5, 2018 at 14:32 • To me the second answer is reliable. To my understanding, first-order Markov chain is that follows just only the previous state. But in case of second-order Markov chain, it will follow previous two states. So, for 2nd order Markov chain, the transition probability should be n^2 x n dimension. If I am wrong, please enlighten me. Commented Feb 5, 2018 at 21:13 • That is right. Why, then, are you reporting a$2\times 2\$ matrix? This obviously is not the transition matrix. For its meaning, please read the documentation for this R package.
– whuber
Commented Feb 5, 2018 at 22:10