Skip to contents

Constructor for a contactmatrix object

Usage

new_contactmatrix(from, to, value, fill = 0, symmetric = NA)

Arguments

from

Character vector, or list of named character vectors in the case of multiple groupings, indicating the characteristics of the group contacting.

to

Character vector, or list of named character vectors in the case of multiple groupings, indicating the characteristics of the group contacted.

value

Value of the contact between individual in groups from and group to

fill

Numeric value to use for contacts non-defined in the from, to, value argument triplet. Defaults to 0; i.e., no contact.

symmetric

Logical value (default to NA) indicating whether the resulting [contactmatrixis symmetric, i.e., $c_{ij}N_i == c_{ji}N_j$ where $i$ is a group fromfrom, $j$ a group from to, $c$ their corresponding contact value` and $N$ the group size.

Value

An array (a matrix if only 1 grouping = 2 dimensions) of subclass contactmatrix. The array has $2n$ dimensions where $n$ is the number of groupings.

Details

  • from, to and value must have the same length

Examples

# Usual case; single grouping by age
new_contactmatrix(
  from  = c("[0,5)", "[5,10)",  "[5,10)"),
  to    = c("[0,5)", "[10,15)", "[15,20)"),
  value = c(0.32   , 0.46   , 0.72   )
)
#> 
#> ── Contact matrix ──
#> 
#> ── Groupings 
#> [1] "[0,5)"   "[10,15)" "[15,20)" "[5,10)" 
#> 
#> ── Contact rates 
#>          _to
#> _from     [0,5) [10,15) [15,20) [5,10)
#>   [0,5)    0.32    0.00    0.00      0
#>   [10,15)  0.00    0.00    0.00      0
#>   [15,20)  0.00    0.00    0.00      0
#>   [5,10)   0.00    0.46    0.72      0

# Multiple groupings; gender & case
cm3d <- new_contactmatrix(
  from  = list(
    age = c("young", "young", "old"),
    gender = c("male", "female", "female")
  ),
  to    = list(
    age    = c("old", "old", "young"),
    gender = c("female", "female", "female")
  ),
  value = c(1, 2, 2)
)