first state to <span class="math inline">\(1\)</span>:</p>
<pre class="r"><code># simulate discrete Markov chains according to transition matrix P
run.mc.sim &lt;- function( P, num.iters = 50 ) {
  
  # number of possible states
  num.states &lt;- nrow(P)
  
  # stores the states X_t through time
  states     &lt;- numeric(num.iters)

  # initialize variable for first state 
  states[1]    &lt;- 1

  for(t in 2:num.iters) {
    
    # probability vector to simulate next state X_{t+1}
    p  &lt;- P[states[t