Giter VIP home page Giter VIP logo

idmodelr's Introduction

Infectious disease model library and utilities

badge CRAN_Status_Badge develVersion DOI metacran monthly downloads metacran downloads

Explore a range of infectious disease models in a consistent framework. The primary aim of idmodelr is to provide a library of infectious disease models for researchers, students, and other interested individuals. These models can be used to understand the underlying dynamics and as a reference point when developing models for research. idmodelr also provides a range of utilities. These include: plotting functionality; a simulation wrapper; scenario analysis tooling; an interactive dashboard; tools for handling mult-dimensional models; and both model and parameter look up tables. Unlike other modelling packages such as pomp, libbi and EpiModel, idmodelr serves primarily as an educational resource. It is most comparable to epirecipes but provides a more consistent framework, an R based workflow, and additional utility tooling. After users have explored model dynamics with idmodelr they may then implement their model using one of these packages in order to utilise the model fitting tools they provide. For newer modellers, this package reduces the barrier to entry by containing multiple infectious disease models, providing a consistent framework for simulation and visualisation, and signposting towards other, more research, focussed resources.

Installation

Install the CRAN version:

install.packages("idmodelr")

Alternatively install the development version from GitHub:

# install.packages("devtools")
devtools::install_github("seabbs/idmodelr")

Documentation

Documentation Development documentation Getting started Functions

Testing

R-CMD-check Coverage Status

Quick start

In this quick start guide we are going to be defining, simulating and plotting a Susceptible-Infected-Recovered deterministic compartmental model with simple population demographics (births = deaths). The first step is to load the idmodelr package.

library(idmodelr)

The next step is to find the model of interest amongst those implemented in idmodelr. model_details lists all of the models implemented in idmodelr and can be search using dplyr, base R, or other dataframe tools.

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

model_details %>% 
  dplyr::filter(model_family %in% "SIR") %>% 
  knitr::kable()
model model_family time type recovered exposed treated susceptible risk_stratified non_exponential simple_demographics vaccination disease_example language parameters
SIR_ode SIR continuous deterministic no no no no no no no no none R beta, tau
SIR_demographics_ode SIR continuous deterministic no no no no no no yes no none R beta, tau , mu
SIR_vaccination_ode SIR continuous deterministic no no no no no no no yes none R beta , tau , lambda
SIR_vaccination_demographics_ode SIR continuous deterministic no no no no no no yes yes none R beta , tau , lambda, alpha , mu

Now look at the model and the model help file (?SIR_demographics_ode) to get an understanding of how the model is constructed.

SIR_demographics_ode
#> function (t, x, params) 
#> {
#>     S <- x[1]
#>     I <- x[2]
#>     R <- x[3]
#>     with(as.list(params), {
#>         N = S + I + R
#>         dS = -beta * S * I/N - mu * S + mu * N
#>         dI = beta * S * I/N - tau * I - mu * I
#>         dR = tau * I - mu * R
#>         derivatives <- c(dS, dI, dR)
#>         list(derivatives)
#>     })
#> }
#> <bytecode: 0x7fb5c4a7da08>
#> <environment: namespace:idmodelr>

Check the parameters required by the model using required_parameters. This returns a table containing all the parameters that must be defined in order to use the model as well as descriptive information for each parameter.

parameters <- required_parameters("SIR_demographics_ode")

