lass="r"><code># setup transition matrix 
P &lt;- t(matrix(c( 0.7, 0.2, 0.1, 
                 0.4, 0.6,   0, 
                   0,   1,   0  ), nrow=3, ncol=3))</code></pre>
<p>Now we will use the function we wrote in the previous section to run several chains and plot the results:</p>
<pre class="r"><code>num.chains     &lt;- 5
num.iterations &lt;- 50

# each column stores the sequence of states for a single chains
chain.states  &lt;- matrix(NA, ncol=num.chains, nrow=num.iterations)

# simulate chains
fo