r语言 - 从过渡矩阵创建一个马尔可夫链对象



>我有一个包含 4 行和 16 列的过渡矩阵,包含从一篇维基百科文章过渡到另一篇维基百科文章的概率。我的行的总和已归一化为等于 1。

以下是概述:

dput(head(res,4))
structure(c(0.0269201326869099, 0.221418475097697, 0.0572200491955321, 
0.0234890665263753, 0.0931927078903348, 0.203375737923007, 0.310133473123916, 
0.220087000151008, 0.00266507896005217, 0.0293922008813503, 0.00467760796806323, 
0.0045399854837374, 0.00598225170820221, 0.0235719630830631, 
0.0370176216782935, 0.00138830028204416, 0.0424711519378526, 
0.0206618441839195, 0.0414532844066293, 0.0344054908493962, 0.0334552465198038, 
0.0453978548266401, 0.166498649139078, 0.0243074330084224, 0.391312976666383, 
0.34181425126798, 0.131335940965361, 0.113533735696854, 0.190425562076493, 
0.0283528727030847, 0.00129037461187951, 0.0467297003707005, 
0.0281959683592753, 0.061278789390538, 0, 0.0299483162596755, 
0, 0.0158809345638979, 0.0305254244122747, 0, 0.0255592413030535, 
0, 0.0753659421750877, 0.0176874327161486, 0, 0, 0.0458082987217227, 
0, 0.0268350769754189, 0, 0.0630670591556111, 0.260016464754222, 
0, 0, 0.000846808339045929, 0.00347318631964031, 0.0287771823877973, 
0.00253596075496799, 0.0145570385902657, 0.0108920681777219, 
0.104207422528423, 0.00631911532385466, 0.0202024275172386, 0.209501819404054
), .Dim = c(4L, 16L), .Dimnames = list(c("Selected Disease Article", 
"Selected Food Scandal Article", "Selected General Article", 
"Selected Pathogen Article"), c("Animal health", "Biology", "Environment", 
"Food industry", "General", "Human and animal health", "Human health", 
"Medicine", "Other", "Related to a Food scandal", "Related to Antibiotic resistance", 
"Related to Food poisoning", "Selected Disease Article", "Selected Food Scandal Article", 
"Selected General Article", "Selected Pathogen Article")))

我遵循了下面的代码,但我卡在了我的马尔可夫链对象的定义上

states <- as.character(1:16)
mc <- new(
    "markovchain",
    states = states,
    byrow = TRUE,
    transitionMatrix = res,
    name = "random_walk");

我收到错误:dinames(x( <- dn 中的错误: "暗名"[2] 的长度不等于数组范围

我的代码中有什么问题?我在创建马尔可夫链函数时做错了什么吗?

这更像是你的(过渡(马尔可夫矩阵的基本问题,它是一个m x n矩阵,它应该是一个n x n矩阵:

http://www.math.harvard.edu/~knill/teaching/math19b_2011/handouts/lecture33.pdf

这可能是您收到dimnames error的原因,因为对象期望dimnames具有相同的长度,请参阅文档的第 4 页:

https://cran.r-project.org/web/packages/markovchain/markovchain.pdf

马尔可夫链的酷可视化:

http://setosa.io/ev/markov-chains/

最新更新