Skip to content

socialmixr

0.7.0Package record

Social Mixing Matrices for Infectious Disease Modelling

1packages dependsuggested by 3
12.3Kdownloads / year
80.3%test coverage
13/13flavors OK

Overview

About

Methods for sampling contact matrices from diary data for use in infectious disease modelling, as discussed in Mossong et al. (2008) doi:10.1371/journal.pmed.0050074.

Changes in 0.7.0

New features

  • compute_matrix() gains a by argument that accepts any combination of participant/contact groupings, not just age. Each entry is either the string "age" (matching the columns produced by assign_age_groups()), a stem "<name>" (resolving to part_<name> and cnt_<name>), or an explicit c(part = "X", cnt = "Y") override. The result is a rank-2K array where the first K axes index participants and the last K index contacts. The default by = "age" reproduces the single-grouping behaviour of previous releases. split_matrix() currently still requires a single-grouping matrix (#143).
  • symmetrise() and per_capita() now accept multi-grouping matrices, with a single survey_pop format across all groupings. survey_pop is a data frame with one column per grouping, named after the grouping (e.g. age, gender) and holding that grouping's levels as they appear in the matrix, plus a population column, with one row per combination. Levels are matched exactly: there is no interpolation. symmetrise() additionally requires the participant- and contact-side dims to share the same levels, otherwise reciprocity is undefined and it aborts (#319).
Show all changes in 0.7.0Hide the rest of the changes in 0.7.0
  • New rebin_ages() rebins a population table to a coarser set of age groups by summing. It operates on an age column of age-group labels (as produced by limits_to_age_groups() or assign_age_groups()) and returns the same form, so it composes directly with the post-processing functions. It only coarsens: requesting age groups finer than the population data is an error, since splitting a band would require assuming a within-band age distribution.
  • New align_ages() aligns a population table to a contact matrix's groupings, returning the survey_pop data frame that symmetrise(), split_matrix() and per_capita() expect. Supply population with an age column of age-group label, plus a column per other grouping; align_ages() coarsens age to the matrix's age groups within each combination of the other groupings (via rebin_ages()) and aggregates categorical groupings by exact name. The population must be at least as fine as the matrix's age groups. A typical workflow is result |> symmetrise(survey_pop = align_ages(population, result)) (#319).
  • The contact_matrix S3 object now carries a groupings field — the list of grouping triples that produced its matrix. Used internally by the multi-grouping post-processing functions; users can read it to introspect the matrix's structure (#319).
  • New flatten() returns a T x T matrix view of a multi-grouping contact matrix — Manna et al.'s generalised representation, with colon-joined dim labels (e.g. "[0,5):F"). For single-grouping matrices it returns the matrix unchanged (#319).
  • plot() and as.matrix() now work on multi-grouping contact matrices, operating on the flattened T x T view. matrix_plot() no longer assumes a square matrix, so non-square flattened matrices plot correctly (#321).
  • New vignette, *Contact matrices across more than one grouping*, with recipes for building, flattening, plotting and post-processing matrices over several groupings (#322).
  • weigh() gains a new canonical target shape: a two-column data frame whose key column matches by is joined and multiplied into weight. This makes recipes like weigh(survey, "country", target = ...) natural. The previous silent dispatch on a population data frame (a target data frame with lower.age.limit/population and no column matching by) is soft-deprecated; use the new weigh_by_age() for the same effect with an explicit name. weigh_by_age() takes a reference population with an age column of age-group labels and a population column. New weigh_by_dayofweek() is a thin wrapper around the existing 5/2 split. weigh()'s named vector and groups paths are unchanged (#314).

Deprecations

  • Exported function names now spell "age groups" consistently as age_groups (snake_case), matching assign_age_groups(). reduce_agegroups(), limits_to_agegroups() and agegroups_to_limits() are renamed to reduce_age_groups(), limits_to_age_groups() and age_groups_to_limits(); the old names remain as deprecated aliases that warn (#331).
  • Interpolating population data to age groups finer than the data itself is deprecated. contact_matrix() (when it adjusts demographic data to the requested age groups) and pop_age() still do it but now warn, and it will error in a future release. Supply population data at least as fine as the requested age groups. The new rebin_ages() and align_ages() never interpolate: they error on finer requests.
  • pop_age() is deprecated in favour of rebin_ages() and warns; it will be removed in a future release (#328).
  • Advance deprecation cycle (#312). wpp_age(), wpp_countries(), and survey_country_population() are deprecated (warn) — all three are thin layers over wpp2017, which is on its way out. Construct a data.frame with columns lower.age.limit and population from a current source (e.g. the wpp2024 package from GitHub) and pass it to contact_matrix() via survey_pop instead. The implicit population lookup in contact_matrix() (when survey_pop is not given but symmetric, split, per_capita, weigh_age, or return_demography is set) keeps the warning introduced in 0.6.0 with a sharper "will error in a future release" message. wpp2017 remains in Imports for now, so this lookup keeps working; it will move to Suggests in a later release once reverse dependencies have migrated. The following are now defunct (deprecate_stop): survey(), check(), get_survey(), download_survey(), list_surveys(), survey_countries(), get_citation(), and the missing_contact_age = "sample" option on assign_age_groups() and contact_matrix(). The dotted argument names (age.limits, survey.pop, country.column, etc.) on contact_matrix(), pop_age(), clean(), and as_contact_survey() remain deprecated and warn, rather than becoming defunct, so downstream packages still using them keep working while they migrate. Bogus "1.0.0" versions on the survey() and check() deprecation messages have been corrected.

Bug fixes

  • load_survey() now errors clearly when given no files (e.g. an empty vector or NULL from a failed download) instead of raising an opaque invalid 'file' argument.

Internal

  • Removed the air formatter: air.toml, the style.yaml format-suggestion workflow, and the VS Code formatter settings. lintr continues to run on changed files, and indentation_linter is re-enabled (with a hanging-indent style) to keep linting indentation now that air no longer handles it.

From NEWS.md in the release

Install

Health

CRAN checks
13OK
Slowest check: 4.3 min · r-oldrel-macos-x86_64
Status changes
  • OK13 OK2026-08-04
  • NOTE12 OK, 1 NOTE2026-08-01
  • OK14 OK2026-03-10
Advisories

none known

Documentation

In release 0.7.0
READMEYes · 256 wordsVignettesYes · 3 · dynamicNEWSYes · 100% structured · mentions 0.7.0Citation fileNoWebsiteYes · pkgdown
Help pages
68 (37 internal)
Examples that run
75%21 run in a plain check (3 of them under a condition) · 7 never run
Exported functions with examples
84%
Documented parameters
94%
Return-value docs
97%
Help pages citing references
1%

Downloads

12.3K
CRAN downloads in the past year
Rank #3,689 · ~34/day · ~1K/mo
Daily download trend is not available in this view yet.
84530 days
2.6K90 days
12.3K1 year
Compare downloads with other packages →
Also on161 r2u7 autocran75 c2d4u

Repository

44Stars
14Forks
1Open issues
0Open PRs
10Releases
719Commits
17Commit identities
rr-package
719 commits · Last activity 2026-09-28 · 0% stars, 30d · Default branch at 0.7.0.9000, ahead of CRAN 0.7.0 (checked 2026-10-11)
Responsiveness
How these are sampled
PRs merged (all time)
90%
Median days to close, 50 most recently updated closed issues
30
Median days to close, 50 most recently updated closed PRs
1

Stars over time

2025-10-02 · 412026-07-07 · 44
PracticesBeta

15 development-tooling and community-health practices detected across 8 families in the upstream repository

Checks run against github.com/epiforecasts/socialmixr on 2026-10-11.

Continuous integration (3)
GitHub ActionsR CMD check workflowTravis CI (config file)

The R CMD check workflow runs on Linux, macOS and Windows, and on R-devel

Governance and community (1)
Code of conduct (inherited from epiforecasts)
Docs source (4)
README.Rmdpkgdown

GitHub Pages site last deployed 2026-09-28 · The repository has a site deploy workflow

pkgdown site last built 2026-09-28

Coverage (1)
Coverage reporting (Codecov)
Show all practicesHide 4 practices
Reproducibility and dev environment (1)
data-raw/
CRAN release process (1)
cran-comments.md
Automation and maintenance (1)
Dependabot
Lint, format, editor (3)
lintrLint workflowRStudio project
How this is detected·Detection ruleset v3 (2026-09-26)
AI coding toolsBeta

This repository shows signs of AI coding tools.

  • Claude Codefirst seen 2025-12-05
    Seen in the repository: CLAUDE.md
    Named in .Rbuildignore: .claude, CLAUDE.local.md, CLAUDE.md
    Named in .gitignore: CLAUDE.local.md
    Pull request it wrote: opened by a project member
Shared conventions any agent may read, so they name no particular tool.
Seen in the repository: AGENTS.md
Review tools
  • CodeRabbit
    Seen in the repository: .coderabbit.yaml
    Named in .Rbuildignore: .coderabbit.yaml
How this is detected·Detection ruleset v4 (updated 2026-09-27)

Dependencies

Declared dependencies
25 external dependencies (excludes base and recommended)

Installing socialmixr adds 37 packages (25 with compiled code, 33 MB of source tarballs). Heaviest: stringi 11 MB, data.table 5.7 MB, wpp2017 4.5 MB.

Depends (1)
R >= 4.1.0
LinkingTo (0)
none
Enhances (0)
none
Reverse dependencies
1direct
0indirect
Imports 1
Suggested by 3
Depends, Imports or LinkingTo, most downloaded first
Suggests, most downloaded first

Datasets

People & History

People (12)
Author, Maintainer since 0.1.0 (2018)
Author · added in 0.3.0
Author · added in 0.5.1
Author · added in 0.2.0
Contributor · added in 0.1.7
Contributor · added in 0.5.0
Contributor · added in 0.1.7
Contributor · added in 0.2.0
Contributor · added in 0.1.7
Contributor · added in 0.1.7
Contributor · added in 0.1.7
col, dtm · added in 0.2.0
Releases (18)

Pick two releases to compare their code metrics.

  • 0.7.0Latest
    record
    2026-04-29 · current release · diff ↗ ·
    added 8 exports
    age_groups_to_limits, align_ages, flatten, limits_to_age_groups, rebin_ages, reduce_age_groups, weigh_by_age, weigh_by_dayofweek
  • 0.6.0
    record
    2026-04-29 · diff ↗ ·
    added 7 exports
    agegroups_to_limits, compute_matrix, contact_age_distribution, per_capita, split_matrix, symmetrise, weigh
  • R
    R 4.6.0 released · 2026-04-24
  • 0.5.1
    record
    2026-02-04 · diff ↗
  • 0.5.0
    record
    2026-01-19 · diff ↗ ·
    added 3 exports
    as_contact_survey, assign_age_groups, survey_country_population
  • R
    R 4.5.0 released · 2025-04-11
  • 0.4.0
    record
    2024-10-18 · diff ↗ ·
    removed 1 export
    cite
  • R
    R 4.4.0 released · 2024-04-24
  • 0.3.2
    record
    2024-04-18 · diff ↗
  • 0.3.1
    record
    2023-10-26 · diff ↗
  • 0.3.0
    record
    2023-10-18 · diff ↗ ·
    added 1 export
    get_citation
  • R
    R 4.3.0 released · 2023-04-21
  • 0.2.0
    record
    2022-10-27 · diff ↗ ·
    added 3 exports
    download_survey, load_survey, matrix_plot
  • R
    R 4.2.0 released · 2022-04-22
  • R
    R 4.1.0 released · 2021-05-18
  • 0.1.8
    record
    2020-11-14 · diff ↗
Show 12 earlier eventsHide 12 earlier events

Package metadata

First published
2018-01-08
Total releases
18 / 8 yrs
License
MIT + file LICENSE OSI · relicensed from GPL-3 in 0.2.0
Minimum R
≥ 4.1.0
Bundled data
364 KB / 1 file
Download size
604 KB
Appears in task views

Cite

Cite this package

Run in R for the authors' preferred citation:

citation("socialmixr")
Funk, S., Bekker-Nielsen Dunbar, M., Chapman, L., Clifford, S., Coletti, P., Gruson, H., Hens, N., Jarvis, C., Pearson, C. A. B., Robert, A., Tierney, N., & Willem, L. (2026). socialmixr: Social Mixing Matrices for Infectious Disease Modelling (Version 0.7.0) [Computer software]. https://doi.org/10.32614/CRAN.package.socialmixr

This package has no citation file, so citation() returns this entry built from DESCRIPTION.

Cite the R Observatory

For a number measured here: a download total, a coverage figure, an archival date.

APA

Balamuta, J. J. (2026). R Observatory: Metrics for socialmixr version 0.7.0 [Data set]. HJJB, LLC. Data release v2026-10-18. https://doi.org/10.5281/zenodo.21843040

From data release v2026-10-18, which the citation names so these numbers can be found later. More on citing and the projects behind them.

Report a problem with this page →

Privacy choices

These apply to this browser and are stored on this device only. Nothing about your choice is sent to us.

Read the privacy policy