Code Monkey home page Code Monkey logo

finalsize's Introduction

finalsize: Calculate the final size of an epidemic

Digital Public Good License: MIT Project Status: Active – The project has reached a stable, usable state and is being actively developed. R-CMD-check Codecov test coverage CRAN status

finalsize is an R package to calculate the final size of a SIR epidemic in populations with heterogeneity in social contacts and infection susceptibility.

finalsize provides estimates for the total proportion of a population infected over the course of an epidemic, and can account for a demographic distribution (such as age groups) and demography-specific contact patterns, as well as for heterogeneous susceptibility to infection between groups (such as due to age-group specific immune responses) and within groups (such as due to immunisation programs). An advantage of this approach is that it requires fewer parameters to be defined compared to a model that simulates the full transmission dynamics over time, such as models in the epidemics package.

finalsize implements methods outlined in Andreasen (2011), Miller (2012), Kucharski et al. (2014), and Bidari et al. (2016).

finalsize can help provide rough estimates of the effectiveness of pharmaceutical interventions in the form of immunisation programmes, or the effect of naturally acquired immunity through previous infection (see the vignette).

finalsize relies on Eigen via RcppEigen for fast matrix algebra, and is developed at the Centre for the Mathematical Modelling of Infectious Diseases at the London School of Hygiene and Tropical Medicine as part of the Epiverse-TRACE.

Installation

The package can be installed from CRAN using

install.packages("finalsize")

Development version

The current development version of finalsize can be installed from Github using the remotes package. The development version documentation can be found here.

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

Quick start

The main function in finalsize is final_size(), which calculates the final size of an epidemic given the $R_0$.

# load finalsize
library(finalsize)

final_size(1.5)
#>     demo_grp   susc_grp susceptibility p_infected
#> 1 demo_grp_1 susc_grp_1              1  0.5828132

Optionally, final_size() can estimate the epidemic size for populations with differences among demographic groups in their social contact patterns, in their susceptibility to infection.

We can use social contact data (here, from the socialmixr package) to estimate the final size of an epidemic when the disease has an R0 of 1.5, and given three age groups of interest — 0-19, 20-39 and 40+. The under-20 age group is assumed to be fully susceptible to the disease, whereas individuals aged over 20 are only half as susceptible as those under 20.

# Load example POLYMOD social contacts data included with the package
data(polymod_uk)

# Define contact matrix (entry {ij} is contacts in group i reported by group j)
contact_matrix <- polymod_uk$contact_matrix

# Define population in each age group
demography_vector <- polymod_uk$demography_vector

# Define susceptibility of each group
susceptibility <- matrix(
  data = c(1.0, 0.5, 0.5),
  nrow = length(demography_vector),
  ncol = 1
)

# Assume uniform susceptibility within age groups
p_susceptibility <- matrix(
  data = 1.0,
  nrow = length(demography_vector),
  ncol = 1
)

# R0 of the disease
r0 <- 1.5 # assumed for pandemic influenza

# Calculate the proportion of individuals infected in each age group
final_size(
  r0 = r0,
  contact_matrix = contact_matrix,
  demography_vector = demography_vector,
  susceptibility = susceptibility,
  p_susceptibility = p_susceptibility
)
#>   demo_grp   susc_grp susceptibility p_infected
#> 1   [0,20) susc_grp_1            1.0 0.32849966
#> 2  [20,40) susc_grp_1            0.5 0.10532481
#> 3      40+ susc_grp_1            0.5 0.06995193

Helper functions included in finalsize are provided to calculate the effective $R_0$, called $R_{eff}$, from demographic and susceptibility distribution data, while other helpers can convert between $R_0$ and the transmission rate $\lambda$.

# calculate the effective R0 using `r_eff()`
r_eff(
  r0 = r0,
  contact_matrix = contact_matrix,
  demography_vector = demography_vector,
  susceptibility = susceptibility,
  p_susceptibility = p_susceptibility
)
#> [1] 1.171758

Package vignettes

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

Help

To report a bug please open an issue.

Contribute

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

Code of conduct

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

Citing this package

citation("finalsize")
#> To cite package 'finalsize' in publications use:
#> 
#>   Gupte P, Van Leeuwen E, Kucharski A (2024). _finalsize: Calculate the
#>   Final Size of an Epidemic_. R package version 0.2.1,
#>   https://epiverse-trace.github.io/finalsize/,
#>   <https://github.com/epiverse-trace/finalsize>.
#> 
#> A BibTeX entry for LaTeX users is
#> 
#>   @Manual{,
#>     title = {finalsize: Calculate the Final Size of an Epidemic},
#>     author = {Pratik Gupte and Edwin {Van Leeuwen} and Adam Kucharski},
#>     year = {2024},
#>     note = {R package version 0.2.1, 
#> https://epiverse-trace.github.io/finalsize/},
#>     url = {https://github.com/epiverse-trace/finalsize},
#>   }

