title: Fit and evaluate a second order transition matrix (Markov Process) in R?
body: <p>I am trying to build a <strong>second-order Markov Chain model</strong>, now I am try to find transition matrix from the following data.</p>
  
  <pre><code>dat&lt;-data.frame(replicate(20,sample(c("A", "B", "C","D"), size = 100, replace=TRUE)))
  </code></pre>
  
  <p>Now I know how to fit the first order Markov transition matrix using the function <code>markovchainFit(dat)</code> in  <code>markovchain</code> package.</p>
  
  <p>Is there any way to fit the second order transition matrix?</p>
  
  <p>How do evaluate the Markov Chain models? i.e. Should I choose the first order model or second order model?</p>