Modelling the final size of an epidemic using finalsize requires us to represent the susceptibility status of multiple demographic groups, as well as the proportions of each demographic group in potentially many susceptibility groups. This is done in final size calculations by representing the relevant system of differential equations in matrix form. R’s matrix class allows us to easily represent multiple demographic groups with multiple susceptibility groups.

This guide explains how to construct susceptibility (susceptibility) and demography-in-susceptibility (p_susceptibility) matrices to represent various scenarios that we might wish to model when estimating epidemic final sizes.

New to finalsize? It may help to read the “Get started” vignette first!

## Use case

You need to create two matrices, susceptibility and p_susceptibility, to pass to the two arguments of the final_size() function. Here are five case examples with different scenarios for the content of each matrix.

### What we have

1. A scenario in which all individuals are equally susceptible to an infection; or,
2. A scenario in which older individuals are more susceptible to infection than younger individuals; or,
3. A scenario in which susceptibility increases with age, but older individuals benefit from immunization.

### What we assume

1. Complete partitioning of individuals into different demographic and susceptibility groups, i.e., that all individuals in the population fall into only one demographic group, and only one susceptibility group.

## Primer on susceptibility matrices

### Susceptibility matrix

Represents the probability of infection of each combination of demographic and infection-risk groups.

$i \; demographic \; groups \left.\vphantom{\begin{matrix} s_{1,1} & s_{1,2} & \cdots & s_{1,j} \\ s_{2,1} & s_{2,2} & \cdots & s_{2,j} \\ \vdots & \vdots & \ddots & \vdots \\ s_{i,1} & s_{i,2} & \cdots & s_{i,j} \end{matrix}}\right\{ \overbrace{ \begin{matrix} s_{1,1} & s_{1,2} & \cdots & s_{1,j} \\ s_{2,1} & s_{2,2} & \cdots & s_{2,j} \\ \vdots & \vdots & \ddots & \vdots \\ s_{i,1} & s_{i,2} & \cdots & s_{i,j} \end{matrix}}^j \; susceptibility \; groups} \quad s: susceptibility$

Each element $$\{i, j\}$$ in this matrix represents the susceptibility of individuals in demographic group $$\{i\}$$ (rows), and susceptibility group $$\{j\}$$ (columns).

A common example of a demographic group in a population is an age group, and each population is typically made up of multiple age groups.

Examples of infection-risk groups may include individuals of different immunization status, or with different prior exposure to pathogens. Final size calculations allow us to specify a different susceptibility to infection for each demography and risk group combination (e.g. fully vaccinated people over 65 years old).

### Demography-in-susceptibility matrix

Represents the proportion (or probability) that individuals in a demographic group are also in a specific susceptibility group.

$i \; demographic \; groups \left.\vphantom{\begin{matrix} p_{1,1} & p_{1,2} & \cdots & p_{1,j} \\ p_{2,1} & p_{2,2} & \cdots & p_{2,j} \\ \vdots & \vdots & \ddots & \vdots \\ p_{i,1} & p_{i,2} & \cdots & p_{i,j} \end{matrix}}\right\{ \overbrace{ \begin{matrix} p_{1,1} & p_{1,2} & \cdots & p_{1,j} \\ p_{2,1} & p_{2,2} & \cdots & p_{2,j} \\ \vdots & \vdots & \ddots & \vdots \\ p_{i,1} & p_{i,2} & \cdots & p_{i,j} \end{matrix}}^j \; susceptibility \; groups} \quad p: probability$

Each element $$\{i, j\}$$ in this matrix represents the proportion of each demographic group $$\{i\}$$ that falls into the susceptibility group $$\{j\}$$. Consequently, each of its rows must always sum to 1.0.

Here we share five case examples with different scenarios and how each influences the content and structure of the two matrices.

## Homogeneous susceptibility

Code
# load necessary packages
if (!require("dplyr")) install.packages("dplyr")
if (!require("tibble")) install.packages("tibble")

library(dplyr)
library(tibble)

### Case 1: Uniform susceptibility

This scenario assumes that all individuals from all age groups in the population of interest have 80% susceptibility to the infection.

Code
# susceptibility matrix
susceptibility <- tibble(
age_group = c("[0,5)", "[5,18)", "[18,40)", "[40,65)", "65+"),
susceptible = c(0.8, 0.8, 0.8, 0.8, 0.8)
) %>%
column_to_rownames(var = "age_group") %>%
as.matrix()

susceptibility
#>         susceptible
#> [0,5)           0.8
#> [5,18)          0.8
#> [18,40)         0.8
#> [40,65)         0.8
#> 65+             0.8

In this example, all individuals and age groups are equally susceptible to infection; thus, the susceptibility matrix (susceptibility) has only a single column with identical values.

Code
# demography-in-susceptibility matrix
p_susceptibility <- tibble(
age_group = c("[0,5)", "[5,18)", "[18,40)", "[40,65)", "65+"),
susceptible = c(1.0, 1.0, 1.0, 1.0, 1.0)
) %>%
column_to_rownames(var = "age_group") %>%
as.matrix()

p_susceptibility
#>         susceptible
#> [0,5)             1
#> [5,18)            1
#> [18,40)           1
#> [40,65)           1
#> 65+               1

The susceptibility matrix (susceptibility) and the demography-in-susceptibility matrix (p_susceptibility) must always have the same dimensions.

$4 \; demo. \; groups \left.\vphantom{\begin{matrix} s_{1,1} \\ s_{2,1} \\ s_{3,1} \\ s_{4,1} \end{matrix}}\right\{ \overbrace{ \begin{matrix} s_{1,1} \\ s_{2,1} \\ s_{3,1} \\ s_{4,1} \end{matrix}}^1 \; susceptibility \; group} \quad 4 \; demo. \; groups \left.\vphantom{\begin{matrix} p_{1,1} \\ p_{2,1} \\ p_{3,1} \\ p_{4,1} \end{matrix}}\right\{ \overbrace{ \begin{matrix} p_{1,1} \\ p_{2,1} \\ p_{3,1} \\ p_{4,1} \end{matrix}}^1 \; susceptibility \; group}$

## Heterogeneous susceptibility

### Case 2: Susceptibility varies between groups

This scenario assumes that, in the population, there is different susceptibility to the infection between individuals of different age groups, from 20% (infants) to 100% (65+).

Code
# susceptibility matrix
susceptibility <- tibble(
age_group = c("[0,5)", "[5,18)", "[18,40)", "[40,65)", "65+"),
susceptible = c(0.2, 0.5, 0.6, 0.9, 1.0)
) %>%
column_to_rownames(var = "age_group") %>%
as.matrix()

susceptibility
#>         susceptible
#> [0,5)           0.2
#> [5,18)          0.5
#> [18,40)         0.6
#> [40,65)         0.9
#> 65+             1.0

# demography-in-susceptibility matrix
p_susceptibility <- tibble(
age_group = c("[0,5)", "[5,18)", "[18,40)", "[40,65)", "65+"),
susceptible = c(1.0, 1.0, 1.0, 1.0, 1.0)
) %>%
column_to_rownames(var = "age_group") %>%
as.matrix()

p_susceptibility
#>         susceptible
#> [0,5)             1
#> [5,18)            1
#> [18,40)           1
#> [40,65)           1
#> 65+               1

### Case 3: Susceptibility varies both between and within groups

This scenario assumes that, in the population, there is different susceptibility to the infection:

• between individuals of different age groups from 20% (infants) to 100% (65+), and

• within individuals of the same age group due the immunization effect of 25% to the 40% of each of the age groups.

Code
immunization_effect <- 0.25

# susceptibility matrix
susceptibility <- tibble(
age_group = c("[0,5)", "[5,18)", "[18,40)", "[40,65)", "65+"),
unimmunised = c(0.2, 0.5, 0.6, 0.9, 1.0)
) %>%
mutate(immunised = unimmunised * (1 - immunization_effect)) %>%
column_to_rownames(var = "age_group") %>%
as.matrix()

susceptibility
#>         unimmunised immunised
#> [0,5)           0.2     0.150
#> [5,18)          0.5     0.375
#> [18,40)         0.6     0.450
#> [40,65)         0.9     0.675
#> 65+             1.0     0.750

# demography-in-susceptibility matrix
p_susceptibility <- tibble(
age_group = c("[0,5)", "[5,18)", "[18,40)", "[40,65)", "65+"),
immunised = c(0.4, 0.4, 0.4, 0.4, 0.4)
) %>%
mutate(unimmunised = 1 - immunised) %>%
column_to_rownames(var = "age_group") %>%
as.matrix()

p_susceptibility
#>         immunised unimmunised
#> [0,5)         0.4         0.6
#> [5,18)        0.4         0.6
#> [18,40)       0.4         0.6
#> [40,65)       0.4         0.6
#> 65+           0.4         0.6

Note that because there are two susceptibility groups, the susceptibility matrix has two columns. The corresponding demography-in-susceptibility matrix must also have two columns!

