adaptP: Adapt a Transition Matrix to a Specific Stationary...

View source: R/C2pop.R

adaptPR Documentation

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)

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

Value

the adjusted transition matrix.

Author(s)

Leonhard Held

See Also

C2pop for an alternative method.

Examples

## 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)

hhh4contacts documentation built on Oct. 8, 2024, 1:08 a.m.