Created
October 4, 2017 01:16
-
-
Save dgrtwo/1d17ed61984ef140f0dac21962b2d048 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(purrr) | |
transition_mc <- function(steps, start, mat) { | |
i <- seq_len(nrow(mat)) | |
transition <- ~ sample(i, 1, prob = (i == .) %*% mat) | |
accumulate(seq_len(steps), transition, .init = start) | |
} | |
# Example: 1 wants to go to 2, 2 could go back to 1, 3 is absorbing | |
transition_matrix <- rbind( | |
c(.1, .9, 0), | |
c(.45, .45, .1), | |
c(0, 0, 1) | |
) | |
# 30 steps starting in state 2 | |
transition_mc(30, 2, transition_matrix) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment