Skip to content


Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


Various implementations of the classical SIR model in Julia

Try the notebooks out in Binder:


Model considered

GitHub Markdown doesn't parse equations, so here's a description of the underlying SIR model.

  • The ordinary differential equation model considers:
    • Susceptible, S, with initial condition S(0)=990
    • Infected, I, with initial condition, I(0)=10
    • Recovered, R, with initial condition R(0)=10
    • Total population, N=S+I+R=1000
  • Susceptible individuals make contacts with others at rate c (=10.0), with the probability of a contact with an infectious person being I/N. With probability β (=0.05), an infected person will infect a susceptible given a contact.
  • Infected individuals recover at a per-capita rate γ (=0.25).

There are two types of parameterization commonly used in this project; the 'standard' version, that considers the number of individuals in the S, I, and R groups, and an alternative version, in which the dynamics of transmission (βSI/N) and recovery (γI) are modelled directly, with S, I, and R being calculated based on these dynamics and the initial conditions for S, I and R.

Simulation with different types of model

The above process can be represented in different kinds of ways:

Generating simulated data

We usually do not observe the trajectory of susceptible, infected, and recovered individuals. Rather, we often obtain data in terms of new cases aggregated over a particular timescale (e.g. a day or a week).

Use of callbacks


In addition to the above examples of simulation, there are also examples of inference of the parameters of the model using counts of new cases. Although these are toy examples, they provide the building blocks for more complex situations.


In conducting inference, it is important to know the extent to which parameters are identifiable from the available data.


Incorporating uncertainty in its many forms is important for using models to make decisions.

Probabilistic integration

When solving continuous-time models like ODEs, the discretization can lead to numerical errors. Probabilistic integration treats this error as a statistical problem to capture the uncertainty in the model outputs generated using the solver.

Global sensitivity

Local sensitivity

Surrogate models

Flexible models


Comments on implementations

Note that the implementations and choice of parameters may be suboptimal, and are intended to illustrate more-or-less the same underlying biological process with different mathematical representations. Additional optimizations may be obtained e.g. by using StaticArrays.

I've also tried to transform parameterisations in discrete time as closely as possible to their continuous counterparts. Please see the great work by Linda Allen for how these different representations compare.

Types of output

Thanks to Weave.jl, Julia Markdown files (in tutorials/) are converted into multiple formats.

Running notebooks

git clone
cd sir-julia

Then launch julia and run the following.

import IJulia

Adding new examples

Plans for new examples are typically posted on the Issues page.

To add an example, make a new subdirectory in the tutorials directory, and add a Julia Markdown (.jmd) document to it. Set the beginning to something like the following:

# Agent-based model using Agents.jl
Simon Frost (@sdwfrost), 2020-04-27

Suggested sections:

  • Introduction
  • Libraries
  • Utility functions
  • Transitions
  • Time domain
  • Initial conditions
  • Parameter values
  • Random number seed
  • Running the model
  • Post-processing
  • Plotting
  • Benchmarking

Change to the root directory of the repository and run the following from within Julia; you will need Weave.jl and any dependencies from the tutorial.

weave_all() # or e.g. weave_folder("abm") for an individual tutorial

If additional packages are added, then these need to be added to build_project_toml.jl, which when run, will regenerate Project.toml.


Examples use the following libraries (see the Project.toml file for a full list of dependencies):

Parts of the code were taken from @ChrisRackauckas DiffEqTutorials, which comes highly recommended.


Various implementations of the classical SIR model in Julia







No releases published


No packages published