Epidemic simulator
Hundreds of people walk through a square, and a few of them carry a virus. Every day each infected person may infect the people close by, and after about a week recovers. Watch the red dots spread, the epidemic curve rise, peak and fall, and compare it with the dashed curves of the classic SIR model of Kermack and McKendrick. Change the infection chance and the recovery time and read R₀, the basic reproduction number; vaccinate a share of the population or keep people at home and see the peak drop. Switch to a log scale to see the early exponential growth as a straight line, and run it again to see how chance can end an outbreak before it starts. People walk at random through the square. Every day each infected person (red) infects each susceptible person (blue) within reach with the infection chance, and recovers (green) after the recovery time on average. The squares are people staying home; the grey dots are vaccinated. The chart shows the share of susceptible, infected and recovered people day by day, with the SIR model dashed. Press Play to watch the outbreak day by day, Skip for the end, Reset for day 0 of the same run and New run for another one. Log scale turns the early exponential growth into a straight line.
How it works
- Choose how many people there are, the infection chance per contact per day and the recovery time in days.
- Set how many people are infected at the start, the share vaccinated and the share staying home.
- Press Play to watch the outbreak day by day, Skip to see the end, or New run for another roll of the dice; turn on Log scale to see the exponential growth.
- Read R₀, the peak, the share ever infected with the herd-immunity threshold and the doubling time, and save the picture or open it in the editor in layers.
Susceptible, infected, recovered
Every person is in one of three groups. Susceptible people (blue) can catch the virus; infected people (red) can pass it on to anyone within their contact zone, with the infection chance on every day they meet; recovered people (green) are immune. Each infected person recovers with a chance of one in the recovery time every day, so a recovery time of 7 days means 7 days on average. That is exactly the assumption of the SIR model, which turns the same rules into three equations: dS/dt = −βSI/N, dI/dt = βSI/N − γI and dR/dt = γI, with β the infection chance times the contacts per day and γ = 1/recovery time. The chart draws the simulation solid and the model dashed.
R₀ and exponential growth
R₀ = β/γ is how many people one case infects when everyone is still susceptible. With an infection chance of 9%, about 4 contacts a day and 7 days to recover it is about 2.5. As long as almost everyone is susceptible the number of cases grows exponentially, doubling every ln 2 / (β − γ) days, a little over 3 days here. On a log scale that growth is a straight line. The growth slows as the susceptible run out, and the outbreak peaks when only 1/R₀ of the people are still susceptible: about 23% are infected at once for R₀ = 2.5, and about 89% are infected in the end.
Vaccination, distancing and chance
Vaccinated people (grey) are immune from day 0. Once more than 1 − 1/R₀ of the population is immune, 60% for R₀ = 2.5, each case infects fewer than one other and outbreaks die out: herd immunity. People staying home (drawn as squares) do not move and do not meet each other, which lowers the contacts per day and with them R₀: the curve gets flatter and later. And because the simulation runs on chance, the first cases sometimes recover before they infect anyone: with one initial case and R₀ = 2.5 a sizeable share of runs fades out at once, something the deterministic model cannot show.
Frequently asked questions
How does the epidemic simulator work?
People walk at random through a square arena. Every day, each infected person meets everyone within a small contact radius, and each susceptible person among them is infected with the infection chance. Every infected person recovers with a chance of one in the recovery time each day. Vaccinated people are immune from the start, and people staying home do not move. The run continues until nobody is infected, at most 400 days.
What are the dashed curves?
The deterministic SIR model of Kermack and McKendrick (1927), solved with the Runge–Kutta method: dS/dt = −βSI/N, dI/dt = βSI/N − γI, dR/dt = γI. Its γ is 1/recovery time and its β is the infection chance times the average number of contacts per person per day, which the simulation counts. The solid curves wobble around the dashed ones because the simulation runs on chance and its contacts are local.
How is R₀ calculated?
R₀ = β/γ: the infection chance times the measured contacts per person per day, times the recovery time. With 9%, about 3.9 contacts and 7 days that is about 2.4. It is the number of people one case infects when everyone is still susceptible; above 1 an outbreak can take off, below 1 it dies out.
Why does the outbreak sometimes stop after a few cases?
Chance. The first infected people may recover before they pass the virus on, even when R₀ is above 1. With one initial case and R₀ = 2.5 this happens in a sizeable share of runs; press New run a few times to see it. The deterministic model always predicts a full epidemic, which is the difference between a stochastic and a deterministic model.
What is the herd-immunity threshold?
The share of the population that must be immune for each case to infect fewer than one other person on average: 1 − 1/R₀. For R₀ = 2.5 that is 60%. Set Vaccinated above it and the outbreak fizzles out. An unchecked epidemic overshoots it: with R₀ = 2.5 about 89% are infected in the end.
Can I use the picture?
Yes. Save gives a PNG, and the pencil opens the picture in the PictorX photo editor with the arena, the contact zones, the susceptible, infected, recovered and vaccinated people, the chart's axes, each curve, the SIR model and the labels on layers of their own. Everything is simulated in your browser.
Epidemic Simulator: how do I record a video?
Press the red Record button in the playback bar: it films what the stage shows. Press it again to stop, and the video is saved to your device. Recording is free; you only need to sign in. Without a subscription the video carries a small PictorX logo in a corner. The button beside Record opens the video options: the shape (as shown, square, story 9:16 or wide 16:9), the length (until you stop, or 5, 10, 15 or 30 seconds for social media) and the file: MP4, WebM or an animated GIF. You can add one of three music tracks: calm, bright or beat.
Ready to try it?
Open PictorX in your browser — no install, no credit card required to start.
Go to Editor