DESCRIPTION Students: Please keep in mind the OMSI rules. Save your files often, make sure OMSI fills your entire screen at all times, etc. Remember that clicking CopyQtoA will copy the entire question box to the answer box. In questions involving code which will PARTIALLY be given to you in the question specs, you may need add new lines. There may not be information given as to where the lines should be inserted. If a question includes test code, make sure to include it in your submission Do not answer any question with simulation code unless this is specified. MAKE SURE TO RUN THE CODE IN PROBLEMS INVOLVING CODE! Hit the OMSI Submit and Run button. QUESTION -ext .R -run 'Rscript omsi_answer1.R' (Code answer.) In our study of Markov chains, the transition matrix P was always either given to us, or easily formulated from the physical structure of the problem. In some applications, though, we may need to estimate P from data. You'll do that here, writing two functions with call forms makeStates(x,nc) findP(xmc) Here x are values observed at times 1,2,3,..., with the values typically being continuous but not necessarily so. The first function creates states 1,2,...,nc from continuous data x. It does this by breaking the range of x into nc equal intervals. It is suggested that you use R's cut() function for this. The second function actually estimates P. Here xmc is the output of makeStates(), or is x if x is already in state form. Of course, all this assumes the Markov Property holds, which we will not be checking. makeStates <- function(x,nc) { } findP <- function(xmc) { k <- max(xmc) # number of states n1 <- length(xmc) - 1 p <- matrix(nrow=k,ncol=k,0) for (m in 1:n1) { } } # test it! nmc <- makeStates(Nile,3) # Nile is built-in dataset in R nmc # [1] 3 3 2 3 3 3 2 3 3 3 2 2 3 2 2 2 3 2 2 3 3 3 3 3 3 3 2 # [28] 3 2 2 2 1 2 2 1 2 1 2 2 2 2 1 1 2 1 3 3 2 2 2 2 2 2 2 # [55] 1 2 1 2 2 1 2 2 2 2 2 2 2 2 2 1 1 2 2 1 2 2 2 2 2 2 1 # [82] 1 2 2 2 2 2 2 2 2 2 2 2 3 2 1 2 1 1 1 findP(nmc) # [,1] [,2] [,3] # [1,] 0.2941176 0.6470588 0.05882353 # [2,] 0.2131148 0.6721311 0.11475410 # [3,] 0.0000000 0.4285714 0.57142857