Understanding Markov Chain source code in R

此生再无相见时 提交于 2019-12-02 08:20:40

Names of the states don't really need to have any statistical meaning as long as they are different. So, while simulating transitions between states, it's perfectly fine to choose states <- 1:length(init) or any other names for them. Ultimately, though, for practical purposes we often have in mind some labels in mind, such as -1, 0, ..., n, as in your example. You can provide those names as the labels parameter and then labels[simlist] will rename 1:length(init) to labels, element by element. I.e., if initially we had c(1, 2, 3) and you provided labels as c(5, 10, 12), then the output will be in terms of the latter vector. For instance,

(states <- sample(1:3, 10, replace = TRUE))
# [1] 1 3 3 2 2 1 2 1 3 3
labels <- c(5, 10, 12)
labels[states]
# [1]  5 12 12 10 10  5 10  5 12 12
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!