current state or move one state up or down, all with equal probability. For the edge cases, states 1 and 8, the chain can either stay or reflect towards the middle states.</p>
<p>Now we run our simulations with the transition matrix above:</p>
<pre class="r"><code>num.chains     &lt;- 5
num.iterations &lt;- 50
chain.states &lt;- matrix(NA, ncol=num.chains, nrow=num.iterations)
for(c in seq_len(num.chains)){
  chain.states[,c] &lt;- run.mc.sim(P)
}</code></pre>
<p>And finally we plot the chains through time 