$4 \; demo. \; groups \left.\vphantom{\begin{matrix} s_{1,1} & s_{1,2} \\ s_{2,1} & s_{2,2} \\ s_{3,1} & s_{3,2} \\ s_{4,1} & s_{4,2} \end{matrix}}\right\{ \overbrace{ \begin{matrix} s_{1,1} & s_{1,2} \\ s_{2,1} & s_{2,2} \\ s_{3,1} & s_{3,2} \\ s_{4,1} & s_{4,2} \end{matrix}}^2 \; suscept. \; groups} \quad 4 \; demo. \; groups \left.\vphantom{\begin{matrix} p_{1,1} & p_{1,2} \\ p_{2,1} & p_{2,2} \\ p_{3,1} & p_{3,2} \\ p_{4,1} & p_{4,2} \end{matrix}}\right\{ \overbrace{ \begin{matrix} p_{1,1} & p_{1,2} \\ p_{2,1} & p_{2,2} \\ p_{3,1} & p_{3,2} \\ p_{4,1} & p_{4,2} \end{matrix}}^2 \; suscept. \; groups}$

### Case 4: Susceptibility varies within groups in different proportion

This scenario assumes that, in the population, there is different susceptibility to the infection:

• between individuals of different age groups from 20% (infants) to 100% (65+), and

• within individuals of the same age group due the immunization effect of 25%.

The immunization uptake rate is also different for each of the age groups: immunization increases with age from 20% (infants) to 90% (65+)

Code
immunization_effect <- 0.25

# susceptibility matrix
susceptibility <- tibble(
age_group = c("[0,5)", "[5,18)", "[18,40)", "[40,65)", "65+"),
unimmunised = c(0.2, 0.5, 0.6, 0.9, 1.0)
) %>%
mutate(immunised = unimmunised * (1 - immunization_effect)) %>%
column_to_rownames(var = "age_group") %>%
as.matrix()

susceptibility
#>         unimmunised immunised
#> [0,5)           0.2     0.150
#> [5,18)          0.5     0.375
#> [18,40)         0.6     0.450
#> [40,65)         0.9     0.675
#> 65+             1.0     0.750

# demography-in-susceptibility matrix
p_susceptibility <- tibble(
age_group = c("[0,5)", "[5,18)", "[18,40)", "[40,65)", "65+"),
immunised = c(0.2, 0.4, 0.6, 0.7, 0.9)
) %>%
mutate(unimmunised = 1 - immunised) %>%
column_to_rownames(var = "age_group") %>%
as.matrix()

p_susceptibility
#>         immunised unimmunised
#> [0,5)         0.2         0.8
#> [5,18)        0.4         0.6
#> [18,40)       0.6         0.4
#> [40,65)       0.7         0.3
#> 65+           0.9         0.1

### Case 5: Susceptibility varies within three groups

This scenario assumes that, in the population, there is different susceptibility to the infection:

• between individuals of different age groups from 20% (infants) to 100% (65+), and

• within individuals of the same age group due the immunization effect of 25% to the 40% of each of the age groups.

Additionally, 10% of individuals in each of the age groups have 100% susceptibility, due to no immunization or not exposed to similar pathogens previously.

Code
immunization_effect <- 0.25

# susceptibility matrix
susceptibility <- tibble(
age_group = c("[0,5)", "[5,18)", "[18,40)", "[40,65)", "65+"),
susceptible = c(1.0, 1.0, 1.0, 1.0, 1.0),
unimmunised = c(0.2, 0.5, 0.6, 0.9, 1.0)
) %>%
mutate(immunised = unimmunised * (1 - immunization_effect)) %>%
column_to_rownames(var = "age_group") %>%
as.matrix()

susceptibility
#>         susceptible unimmunised immunised
#> [0,5)             1         0.2     0.150
#> [5,18)            1         0.5     0.375
#> [18,40)           1         0.6     0.450
#> [40,65)           1         0.9     0.675
#> 65+               1         1.0     0.750

# demography-in-susceptibility matrix
p_susceptibility <- tibble(
age_group = c("[0,5)", "[5,18)", "[18,40)", "[40,65)", "65+"),
susceptible = c(0.1, 0.1, 0.1, 0.1, 0.1),
immunised = c(0.4, 0.4, 0.4, 0.4, 0.4)
) %>%
mutate(unimmunised = 1 - immunised - susceptible) %>%
column_to_rownames(var = "age_group") %>%
as.matrix()

p_susceptibility
#>         susceptible immunised unimmunised
#> [0,5)           0.1       0.4         0.5
#> [5,18)          0.1       0.4         0.5
#> [18,40)         0.1       0.4         0.5
#> [40,65)         0.1       0.4         0.5
#> 65+             0.1       0.4         0.5

Recall that in the demography-in-susceptibility matrix (p_susceptibility) each row must always sum to 1.0!

Miller, Joel C. 2012. “A Note on the Derivation of Epidemic Final Sizes.” Bulletin of Mathematical Biology 74 (9): 2125–41. https://doi.org/10.1007/s11538-012-9749-6.