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

Description Usage Arguments Value Author(s) See Also Examples

View source: R/C2pop.R

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

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
## 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 July 4, 2017, 9:44 a.m.