generated from epiverse-trace/packagetemplate
-
Notifications
You must be signed in to change notification settings - Fork 1
Add weighted sampling for sex of contacts and cases #255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
joshwlambert
wants to merge
9
commits into
main
Choose a base branch
from
sex_sampling
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
avallecam
approved these changes
Nov 24, 2025
Member
avallecam
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @joshwlambert just run this reprex to test it. think it is ready to merge 🚀
# pak::pak("epiverse-trace/simulist@sex_sampling")
library(simulist)
library(magrittr)
sessioninfo::package_info(pkgs = "attached")
#> package * version date (UTC) lib source
#> magrittr * 2.0.3 2022-03-30 [1] RSPM
#> simulist * 0.6.0 2025-11-24 [1] Github (epiverse-trace/simulist@4b81aea)
#>
#> [1] C:/Users/AndreeValleCampos/Documents/0projects/epicatador/renv/library/windows/R-4.5/x86_64-w64-mingw32
#> [2] C:/Users/AndreeValleCampos/AppData/Local/R/cache/R/renv/sandbox/windows/R-4.5/x86_64-w64-mingw32/0eea1ca5
#> [3] C:/Program Files/R/R-4.5.1/library
#> * ── Packages attached to the search path.
set.seed(1)
sim_data <- simulist::sim_linelist(
outbreak_size = c(1000, 1500),
config = simulist::create_config(prob_male = 0.2)
) %>%
dplyr::as_tibble()
#> Warning: Number of cases exceeds maximum outbreak size.
#> Returning data early with 1546 cases and 3059 total contacts (including cases).
sim_data %>%
dplyr::count(sex)
#> # A tibble: 2 × 2
#> sex n
#> <chr> <int>
#> 1 f 1261
#> 2 m 285
out <- sim_data %>%
incidence2::incidence(
date_index = "date_onset",
interval = "day",
groups = "sex"
)
incidence2::estimate_peak(x = out)
#> # A tibble: 2 × 8
#> sex count_variable observed_peak observed_count bootstrap_peaks lower_ci
#> <chr> <chr> <date> <int> <list> <date>
#> 1 f date_onset 2023-05-01 18 <df [100 × 1]> 2023-03-24
#> 2 m date_onset 2023-04-18 5 <df [100 × 1]> 2023-02-17
#> # ℹ 2 more variables: median <date>, upper_ci <date>Created on 2025-11-24 with reprex v2.1.1
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR addresses #252 by adding the ability for users to specify the probability of sampling male and female contacts and cases using the new
prob_maleoption increate_config(). Theconfiglist is used in.sim_internal()to sample the sex of each contact.The default (
prob_male = 0.5) is backwards compatible, however, because theprobargument is now specified forsample()it changes the random number chain meaning that the output is different for line list or contact tracing data that is sampled after sex (e.g. age, name, case type, etc.).Unit tests are added to ensure the simulation errors as expected when$\geq$ 1 or $\leq$ 0. Due to the change in the random number generation chain the snapshots for
prob_malesim_linelist(),sim_contacts()andsim_outbreak()have all be updated.