hhh4contacts (version 0.13.1)

adaptP: Adapt a Transition Matrix to a Specific Stationary Distribution

Description

Experimental Metropolis-Hastings algorithm, which tries to adjust a transition matrix such that its stationary distribution becomes approximately equal to a prespecified probability vector.

Usage

adaptP(P, target, niter = 1e+06)

Value

the adjusted transition matrix.

Arguments

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

Author

Leonhard Held

See Also

C2pop for an alternative method.

Examples

Run this code
## 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)

Run the code above in your browser using DataLab