SIR Epidemiological Model¶
A deterministic compartmental model with dissmodel¶
The SIR model tracks the spread of an infectious disease through a population divided into three compartments:
- Susceptible — healthy individuals who can be infected
- Infected — individuals who carry and spread the disease
- Recovered — individuals who have recovered and gained immunity
Requirements — this notebook uses the SIR model from
dissmodel-sysdyn, installed separately:pip install "git+https://github.com/DisSModel/dissmodel-sysdyn.git"
How it works¶
At each time step, the model computes:
| Variable | Formula | Description |
|---|---|---|
| α | contacts × probability |
Force of infection |
| ΔI | I × α × (S / N) |
New infections |
| ΔR | I / duration |
New recoveries |
Where N = S + I + R is the total population.
Imports¶
from dissmodel.core import Environment
from dissmodel_sysdyn.models import SIR
from dissmodel.visualization import Chart
⚠️ Important: instantiation order¶
The Environment must always be created before any model (SIR, Chart).
Models connect to the active environment automatically when instantiated —
if no environment exists yet, the connection fails.
Environment → SIR → Chart
↑ ↑ ↑
first second third
# 1. Environment must be created first
env = Environment()
Setting up the model¶
The SIR model accepts the following parameters:
| Parameter | Description | Default |
|---|---|---|
susceptible |
Initial susceptible population | 9998 |
infected |
Initial infected population | 2 |
recovered |
Initial recovered population | 0 |
duration |
Steps an individual remains infectious | 2 |
contacts |
Average contacts per individual per step | 6 |
probability |
Transmission probability per contact | 0.25 |
# 2. Model connects to the active environment automatically
SIR(
susceptible=9998,
infected=2,
recovered=0,
duration=2,
contacts=6,
probability=0.25,
)
<dissmodel_sysdyn.models.sir.SIR at 0x70e0542dffe0>
Visualization¶
The Chart model redraws the time series at every simulation step.
It automatically tracks susceptible, infected, and recovered
because the SIR class is decorated with @track_plot — no extra
configuration needed.
# 3. Chart also connects to the active environment automatically
Chart(show_legend=True, show_grid=True, title="SIR Model")
<dissmodel.visualization.chart.Chart at 0x70e05430ba10>
Running the simulation¶
env.run(30)
Try it yourself¶
Go back and experiment:
- Increase
contactsto simulate a more contagious disease - Increase
durationto make the disease last longer - Decrease
probabilityto simulate a less transmissible disease - Try starting with more
infectedindividuals - Change
env.run(30)to run for more steps