knitr::kable(parameters)
parameter parameter_family description type risk_stratified non_exponential
beta transmission Transmission rate = the transmission probability per contact * the number of contacts each individual has. rate no no
tau recovery Recovery rate. The reciprocal of the time infectious. rate no no
mu demographics The natural mortality rate. The reciprocal of the average lifespan. (for simple demographics this is also the birth rate. rate no no

Parameterise the model.

parameters <- data.frame(
  beta = 3, ##Transmission rate = contact rate * transmission probablity
  tau = 0.5, ## Rate recovcery = 1 / duration of infection
  mu = 1/81 ## Natural birth/death rate = 1 / average lifespan
)

Check the initial conditions required by looking at the start of the model function. In most cases this should match up to the model name (i.e S, I and R for an SIR model) but risk stratification etc. will require additional compartments.

inits <- data.frame(
  S = 999,
  I = 1,
  R = 0
  )

Specify the timespan over which to run the model.

times <- seq(0, 50, 0.1)

Simulate the model.

traj <- simulate_model(model = SIR_demographics_ode,
                       sim_fn = solve_ode, ##as solving an ode
                       inits = inits,
                       params = parameters,
                       times = times)


traj
#> # A tibble: 501 × 4
#>     time     S     I      R
#>    <dbl> <dbl> <dbl>  <dbl>
#>  1   0    999   1    0     
#>  2   0.1  999.  1.28 0.0567
#>  3   0.2  998.  1.64 0.129 
#>  4   0.3  998.  2.11 0.222 
#>  5   0.4  997.  2.70 0.342 
#>  6   0.5  996.  3.46 0.494 
#>  7   0.6  995.  4.43 0.690 
#>  8   0.7  993.  5.67 0.940 
#>  9   0.8  991.  7.25 1.26  
#> 10   0.9  989.  9.28 1.67  
#> # … with 491 more rows
#> # ℹ Use `print(n = ...)` to see more rows

Summarise the model.

summarise_model(traj) %>% 
  knitr::kable()
Final size: S Final size: I Final size: R Epidemic peak time Epidemic peak Epidemic duration
136 31 833 3.5 533 Inf

Plot the model trajectory.

plot_model(traj, facet = FALSE)
#> Warning: `guides(<scale> = FALSE)` is deprecated. Please use `guides(<scale> =
#> "none")` instead.

Vary the model parameters, by increasing the mortality rate, and then simulate the updated model.

parameters_up <- parameters
parameters_up[["mu"]] <- 1 / 20


traj_up <- simulate_model(model = SIR_demographics_ode,
                          sim_fn = solve_ode,
                          inits, 
                          parameters_up,
                          times)

Plot the original trajectory and the updated trajectory. What has the impact of increasing mortality been?

plot_model(traj, traj_up, facet = TRUE)
#> Warning: `guides(<scale> = FALSE)` is deprecated. Please use `guides(<scale> =
#> "none")` instead.

See the package vignettes for more help getting started and some additional ideas for exploring infectious disease model dynamics.

Dashboard

A shiny application has been developed that showcases some of the functionality of the idmodelr package. This application allows the parameter spaces of a range of models built into idmodelr to be explored in an interactive session. It is designed to be used as a teaching aid when introducing people to the concepts behind infectious disease models without requiring them to interact with the underlying code. The code for the dashboard can be found here. It can be run locally using the following (Note: this will install required packages to your system),

#install.packages("shiny")
shiny::runGitHub("exploreidmodels", "seabbs")

Snapshot of the integrated dashboard.

Contributing

Contributing a model

Additional models are extremely welcome!

To add models in the same family as those already implemented (i.e SIR_ode) please follow the implemented coding style closely (alternatively open an issue explaining why this style needs updating). Models should be named using their compartments in capitals followed by lower case model details, and finally the model type. An example of this is the SIR_demographics_ode model. For highly complex models only the most major model details should be listed (aim for less than 40 characters). An entry for model_details is also required (see model_details.R). If new parameters have been used then a description must be added to parameter_details (see parameter_details.R). Please consider also adding to the testing suite for your new model (or flagging the lack of tests). Models can either be added via a pull request or via an issue.

To add a new family of models (i.e stochastic models) please open an issue outlining your proposed approach. A new family of models is likely to require at least its own solve_ (equivalent to solve_ode) function and may also require other package changes. Models implemented in other languages (i.e C) are also very welcome.

Other contributions

File an issue here if there is any other feature, that you think is missing from the package, or better yet submit a pull request!

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

Docker

This packge was developed in a docker container based on the tidyverse docker image. To run the docker image run:

docker run -d -p 8787:8787 --name idmodelr -e USER=seabbs -e PASSWORD=seabbs seabbs/idmodelr

The rstudio client can be found on port :8787 at your local machines ip. The default username:password is seabbs:seabbs, set the user with -e USER=username, and the password with - e PASSWORD=newpasswordhere. The default is to save the analysis files into the user directory. Alternatively, access the development environment via binder.

idmodelr's People

Contributors

romainfrancois avatar seabbs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

idmodelr's Issues

Rcpp models

For compute-intensive analysis, R based models are often inadequate. A common approach for working around this is to implement the model in C and to then integrate it into other code using Rcpp.

idmodelr should include examples of Rcpp models that can be compared to their R versions. This should be a great help to those new to Rcpp.

Describe the solution you'd like
Replicas of all currently implemented models using Rcpp.

Additional context
All Rcpp models should work with all other package functionality.

Improve the rigour of the testing suite

At the moment the testing suite has good coverage but is not very rigorous. Add tests more properly customised to function utility to make sure errors are caught properly

Add paper

Add a paper outline ahead of JOSS submission (post-CRAN).

Getting started vignette

Vignette outlining how to use the package.

A basic version of this should also be in the readme (or only in the readme). Depening on length....

Where does `idmodelr` sit?

There are multiple other infectious disease modelling packages with different aims. Where does idmodelr sit within these?

Packages:

  • epimodel
  • pomp
  • libbi

These packages are mainly focussed on usage for actual research. pomp and libbi focus on model fitting, whilst epimodel is focussed on network models. None of these tools provide a library of models.

idmodelr

idmodelr provides a library of models that can be used within a consistent framework. The main purpose of idmodelr is to allow those new to infectious disease modelling to quickly, and easily explore infectious disease model dynamics. It also serves as a reference point for these users when developing their own models. It is hoped that over time it will develop into a library of infectious disease model, each displaying a different technique. In essence, this is an in R implementation of epirecipes but with an R centric scope.

Jobs

  • Add a package description.
  • Add an other modelling tools section + resources.
  • Add a contributing models section.
  • Add so I understand model dynamics what now? Section.

Stochastic models

Make stochastic models have parity with current ODE implementations

Jobs

  • Implement a solving function for stochastic models
  • Implement all models as stochastic
  • Testing for all stochastic models
  • Support for multiple model runs in all functions

Adapt solve and simulate

Move to a generic solve function and make the simulate function the major passed function that controls behaviour.

Summarise model

The current implementation of the summarise_model is quite limited and focusses exclusively on the outbreak. This will not generalise well and performs poorly for multiple model runs.

Task

  • Develop a summarise_epidemic function that summarise an initial outbreak based on a specified set of compartments (vectorised) by default this should be I. This needs to be robust to multiple models runs.
  • Develop a comparable summarise_endemic function that looks at the long run behaviour of the model.
  • Develop a summarise_simulation function that summarise multiple model runs.
  • Transition current summarise_model functionality to wrap all three of the above.

Add case study

Develop a package case study by adapting the Epidemics material on the gamma-distributed model. Make sure to cite back to it clearly. Depends on #27

Integrate `exploreidmodels`

The interactive interface provides many of the functions of the package. It needs to be tightly integrated and promoted. Adding a model/feature should be made easier if possible.

Exploring ID models

A vignette exploring some of the dynamics of ID models with pointers to more information. This will then be adapted along with the getting started vignette into a release blog.

Plot model

Plot model needs to be able to handle multiple models runs in a more intelligent fashion.

Task

  • Move from being able to handle two simulations to an arbitrary number
  • Add ability to summarise simulations - rely on functionality from summarise_model. and the plot them
  • Plot both all simulations and summarise options

Searchable library of models

Model types that are provided in the package need to be easily understood. This also needs to be future proof in case on any changes.

Task

  • Add a data frame containing model information.
  • Make the data frame searchable/subset able in some way.
  • Add as a vignette.

To S3 or not?

Currently, all functionality is built into specially named functions. Should S3 methods be used instead?

Improve how to contribute

Very important that it is clear how to contribute to the package. This needs to be laid out clearly somewhere.

PMCMC case study

Background

Vignette walking through the use of PMCMC modelling using a base R model but any other tools required.

Aim

Explain the basics of PMCMC and give directions to more resources. Based on the draft vignette package functionality will be expanded so that everything (excepting the actual PMCMC) can be reproduced using package code.

Method

Explain some of the workings of PMCMC, highlight tools that are available and point towards other tools (such as LibBi and POMP) that may be more appropriate for use in actual research. Link to recent paper that provides a more complete walkthrough.

Based on the draft vignette package functionality will be expanded and the vignette will then be updated to reflect this.

Links

  • Linked to adding stochastic models to the package.
  • Link to package resources on LibBi and Pomp
  • Link to any package tools that are used (fine if none)
  • Linked to #10 (stochastic models)

What do you think @akira-endo?

Bifurcation/Steady state plot

Plotting + simulation of a models steady states as parameters vary.

Need to have model simulation over a range of parameters
and plotting of steady states/pseudo -steady states

run_permutation_analysis

A function to run through a data-frame of parameters, simulating for each parameter set, and then offering the options of summarising the results. Parallised for efficiency.

Add parameter look up

Different models require different parameters and these can often have hard to understand greek names (which are anyway somewhat arbitary).

Need to ensure that parameter names are used consistently across models and that the requirements for a given model can be checked.

For this reason need a central table of model parameters that can be search either by model or by parameter.

Hexsticker

Use package functionality to produce a hexsticker

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.