Interactive two-host SIR model

[This article was first published on Ecology in silico, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

This is an example of interfacing R, shiny, and deSolve to produce an interactive environment where users can explore model behavior by altering parameters in an easy to use GUI.

The model tracks the number of susceptible, infectious, and recovered individuals in two co-occuring host species. The rates of change for each class are represented as a system of differential equations:

Where $S_i$, $I_i$, and $R_i$ represent the density of susceptible, infectious, and recovered individuals respectively of species $i$. The total number of individuals of each species is $N_i$. Per capita birth and death rates are represented by $b_i$ and $d_i$, and the strength of density dependence in population growth is $\delta_i$. Transmission rates from species $j$ to species $i$ are given by . The pathogen imposes additional mortality for infected individuals at rate , and infected individuals recover at rate so that the average infectious period is . Here, it is assumed that the pathogen does not castrate its hosts. Thus, susceptible, infectious, and recovered individuals reproduce at the same rate.

Epidemiological models often differentiate between two transmission dynamics. With density-dependent transmission, the number of host contacts and transmission events increases with the density of individuals (as shown in the above system of equations). In contrast, with frequency-dependent transmission, hosts have a constant contact rate so that the transmission rate depends on the relative proportion of infectious individuals. As an example, models of sexually transmitted infections often assume frequency dependent transmission, implying that the number of sexual partners one has is independent of population density. To incorporate frequency dependent transmission into the above model, it is necessary to divide the transmission term $S\sum{(\beta I)}$ by $N$.

Based on this system of equations, a criterion for pathogen invasion called can be derived based on the dominant eigenvalue of the next generation matrix (Dobson 2004). If , the pathogen does not invade; if $R_0>1$, the pathogen invades.

Building the R shiny app

Shiny requires two files to run: a file containing all of the calculations, plotting functionality, etc., and a file defining a user interface.

Here is the file defining what you want the server to do. Note the use of ifelse() to have either density- or frequency-dependent transmission.

Here is the file defining the user interface.

Here is a link to the resulting graphical user interface for the model, with example output below.

Feel free to clone the repository or alter the code to suit your own needs. Shiny seems like a tool with great potential to make some mathematical models more accessible (at some level). For instance, something like this could be used in an ecology class to demonstrate the different ways that pathogens can regulate host populations.

To leave a comment for the author, please follow the link and comment on their blog: Ecology in silico.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)