**Ecology in silico**, and kindly contributed to R-bloggers)

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 , , and represent the density of

susceptible, infectious, and recovered individuals respectively of

species $i$. The total number of individuals of each species is .

Per capita birth and death rates are represented by and ,

and the strength of density dependence in population growth is

. Transmission rates from species to species 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 , 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 the resulting graphical user interface for the model.

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.

**leave a comment**for the author, please follow the link and comment on his blog:

**Ecology in silico**.

R-bloggers.com offers

**daily e-mail updates**about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...