References

Andreasen, Viggo. 2011. “The Final Size of an Epidemic and Its Relation to the Basic Reproduction Number.” Bulletin of Mathematical Biology 73 (10): 2305–21. https://doi.org/10.1007/s11538-010-9623-3.

Bidari, Subekshya, Xinying Chen, Daniel Peters, Dylanger Pittman, and Péter L. Simon. 2016. “Solvability of Implicit Final Size Equations for SIR Epidemic Models.” Mathematical Biosciences 282 (December): 181–90. https://doi.org/10.1016/j.mbs.2016.10.012.

Kucharski, Adam J., Kin O. Kwok, Vivian W. I. Wei, Benjamin J. Cowling, Jonathan M. Read, Justin Lessler, Derek A. Cummings, and Steven Riley. 2014. “The contribution of social behaviour to the transmission of influenza A in a human population.” PLoS pathogens 10 (6): e1004206. https://doi.org/10.1371/journal.ppat.1004206.

Miller, Joel C. 2012. “A Note on the Derivation of Epidemic Final Sizes.” Bulletin of Mathematical Biology 74 (9): 2125–41. https://doi.org/10.1007/s11538-012-9749-6.

finalsize's People

Contributors

actions-user avatar adamkucharski avatar avallecam avatar bisaloo avatar chartgerink avatar joshwlambert avatar pratikunterwegs avatar rozeggo avatar thibautjombart avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

finalsize's Issues

p_susceptibility implementation for final_size R

Adding functionality to handle populations with non uniform distribution of susceptibilities in current finalsize function final_size in R.

This will add a p_susceptibility (or similar) argument to final_size.

End point is a function whose functionality is in line with the proposed final_size_cpp function whose underlying Cpp code already implements heterogenous susceptibility distributions across age groups.

Design and implement finalsize output class?

Designing an output format for finalsize that is shared by outputs from the ODE-based simulations in the upcoming epidemics package. Implementation likely to be as S3 and may be moved to another package.

Discussion item: possibly useful functionality elsewhere

Not really an issue - should we start a discussion board?

Just to mention that some related (probably simpler) functionality to what I think is being implemented here is available at https://github.com/sbfnk/epimixr/blob/master/R/epidemic_age_dist.r - haven't looked yet in detail how the different methods are related but either way there might be useful code/inspiration there.

There are related functions there for estimating reproduction numbers and projecting immunity from seroprevalence/vaccination data. These could one day be brought under the same hat and/or linked up.

Check that Rcpp implementation of finfal_size works

Add tests for final_size_cpp, the Rcpp implementation of final_size.
Check:

  1. Basic functionality with synthetic data,
  2. Functionality with polymod data,
  3. Increasing r0 leads to larger epidemics,
  4. Passing incorrect length vector arguments throws specific errors.

Add finalsize Cpp code as include header

Structure the finalsize Cpp Newton solver code as a header in an include directory so that it can be called from other Rcpp projects similar to the BH (Boost Headers) package (which provides the Boost libraries as headers).

Check for r0 > 1

final_size returns final epidemic sizes of 0.0 for any prop_initial_infected (> 0.0) when r0 < 1.0. This is implausible as some individuals are already initially infected. The algorithm implemented here (most likely) does not work for r0 < 1.0, and final_size should stop when r0 < 1.0 is provided.

R implementation of final_size with susceptibility groups

Implement code for final_size with susceptibility groups. This is the R-only equivalent of the Rcpp code in #39.

The idea here is to provide finalsize with a function exported to users, and with other internal functions and documentation, that allow the calculation of the final size of an epidemic in a population with heterogeneous mixing and also heterogeneous susceptibility to infection.

This is to be achieved by a translation of the Cpp code here https://gitlab.com/epidemics-r/code_snippets/-/blob/feature/newton_solver/include/finalsize.hpp#L20 into R.

This issue includes the following sub-issues: #44 #45 #46 #47 #48

Specify initial proportions infected

The initial proportions of each age group infected in final_size are hard coded to a numeric. Suggest instead a function argument that allows this proportion to be specified by the user. Could be a single value for all age groups or one per age group.
This issue addresses @thibautjombart in #19 (comment)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.