epiverse-trace / epiverse-trace/tutorials-late
replace `socialmixr::contact_matrix()` with piped `socialmixr::symmetrise()`
- Dominant language
- R
- Stars
- 2
- Forks
- 5
- Avg merge
- 4m
- Merged PRs (30d)
- 2
Description
**Is your feature request related to a problem? Please describe.**
similar to #152, to replace `socialmixr::contact_matrix()` with a full transition to the piped workflow by latest `{socialmixr}` after https://github.com/epiforecasts/socialmixr/issues/330
**Describe the solution you'd like**
``` r
library(socialmixr)
library(magrittr)
library(wpp2024)
data("popAge1dt")
uk_demo <- popAge1dt %>%
dplyr::filter(name == "United Kingdom", year == max(year)) %>%
dplyr::transmute(age = socialmixr::limits_to_age_groups(x = age), population = pop * 1000) %>%
socialmixr::rebin_ages(age_limits = c(0, 20, 40))
contact_data3 <- polymod[country == "United Kingdom"] %>%
socialmixr::assign_age_groups(age_limits = c(0, 20, 40)) %>%
socialmixr::compute_matrix() %>%
socialmixr::symmetrise(survey_pop = uk_demo)
contact_matrix3 <- contact_data3$matrix
demography_vector3 <- uk_demo$population
names(demography_vector3) <- rownames(contact_matrix3)
contact_matrix3
#> contact.age.group
#> age.group [0,20) [20,40) [40,Inf)
#> [0,20) 7.883663 3.105519 3.290997
#> [20,40) 2.806513 4.854839 4.986325
#> [40,Inf) 1.488256 2.495156 5.005571
demography_vector3
#> [0,20) [20,40) [40,Inf)
#> 15962345 17662976 35297722
```
Created on 2026-08-21 with [reprex v2.1.1](https://reprex.tidyverse.org)
**Additional context**
Add any other context or screenshots about the feature request here.
Contributor guide
Research direction
Search the tutorials for uses of socialmixr::contact_matrix() and read the surrounding workflow before changing them. Apply the piped assign_age_groups(), compute_matrix(), and symmetrise() sequence shown in the issue, then verify that the resulting contact matrix and demography vector match the demonstrated outputs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100