Herd immunity

that's when the group is protected

If enough individuals in a group become immune to a disease, it stops the disease from spreading. But how does it work? Let's take a look at that, with the help of mathematical simulations 🤓 and a fictional virus.

This article is based on simple mathematical models, and aims to show how the mechanisms behind herd immunity works. It is not a model to describe how covid-19 is spread.

What is herd immunity?

Herd immunity refers to a group's ability to resist disease. A disease spreads when an infected individual comes into contact with a non-immune individual. When most people are non-immune, the disease spreads rapidly because each infected individual has a high chance of coming into contact with a non-immune individual. If enough individuals are immune, infected individuals may not spread the disease to anyone, allowing the virus spread to slow down and eventually stop completely. If enough individuals are immune, in a way the whole group becomes immune because people who are not immune are protected by the herd.

Let's talk about how the simulation works. Every dot in the graphics is an individual. If the dot is green, it is immune and is not affected by the virus. If the dot is white it is not immune and is therefore susceptible to the virus. If the dot is purple, it has the virus, and can spread the virus to all its susceptible neighbors (adjacent dots).

Below the dots, you can see bars that show what proportion of the dots became infected and what proportion remained unaffected for each round of the simulation. The mathematical simulation is run approximately every two seconds.

Okay, so the first simulations below show what herd immunity is. Look at the graphics - in the left one 20% is immune and the fictional virus spreads basically unhindered. In the right one, 70% are immune, and the virus is effectively stopped. The right has thus achieved herd immunity.

You either have it or you don't

With herd immunity, it is almost as if a society has either achieved it or not - and it does not have to be much that separates these two states. In the left simulation below, 50% are now immune, but this hardly stops the spread. The virus finds a way around the protected individuals.

In the right, 60% are immune, and the fictional virus is usually stopped after only a small proportion was infected.

It all depends on how contagious the virus is

The more contagious the virus is, the greater proportion of the group must be immune to achieve herd immunity.

In the simulation below, the virus to the right spreads only to the neighbors who are above or next to it, that is four other dots. The virus on the left, on the other hand, can spread to six dots (it is more contagious).

In both simulations, 50% of the dots are immune. Where it is spread to four neighbors (on the right) that is enough to achieve herd immunity - but in the left it is not enough.

This is how the simulation works

It calculates every two seconds

In our simulation, things happen step by step. About every two seconds, it calculates everything that is going to happen - which cells our fictional virus is to spread to. It also calculates all the data we receive, like how large a proportion are still unaffected and how many are infected.

The world is divided into cells

The simulation is based on us creating a "world" that consists of a number of cells (the dots). They are placed on a grid and either the cells have six sides and thus have six neighbors, or four sides - and have four neighbors.

Grid with six sides

Grid with four sides

First the the virus is introduced

At the beginning of a round (simulation), all cells first become receptive. Then it is randomized who is immune. After that, the simulation is started by two susceptible cells getting the virus, this also happens randomly.

After that, the virus spreads to the susceptible neighbors. When that is done, the graphics are updated.

Finally the spread stops

When no more cells can be infected, the graphics stop and the simulation is over. Shortly after that, a new round begins and because it is random every time, one round does not give the same result as the other.


Do you like simulations? Read our article on social distancing from the beginning of 2020

It is not yet clear how what share of a population must become "immune" to stop covid-19. But what is known is that the higher the proportion that is immune (and does not spread the virus further), the less opportunity there is for the virus to spread within the population.

Oskar Nyqvist

SVT Datajournalistik

Publicerad: 15 maj 2020