adaptP | R Documentation |
Experimental Metropolis-Hastings algorithm, which tries to adjust a transition matrix such that its stationary distribution becomes approximately equal to a prespecified probability vector.
adaptP(P, target, niter = 1e+06)
P |
a transition matrix, i.e., a square matrix where all rows sum to 1. |
target |
the stationary probability vector to approximate. |
niter |
the number of iterations of the MCMC algorithm |
the adjusted transition matrix.
Leonhard Held
C2pop
for an alternative method.
## a row-normalized contact matrix
C <- matrix(c(0.8, 0.1, 0.1,
0.2, 0.6, 0.2,
0.1, 0.2, 0.7), byrow=TRUE, ncol=3, nrow=3)
stationary(C)
## population fractions define the target distribution
popfracs <- c(0.4, 0.3, 0.3)
## adapt 'C' to the given population fractions
Cpop <- adaptP(C, popfracs, niter = 50000)
stationary(Cpop)
## this method increases the diagonal values of 'C'
round(C, 3)
round(Cpop, 3)
round(Cpop/C, 3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.