Open GaryBAYLOR opened 9 years ago
Random walk is a non-convergent Markov Chain. We can show that it is not convergent
random.walk <- function(t = 1e4) { res <- numeric(t + 1) res[0] <- rnorm(1) for(i in 1:t) { res[i + 1] <- res[i] + rnorm(1) } plot(res, type = "l", lwd = 0.5) }
The plot looks like the following graph. Each time the random walk function is run, the plot is different.
If we slightly change the code, the Markov Chain will be convergent.
Markov.chain <- function(t = 1e4, rho = 0.9) { res <- numeric(t + 1) res[0] <- rnorm(1) for(i in 1:t) { res[i + 1] <- rho * res[i] + rnorm(1) } par(mfrow = c(1, 2)) plot(res, type = "l", lwd = 0.5) plot(density(res), type = "l") }
The plot is like this Each time the function is run, the density will be almost the same
Random walk is a non-convergent Markov Chain. We can show that it is not convergent
The plot looks like the following graph. Each time the random walk function is run, the plot is different.
If we slightly change the code, the Markov Chain will be convergent.
The plot is like this Each time the function is run, the density will be almost the same