Learn R Programming

serofoi: force-of-infection from population based serosurveys with age-disaggregated data

serofoi is an R package to estimate the Force-of-Infection (FoI) of a given pathogen from age-disaggregated population-based cross-sectional serosurveys, using a Bayesian framework. The package provides a set of features for assessing model fitting, convergence and visualisation.

serofoi relies on the rstan package, which provides an R interface for the Stan programming language for statistical Bayesian modelling. Particularly, serofoi relies on the use of a Hamiltonian Monte Carlo (HMC) algorithm implemented by Stan for Markov chain Monte Carlo (MCMC) sampling. The implemented methods are outlined in (Cucunubá et al. 2017) and (Carrera et al. 2020) (see FoI Models for further details). A compelling mathematical treatment of the implemented serocatalytic models can be found in (Kamau et al. 2025).

serofoi is part of the Epiverse Initiative.

Installation

You can install serofoi from CRAN using:

install.packages("serofoi")

You can install the development version of serofoi from GitHub running:

if(!require("pak")) install.packages("pak")
pak::pak("epiverse-trace/serofoi")

or:

if(!require("remotes")) install.packages("remotes")
remotes::install_github("epiverse-trace/serofoi")

Quick start

serofoi provides some minimal serosurvey datasets that can be used to test out the package. For instance, the dataset chagas2012 contains seroprevalence measures of IgG antibodies against Trypanosoma cruzi infection corresponding to a serological survey conducted in Colombia during 2012 on a rural indigenous community that is known to present long-term endemic transmission

# Load example dataset chagas2012 included with the package
data(chagas2012)
head(chagas2012, 5)
#>   survey_year n_sample n_seropositive age_min age_max
#> 1        2012       34              0       1       1
#> 2        2012       25              0       2       2
#> 3        2012       35              1       3       3
#> 4        2012       29              0       4       4
#> 5        2012       36              0       5       5

A visualisation of the serological data can be obtained using the function plot_serosurvey:

plot_serosurvey(chagas2012, bin_serosurvey = TRUE, size_text = 15)

Here, the error bars correspond to the binomial confidence interval and the point size represents the sample size for each age group.

A constant FoI model can easily be implemented by means of fit_seromodel:

seromodel <- fit_seromodel(serosurvey = chagas2012)

For further details on how to visualise the results and other available models, please refer to the online documentation.

Contributions

Contributors to the project include:

Package vignettes

More details on how to use serofoi can be found in the online documentation as package vignettes, under “Articles”.

Help

To report a bug please open an issue.

Contribute

Contributions to serofoi are welcomed. Please follow the package contributing guide.

Code of conduct

Please note that the serofoi project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

References

Carrera, Jean-Paul, Zulma M. Cucunubá, Karen Neira, Ben Lambert, Yaneth Pittí, Jesus Liscano, Jorge L. Garzón, et al. 2020. “Endemic and Epidemic Human Alphavirus Infections in Eastern Panama: An Analysis of Population-Based Cross-Sectional Surveys.” The American Journal of Tropical Medicine and Hygiene 103 (6): 2429–37. https://doi.org/10.4269/ajtmh.20-0408.

Cucunubá, Zulma M, Pierre Nouvellet, Lesong Conteh, Mauricio Javier Vera, Victor Manuel Angulo, Juan Carlos Dib, Gabriel Jaime Parra -Henao, and María Gloria Basáñez. 2017. “Modelling Historical Changes in the Force-of-Infection of Chagas Disease to Inform Control and Elimination Programmes: Application in Colombia.” BMJ Global Health 2 (3): e000345. https://doi.org/10.1136/bmjgh-2017-000345.

Kamau, Everlyn, Junjie Chen, Sumali Bajaj, Nicolas Torres, Richard Creswell, Jaime A Pavlich-Mariscal, Christl Donnelly, Zulma Cucunuba, and Ben Lambert. 2025. “The Mathematics of Serocatalytic Models with Applications to Public Health Data.” medRxiv, 2025–01.

Copy Link

Version

Install

install.packages('serofoi')

Monthly Downloads

189

Version

1.0.3

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Zulma M. Cucunubá

Last Published

March 31st, 2025

Functions in serofoi (1.0.3)

simulate_serosurvey_time

Simulate serosurvey data based on a time-varying Force-of-Infection (FoI) model.
serofoi-package

The 'serofoi' package.
validate_plot_constant

Helper function to validate whether the current plot corresponds to a constant model
prob_seroprev_age_by_age

Generate probabilities of seropositivity by age based on an age-varying Force-of-Infection (FoI) model.
plot_rhats

Plot r-hats convergence criteria for the specified model
prob_seroprev_by_age

Generate probabilities of seropositivity by age based on model choice.
plot_seroprev_estimates

Plot seroprevalence estimates on top of the serosurvey
plot_summary

Plots model summary
prepare_serosurvey_for_plot

Prepares serosurvey for plotting
set_foi_init

Sets initialization function for sampling
probability_exact_time_varying

Computes the probability of being seropositive when Forces-of-Infection (FoIs) vary by time
validate_foi_df

Helper function to validate FoI structure for simulation
validate_foi_index

Helper function to validate FoI index consistency
validate_simulation_age_time

Helper function to validate consistency between the FoI and the survey features for simulation of age- and time-varying model
summarise_central_estimate

Summarise central estimate
sf_cauchy

Sets Cauchy distribution parameters for sampling
sf_none

Sets empty prior distribution
simulate_serosurvey_age_time

Simulate serosurvey data based on an age-and-time-varying Force-of-Infection (FoI) model.
simulate_serosurvey_general

Simulate serosurvey data based on general serocatalytic model.
validate_survey_features

Helper function to validate serosurvey features for simulation
sf_normal

Sets normal distribution parameters for sampling
veev2012

Venezuelan Equine Encephalitis Virus (VEEV) seroprevalence data in serofoi
validate_seroreversion_rate

Helper function to validate seroreversion rate properties for simulation
set_stan_data_defaults

Set stan data defaults for sampling
summarise_seromodel

Summarise specified model
sf_uniform

Sets uniform distribution parameters for sampling
summarise_loo_estimate

Extract specified loo estimate
validate_serosurvey

Helper function to validate serosurvey structure
prob_seroprev_time_by_age

Generate probabilities of seropositivity by age based on a time-varying Force-of-Infection (FoI) model.
probability_exact_age_varying

Computes the probability of being seropositive when Forces-of-Infection (FoIs) vary by age
validate_simulation_age

Helper function to validate consistency between the FoI and the survey features for simulation
simulate_serosurvey_age

Simulate serosurvey data based on an age-varying Force-of-Infection (FoI) model.
simulate_serosurvey

Simulate serosurvey data based on various Force-of-Infection (FoI) models.
get_seroprev_counts_by_bin

Generate seropositivity counts by bin given the probability and sample size per age group bin
extract_central_estimates

Extracts central estimates from stan_fit object for specified parameter
add_age_group_to_serosurvey

Adds age group marker to serosurvey
fit_seromodel

Runs specified stan model for the Force-of-Infection (FoI)
plot_foi_estimates

Plots Force-of-Infection central estimates
get_foi_index

Generates Force-of-Infection indexes for heterogeneous age groups
build_stan_data

Builds stan data for sampling depending on the selected model
plot_serosurvey

Plots seroprevalence from the given serosurvey
prob_seroprev_age_time_by_age

Generate probabilities of seropositivity by age based on an age-and-time varying Force-of-Infection (FoI) model.
prob_seroprev_gen_by_age

Generate probabilities of seropositivity by age based on a general Force-of-Infection (FoI) model.
chik2015

Chikungunya seroprevalence data in serofoi
chagas2012

Chagas seroprevalence data in serofoi
check_age_constraints

Check min and max age consistency for validation purposes
plot_seromodel

Visualise results of the provided model