Code for fitting a coupled SEIRD model to deaths per day data for multiple groups (e.g. age groups, sex).
Gavin Woolman 16/Sept/2025
The SEIRD model (Susceptible, Exposed, Infectious, Recovered, Dead) is one of the canonical compartmental models of disease. Each compartment has a population, and a simple deterministic model describes the rate of change of the population of each compartment.
In the simplest form, the SEIRD model differential equations are as follows:
\begin{align}
\frac{\text{d}S}{\text{d}t} &= -\beta S\frac{I}{N - D},\
\frac{\text{d}E}{\text{d}t} &= +\beta \frac{I}{N - D} - \frac{E}{l},\
\frac{\text{d}I}{\text{d}t} &= \frac{E}{l} - \left(\gamma + \delta\right)I,\
\frac{\text{d}R}{\text{d}t} &= \gamma I,\
\frac{\text{d}D}{\text{d}t} &= \delta I,\
\end{align}
where
This code creates a coupled-SEIRD model, imagining
The code is partitioned into several parts:
-
The main script is given in the notebook
SEIRD model.ipynb. This lays out examples for how to use the code. -
The differential equations that govern how the coupled SEIRD model works are laid out in
SEIRD_model.py. This file shouldn't need changed unless something fundamental about the model is being altered. -
A class used to manage fitting the model to data is set out in
SEIRD_fitting.py. Again, this class shouldn't really need changed unless something fundamental about the fitting process is being altered. -
The main class that is to be changed is
ModelHandler, defined in the jupyter notebook itself. This defines how the fitting parameters are put into the model, and sets initial conditions (e.g. the compartment populations on the first day of infection, and the date of the first day of infection).