View the step-by-step solution to:

Question

<pre class="ql-syntax">make some observations on the sample path(s) of a Markov chain

model  &gt; P &lt;- matrix(data = c(0.45, 0.48, 0.07, + 0.05, 0.70, 0.25, + 0.01, 0.50, 0.49), nrow=3, byrow = TRUE) &gt; P Complete the first function below to generate the sample path(s) data. <span class="hljs-comment"># generate a matrix that contains sample paths and classify it as a "dsdtmc" object</span> simulate_MC_sample_paths &lt;- <span class="hljs-keyword">function</span>(transition_probability_matrix, number_sample_paths, initial_states, number_iterations) { sample_paths &lt;- matrix(data = NA, ncol = number_sample_paths, nrow = number_iterations) <span class="hljs-keyword">for</span> (j <span class="hljs-keyword">in</span> 1:number_sample_paths) { sample_paths[1, j] &lt;- initial_states[j] <span class="hljs-keyword">for</span> (i <span class="hljs-keyword">in</span> 2:number_iterations) { <span class="hljs-comment">##### Your Code Starts Here ##### </span> p &lt;- transition_probability_matrix[sample_paths[, j], ] <span class="hljs-comment">##### Your Code Ends Here ##### </span> sample_paths[i, j] &lt;- <span class="hljs-built_in">which</span>(rmultinom(n = 1, size = 1, prob = p) == 1) } } <span class="hljs-comment"># return</span> structure(sample_paths, class = <span class="hljs-string">"dsdtmc"</span>) <span class="hljs-comment"># assign sample_paths to the "dsdtmc" class</span> } <span class="hljs-comment"># add a method to the generic function plot() for the "dsdtmc" class</span> plot.dsdtmc &lt;- <span class="hljs-keyword">function</span>(sample_paths) { pch &lt;- 16 cex &lt;- 0.5 plot(sample_paths[, 1], <span class="hljs-built_in">type</span> = <span class="hljs-string">"l"</span>, col = 1, xlab = <span class="hljs-string">"Time"</span>, ylab = <span class="hljs-string">"State"</span>) points(sample_paths[, 1], pch = pch, cex = cex, col = 1) <span class="hljs-keyword">if</span> (ncol(sample_paths) &gt; 1) { <span class="hljs-keyword">for</span> (j <span class="hljs-keyword">in</span> 2:ncol(sample_paths)) { lines(sample_paths[, j], col = j) points(sample_paths[, j], pch = pch, cex = cex, col = j) } } } </pre>

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes