# C2pop: Adapt a Contact Matrix to Population Fractions In hhh4contacts: Age-Structured Spatio-Temporal Models for Infectious Disease Counts

## Description

Experimental function, which tries to adjust a given contact matrix such that the stationary distribution of its row-normalized version (i.e., the transition matrix) becomes approximately equal to a prespecified probability vector.

## Usage

 `1` ```C2pop(C, target, eps = 0.001, iter.max = 100) ```

## Arguments

 `C` a square numeric (contact) matrix. `target` the stationary probability vector to approximate. `eps` the tolerated mean absolute difference between the target probabilities and the stationary distribution of the adapted, normalized contact matrix. `iter.max` maximum number of iterations (guard against infinite loop).

## Author(s)

Leonhard Held (original) and Sebastian Meyer (this implementation)

`adaptP` for an alternative method.

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16``` ```GROUPING <- c(1, 2, 2, 4, 4, 2) C <- contactmatrix(grouping = GROUPING) popBErbyg <- aggregateCountsArray(pop2011, dim = 2, grouping = GROUPING) popfracs <- prop.table(colSums(popBErbyg)) ## adapt 'C' to the given population fractions Cpop <- C2pop(C, popfracs) ## compare the stationary distributions compstat <- cbind(before = stationary(C/rowSums(C)), popBE = popfracs, after = stationary(Cpop)) matplot(compstat, type="b", lty=1, ylim=c(0, max(compstat)), xlab="age group", ylab="population fraction") ## compare the normalized contact matrices print(plotC(C/rowSums(C), main="original", at=seq(0,0.6,length.out=17)), split=c(1,1,2,1), more=TRUE) print(plotC(Cpop, main="adapted", at=seq(0,0.6,length.out=17)), split=c(2,1,2,1), more=FALSE) ```

### Example output

```Loading required package: surveillance