· 2 min read

Shiny + deSolve = Interactive ODE Models

Output from an SEIR compartmental model: four curves of number of people, 0 to one million, against time, 0 to about 105, with a legend giving S in red, E in olive, I in cyan and R in purple. S holds flat at one million until about time 20, then collapses to near zero by time 40. I rises from zero to a peak of about 710,000 around time 34 and decays slowly to near zero by 105. R climbs from zero through the crossover with I around time 44 and levels off near 970,000. E stays close to the axis throughout, with a small bump peaking near 60,000 around time 29.

While taking a disease dynamics course, I thought it would be a good opportunity to learn how to use the Shiny package in R and create an interactive interface for some of my problem sets. After a few trial runs with smaller, simpler setups, I have wrapped up the side project (for now). You can see it in action here 1 and you can view the final code on my Git.

At some point, I’d like to make an analogous version of these models using network-based approaches. However, all my work in network models has been done using Python so it might take a while.

If you’re unfamiliar with compartmental models, they are deterministic models that use differential equations to describe the spread of an epidemic through a population. The Wikipedia page on them is a pretty good place to start. The parameters on the page are described below—note that certain parameters are only shown when they are applicable.


  • Basics:
    • Probability of transmission: the probability that an infectious person will infect a susceptible person at any one contact.
    • Average contacts: the number of people an infected person will run into (per week).
  • Disease properties:
    • No recovery: when checked, if somebody becomes infected, they will be infectious forever—never recovering.
    • Duration: how long an infected person remains infected
    • Latent period: the time between being infected and being infectious (at which point they are neither susceptible nor infected, but are “exposed”).
    • Seasonal fluctuations: a cosine function that emulates seasonal fluctuations in contact rates.
  • Vital dynamics:
    • Birth and death rate: Self-explanatory. In these model, kept equal to each other.
    • Proportion of vaccinated a birth: assumes vaccination occurs immediately at birth (therefore, this is the proportion of new births who never enter a susceptible stage).
    • Vaccine effectiveness: probability of a vaccine actually working.

Footnotes

  1. Updated 02/13/15 — moved to shinyapps.io