Skip to contents

The symmetry is achieved to ensure that n(i) * c(i, j) == n(j) * c(j, i) where n(i) is the population size of age group i and c(i, j) is the contact rate from age group i to age group j.

Usage

make_cmat_symmetric(cmat, pop)

Arguments

cmat

A contact matrix.

pop

A vector of population sizes for each age group.

Details

This function was adapted from that described in socialmixr::symmetrise() to work with a simple matrix and population vector. The process is implemented as described in the original function, replacing the ij-th entries with (c_ij * N_i + c_ji * N_j) / 2 and divided by the population size of the respective age group to ensure that the resulting matrix is symmetric with respect to the population sizes.

The resulting matrix will satisfy the condition that n(i) * c(i, j) == n(j) * c(j, i) for all age groups i and j, ensuring that the total number of contacts from age group i to age group j is equal to the total number of contacts from age group j to age group i.

The operation will change the row and column sums of the contact matrix.

Examples

cmat <- c(4, 2, 1, 3, 5, 6, 4, 5, 2) |>
  matrix(nrow = 3, byrow = TRUE)
pop <- c(100, 200, 300)

cmat_symm <- make_cmat_symmetric(cmat, pop)

# Checking symmetry
cmat_symm * pop == t(cmat_symm * pop)
#>      [,1] [,2] [,3]
#> [1,] TRUE TRUE TRUE
#> [2,] TRUE TRUE TRUE
#> [3,] TRUE TRUE TRUE