MarkovChain包错误

时间:2017-03-21 14:00:37

标签: r matrix markov-chains

我使用库'markovchain'制作马尔可夫模型时遇到问题。 要制作markovchain图,您需要有一个transistion矩阵。如您所见,行总计为1。

> rowSums(trans_matrix)
          (start)      (conversion)            (null) GenericPaidSearch     OrganicSearch            Direct        Affiliates BrandedPaidSearch   NewsletterEmail            Social          Referral      Marketplaces        OtherEmail 
                1                 1                 1                 1                 1                 1                 1                 1                 1                 1                 1                 1                 1 
          Display 
                1 
> trans_matrix
                  (start) (conversion)    (null) GenericPaidSearch OrganicSearch    Direct  Affiliates BrandedPaidSearch NewsletterEmail       Social     Referral Marketplaces   OtherEmail     Display
(start)                 0  0.000000000 0.0000000        0.37693185    0.15836078 0.1617304 0.061413732       0.093944768     0.080808209 0.0166455536 0.0235115277 0.0126805169 0.0061692425 0.007803395
(conversion)            0  1.000000000 0.0000000        0.00000000    0.00000000 0.0000000 0.000000000       0.000000000     0.000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.000000000
(null)                  0  0.000000000 1.0000000        0.00000000    0.00000000 0.0000000 0.000000000       0.000000000     0.000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.000000000
GenericPaidSearch       0  0.026518121 0.2476859        0.00000000    0.22858954 0.2588602 0.096999616       0.068680265     0.020547374 0.0026017779 0.0095898864 0.0037192081 0.0109908437 0.025217232
OrganicSearch           0  0.020783463 0.1832775        0.30980878    0.00000000 0.2380805 0.118139063       0.050747698     0.017741981 0.0021966262 0.0219099383 0.0094060661 0.0102509223 0.017657495
Direct                  0  0.024502434 0.4800258        0.17849728    0.05675473 0.0000000 0.055662944       0.075476088     0.085230527 0.0057094788 0.0139604811 0.0020761741 0.0129939863 0.009110109
Affiliates              0  0.024389032 0.4040831        0.17484602    0.13595271 0.1892509 0.000000000       0.020216571     0.012418041 0.0021359030 0.0108285317 0.0090403338 0.0049175442 0.011921319
BrandedPaidSearch       0  0.022660202 0.2972702        0.13880691    0.12083685 0.2903668 0.071722175       0.000000000     0.030143339 0.0002107926 0.0076412310 0.0000000000 0.0100126475 0.010328836
NewsletterEmail         0  0.006875955 0.3729685        0.09029032    0.02312821 0.4032505 0.015140992       0.048478955     0.000000000 0.0005556327 0.0112515627 0.0029865259 0.0109042923 0.014168635
Social                  0  0.005744375 0.3834371        0.11967449    0.02058401 0.3011010 0.019147918       0.022020105     0.049305888 0.0000000000 0.0000000000 0.0004786979 0.0004786979 0.078027764
Referral                0  0.013950399 0.3492028        0.10518158    0.06753764 0.2843224 0.084145261       0.027015058     0.058237378 0.0004428698 0.0000000000 0.0002214349 0.0097431355 0.000000000
Marketplaces            0  0.009984235 0.3657383        0.13977930    0.09353652 0.2548607 0.074093537       0.002101944     0.001050972 0.0005254861 0.0000000000 0.0000000000 0.0026274304 0.055701524
OtherEmail              0  0.005845817 0.4607234        0.06868834    0.02922908 0.3704786 0.002922908       0.020460358     0.041286080 0.0000000000 0.0003653635 0.0000000000 0.0000000000 0.000000000
Display                 0  0.004073808 0.5837527        0.14306254    0.03882099 0.1418644 0.003594536       0.021567218     0.022046489 0.0393002636 0.0002396358 0.0004792715 0.0011981788 0.000000000

但是,当我尝试制作markovchain时,我收到了这个错误:

> trans_matrix12 <- new("markovchain", transitionMatrix = trans_matrix)
Error in validObject(.Object) : 
  invalid class “markovchain” object: Error! Row sums not equal to one
谁能帮助我?

1 个答案:

答案 0 :(得分:3)

在创建markovchain时,由于数字容差,markovchain包中存在isse。我已经在github上托管的开发版本上推了一个补丁...你可以通过以下方式下载:

devtools::install_github('spedygiorgio/markovchain')