Will we survive the COVID-19 pandemic?

A Python simulation to visualise how disease spreads in a community.

Yeap Ping Lin
Towards Data Science
5 min readMar 20, 2020

--

Unless you’re living under a rock, you’ve probably been swarmed with news of the COVID-19 pandemic. But with so many conflicting claims made by people, governments, the media, and even healthcare experts about how this pandemic will pan out (ha!), it’s easy to get lost in all the noise.

So I thought, why not make use of available data and simulate the spread of this virus?

The rules of the Matrix

Here, I use a Conway’s game-board to simulate a 2-dimensional population of cells on Python. A certain percentage of the population is randomly infected. Based on current estimates of the different rates, an infected cell can either: (i) infect neighbouring cells, (ii) recover, or (iii) die. The infection then “spreads” through the population as the simulation iterates.

The basic reproduction number, or R0, for COVID-19 varies with many factors; in this simulation I use an estimated value of 3.28. This means that an infected cell can be expected to directly infect 3.28 other neighbouring cells. The probability of an infected cell infecting a neighbouring cell is then taken as the ratio of R0 to the number of neighbouring cells, i.e. 3.28 / 8 = 0.41.

The two other rates used are the fatality rate and recovery rate. The fatality rate is taken from the death rate — the number of known deaths divided by the total number of confirmed cases. According to WHO, the global death rate as of 3 March is 3.4%. The recovery rate is taken to be 81%, as the majority of the cases will eventually recover if given proactive treatment.

TL;DR — In this simulation, an infected cell has a probability of 0.41 of infecting the 8 neighbouring cells, a probability of 0.81 of recovering, and a probability of 0.034 of dying.

Trial simulation of 100 cells. An infected cell (red) can either infect other cells, recover (green), or die (black). Uninfected cells are (white).

We will probably survive this.

If the assumptions are right, most of humanity will survive this pandemic. In this simulation of 2,500 cells, the infection is allowed to spread freely (which, by the way, was what the UK planned to do with its herd immunity strategy).

A population of 2,500 cells with 1% initially infected.

Here, most of the cells eventually recover, but this is definitely not an ideal outcome. Almost the entire population is infected eventually, and in the real world, many of them will probably suffer from some health or financial complications.

There’s also that ~5% of population that dies from the infection. With a population of ~68 million in the UK, that number translates to more than 3 million people.

At the peak of the infection, ~20% of the population is infected at the same time. For a large population, this is a lot of people, and it can potentially overwhelm the healthcare system. Which leads to the next point.

Healthcare is crucial.

The fatality rate of 3.4% and recovery rate of 81% are based on the assumption that all infected cases receive timely and adequate healthcare upon infection. This is not always true, especially when healthcare systems are overwhelmed. In this simulation, I use Italy’s fatality rate of 7.94% as well as a lower recovery rate.

Using a higher fatality rate and lower recovery rate to simulate overwhelmed healthcare systems.

Sure, humans won’t go extinct, but at the peak a quarter of the population is infected, with >10% of the population eventually deceased. We certainly do not want to head down that path. So what should we do?

Social distancing works.

Social distancing involves people avoiding gatherings or large events to slow the spread of a disease. This means that people shouldn’t congregate, even if they are praying to eliminate the virus.

In this simulation, when a cell is distanced or quarantined, it is assumed to be uninfected and also unable to be infected by others.

Small-scale social distancing. A cell that is distanced or quarantined (blue) is assumed to be uninfected and also unable to be infected.

With small-scale distancing (where 10% of the population is distanced), peak infection already drops to ~10%. The curve is significantly flattened, and some of the population can even be spared from the infection.

Medium-scale social distancing. Infections are kept to manageable levels.

With 50% of the population distanced, the spread is evidently slowed by the distanced cells (blue). Infections are kept to manageable levels, and healthcare systems are not compromised.

Large-scale social distancing. Disease dies out.

With 90% of the population distanced, the disease dies out rapidly. This is probably why Wuhan, the source of the outbreak, was able to bring new domestic infections to zero.

In closing

Can these simulations be wrong? Definitely. These are just simple computer models built on limited inputs and questionable assumptions by someone who has too much time while practising social distancing. But I guess they could still be useful as an alternative visualisation tool.

And so folks, get distancing.

Disclaimer: the author does not make any warranties about the completeness, reliability and accuracy of this simulation exercise. Any action you take upon the information on this article is strictly at your own risk.

--

--