-1], ]
    
    ## draw from multinomial and determine state
    states[t] &lt;-  which(rmultinom(1, 1, p) == 1)
  }
  return(states)
}</code></pre>
</div>
<div id="simulation-1-3x3-example" class="section level1">
<h1>Simulation 1: 3x3 example</h1>
<p>Assume our probability transition matrix is: <span class="math display">\[P = \begin{bmatrix}
    0.7 &amp; 0.2 &amp; 0.1 \\
    0.4 &amp; 0.6 &amp; 0 \\
    0   &amp; 1   &amp; 0 
\end{bmatrix}\]</span></p>
<p>We initialize this matrix in R below:</p>
<pre c