
# Social mixing matrices for infectious disease modelling in R

<!-- badges: start -->

[![CRAN
version](https://www.r-pkg.org/badges/version-ago/socialmixr)](https://cran.r-project.org/package=socialmixr)
[![R-CMD-check](https://github.com/epiforecasts/socialmixr/workflows/R-CMD-check/badge.svg)](https://github.com/epiforecasts/socialmixr/actions)
[![Codecov test
coverage](https://codecov.io/gh/epiforecasts/socialmixr/graph/badge.svg)](https://app.codecov.io/gh/epiforecasts/socialmixr)
<!-- badges: end -->

[socialmixr](https://github.com/epiforecasts/socialmixr) is an `R`
package to derive social mixing matrices from survey data.

# Installation

The package can be installed using

``` r
install.packages("socialmixr")
```

The current development version can be installed using the `remotes`
package

``` r
remotes::install_github("epiforecasts/socialmixr")
```

# Usage

Contact matrices are computed through a small pipeline of composable
functions: subsetting the survey, assigning age groups, optionally
weighing participants, and computing the matrix. A minimal example using
the included POLYMOD data:

``` r
library(socialmixr)
data(polymod)

polymod[country == "United Kingdom"] |>
  assign_age_groups(age_limits = c(0, 1, 5, 15)) |>
  compute_matrix()
```

Post-processing functions `symmetrise()`, `split_matrix()` and
`per_capita()` can be piped after `compute_matrix()` to enforce
symmetry, decompose the matrix, or convert to per-capita contact rates.

# Documentation

For more on how to use the socialmixr package, see the [introduction
vignette](https://epiforecasts.io/socialmixr/articles/socialmixr.html).

## Contributors

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->

All contributions to this project are gratefully acknowledged using the
[`allcontributors` package](https://github.com/ropensci/allcontributors)
following the [allcontributors](https://allcontributors.org)
specification. Contributions of any kind are welcome!

### Code

<a href="https://github.com/epiforecasts/socialmixr/commits?author=sbfnk">sbfnk</a>,
<a href="https://github.com/epiforecasts/socialmixr/commits?author=Bisaloo">Bisaloo</a>,
<a href="https://github.com/epiforecasts/socialmixr/commits?author=lwillem">lwillem</a>,
<a href="https://github.com/epiforecasts/socialmixr/commits?author=njtierney">njtierney</a>,
<a href="https://github.com/epiforecasts/socialmixr/commits?author=alxsrobert">alxsrobert</a>,
<a href="https://github.com/epiforecasts/socialmixr/commits?author=Degoot-AM">Degoot-AM</a>,
<a href="https://github.com/epiforecasts/socialmixr/commits?author=pearsonca">pearsonca</a>,
<a href="https://github.com/epiforecasts/socialmixr/commits?author=jarvisc1">jarvisc1</a>,
<a href="https://github.com/epiforecasts/socialmixr/commits?author=jamesmbaazam">jamesmbaazam</a>,
<a href="https://github.com/epiforecasts/socialmixr/commits?author=LloydChapman">LloydChapman</a>,
<a href="https://github.com/epiforecasts/socialmixr/commits?author=mariabnd">mariabnd</a>,
<a href="https://github.com/epiforecasts/socialmixr/commits?author=ukhsa-tt">ukhsa-tt</a>

### Issue Authors

<a href="https://github.com/epiforecasts/socialmixr/issues?q=is%3Aissue+author%3Abastistician">bastistician</a>,
<a href="https://github.com/epiforecasts/socialmixr/issues?q=is%3Aissue+author%3ABlackEdder">BlackEdder</a>,
<a href="https://github.com/epiforecasts/socialmixr/issues?q=is%3Aissue+author%3APinzo1">Pinzo1</a>,
<a href="https://github.com/epiforecasts/socialmixr/issues?q=is%3Aissue+author%3Aflorpi">florpi</a>,
<a href="https://github.com/epiforecasts/socialmixr/issues?q=is%3Aissue+author%3Acchauve">cchauve</a>,
<a href="https://github.com/epiforecasts/socialmixr/issues?q=is%3Aissue+author%3Athutran">thutran</a>,
<a href="https://github.com/epiforecasts/socialmixr/issues?q=is%3Aissue+author%3Adlaydon">dlaydon</a>,
<a href="https://github.com/epiforecasts/socialmixr/issues?q=is%3Aissue+author%3Adeusthindwa">deusthindwa</a>,
<a href="https://github.com/epiforecasts/socialmixr/issues?q=is%3Aissue+author%3Akrivit">krivit</a>,
<a href="https://github.com/epiforecasts/socialmixr/issues?q=is%3Aissue+author%3Alinyang17">linyang17</a>,
<a href="https://github.com/epiforecasts/socialmixr/issues?q=is%3Aissue+author%3Acliu822">cliu822</a>,
<a href="https://github.com/epiforecasts/socialmixr/issues?q=is%3Aissue+author%3ATimTaylor">TimTaylor</a>,
<a href="https://github.com/epiforecasts/socialmixr/issues?q=is%3Aissue+author%3ANaomiWaterlow">NaomiWaterlow</a>,
<a href="https://github.com/epiforecasts/socialmixr/issues?q=is%3Aissue+author%3Aaakhmetz">aakhmetz</a>,
<a href="https://github.com/epiforecasts/socialmixr/issues?q=is%3Aissue+author%3Aadamkucharski">adamkucharski</a>,
<a href="https://github.com/epiforecasts/socialmixr/issues?q=is%3Aissue+author%3Achitrams">chitrams</a>,
<a href="https://github.com/epiforecasts/socialmixr/issues?q=is%3Aissue+author%3AIsaacStopard">IsaacStopard</a>,
<a href="https://github.com/epiforecasts/socialmixr/issues?q=is%3Aissue+author%3Aavallecam">avallecam</a>,
<a href="https://github.com/epiforecasts/socialmixr/issues?q=is%3Aissue+author%3Amaishaoshao">maishaoshao</a>,
<a href="https://github.com/epiforecasts/socialmixr/issues?q=is%3Aissue+author%3AFrancescoBonacina">FrancescoBonacina</a>,
<a href="https://github.com/epiforecasts/socialmixr/issues?q=is%3Aissue+author%3Alucy-gf">lucy-gf</a>

### Issue Contributors

<a href="https://github.com/epiforecasts/socialmixr/issues?q=is%3Aissue+commenter%3Avikkytom">vikkytom</a>,
<a href="https://github.com/epiforecasts/socialmixr/issues?q=is%3Aissue+commenter%3Abahadzie">bahadzie</a>,
<a href="https://github.com/epiforecasts/socialmixr/issues?q=is%3Aissue+commenter%3Ajoshwlambert">joshwlambert</a>

<!-- markdownlint-enable -->
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->
