# Introduction to socialmixr In socialmixr: Social Mixing Matrices for Infectious Disease Modelling

library('knitr')
mr <- Reduce("+", lapply(m$matrices, function(x) {x$matrix})) / length(m$matrices) mr  # Demography Obtaining symmetric contact matrices or splitting out their components (see below) requires information about the underlying demographic composition of the survey population. This can be passed to contact_matrix as the survey.pop argument, a data.frame with two columns, lower.age.limit (denoting the lower end of the age groups) and population (denoting the number of people in each age group). If no survey.pop is not given, contact_matrix will try to obtain the age structure of the population (as per the countries argument) from the World Population Prospects of the United Nations, using estimates from the year that closest matches the year in which the contact survey was conducted. If demographic information is used, this is returned by contact_matrix as the demography field in the results list. # Symmetric contact matrices Conceivably, contact matrices should be symmetric: the total number of contacts made by members of one age group with those of another should be the same as vice versa. Mathematically, if$c_{ij}$is the mean number of contacts made by members of age group$i$with members of age group$j$, and the total number of people in age group$i$is$N_i$, then $$c_{ij} N_i = c_{ji}N_j$$ Because of variation in the sample from which the contact matrix is obtained, this relationship is usually not fulfilled exactly. In order to obtain a symmetric contact matrix that fulfills it, one can use $$c'_{ij} = \frac{1}{2N_i} (c_ij N_i + c_ji N_j)$$ To get this version of the contact matrix, use symmetric = TRUE when calling the contact_matrix function. contact_matrix(polymod, countries = "United Kingdom", age.limits = c(0, 1, 5, 15), symmetric = TRUE)  # Splitting contact matrices The contact_matrix contains a simple model for the elements of the contact matrix, by which it is split into a global component, as well as three components representing contacts, assortativity and demography. In other words, the elements$c_{ij}$of the contact matrix are modelled as $$c_{ij} = q d_i a_{ij} n_j$$ where$q d_i$is the number of contacts that a member of group$i$makes across age groups,$n_j$is the proportion of the surveyed population in age group$j$. The constant$q$is set to the value of the largest eigenvalue of$c_{ij}$; if used in an infectious disease model, it can be replaced by the basic reproduction number$R_0$. To model the contact matrix in this way with the contact_matrix function, set split = TRUE. The components of the matrix are returned as elements normalisation ($q$), contacts ($d_i$), matrix ($a_{ij}$) and demography ($n_j\$) of the resulting list.

contact_matrix(polymod, countries = "United Kingdom", age.limits = c(0, 1, 5, 15), split = TRUE)


# Plotting

The contact matrices can be plotted, for example, using the geom_tile function of the ggplot2 package.

library('reshape2')
library('ggplot2')
df <- melt(mr, varnames = c("age1", "age2"), value.name = "contacts")
ggplot(df, aes(x = age2, y = age1, fill = contacts)) + theme(legend.position="bottom") + geom_tile()


## Try the socialmixr package in your browser

Any scripts or data that you put into this service are public.

socialmixr documentation built on Jan. 11, 2020, 9:31 a.m.