# Question 1b ############################# MonopolyChain1 <- function(N){ x <- rep(NA, N+1) # for storing the simulated states x[1] <- 0 # initial states for (k in 1:N){ d <- sample(6,2,replace=TRUE) # two independent rolls of a dice x[k+1] <- (x[k]+sum(d))%%36 } return(x) } N1 <- 100 # number of steps simulated from the Markov chain. chain1 <- MonopolyChain1(N1) ts.plot(chain1) # Question 1c ############################# N2 <-10^5 chain2 <- MonopolyChain1(N2) barplot(table(chain2)) # Question 2a ############################# MonopolyChain2 <- function(N){ x <- rep(NA, N+1) # for storing the simulated states x[1] <- 0 # initial states for (k in 1:N){ d <- sample(6,2,replace=TRUE) if (x[k] == 18){ # i.e. if you are in jail if (sum(d) == 12){ x[k+1] <- (x[k]+sum(d))%%36 } else { x[k+1] <- x[k] } } else { # i.e. if you are not in jail x[k+1] <- (x[k]+sum(d))%%36 } } return(x) } N3 <- 10^5 # number of steps simulated from the Markov chain. chain3 <- MonopolyChain2(N3) barplot(table(chain3))