Skip to main content

Simulate your own viral spread


The experts use computer simulations to predict how a pandemic or epidemic will spread through the population. But for most people, the idea of a computer simulation being used to make decisions that affect all our lives, seems very distant. It’s potentially difficult to understand how these simulations relate to the real world and hard to decide if they are giving useful predictions.
I feel like the best way to understand something is to have a go. So that's what I have done, and I thought I would give anyone else who wishes, the opportunity to have a go as well. So I have coded up my own small simulation of a spreading virus. You can download it here! Download it to your laptop or PC and just double click it to get going. Unfortunately I’ve never written apps for phones, so there isn’t an app version - you will need a laptop or PC.

What this is and what this isn’t

This is what scientists refer to as a toy model. This means it is a simulation that captures some of the basic things that are going on, but it does not include all the complexities of the real world. Also this simulation was written by a scientist who measures weather, not a scientist who measures spread of diseases. Just like everything you find on the internet, accept it with a healthy chunk of scepticism.

In this simulation, a series of dots wander randomly around on your screen. 5 of them are infected with a virus! The virus has three stages. Initially a dot is simply a carrier, you will see it’s colour change to a lighter shade of grey. In the second stage the virus is contagious. At this point the dot will turn pink and if it gets too close to another dot, it passes the virus on. Most dots only have these two phases and they fully recover. Recovered dots are immune from getting the virus again and are blue. Unfortunately some dots hit the third viral stage and become critically ill, turning dark red. A fraction of these will die becoming a white dot. If the health system becomes overloaded with critical patients, you will see the statistics in the corner turn red, and any critically ill dots who cannot get an intensive care bed will die. As the simulation progresses you can see the reproduction number of the virus and the charts showing the fraction of dots at the different stages.
You can affect how things pan out, by changing the simulation setup. You can adjust parameters, such as how deadly the virus is, how many dots there are, how much they move around to spread the virus and how many intensive care beds there are.  You can also lockdown the population, protect the vulnerable and induce new infections. The default setup gives a reproduction number around 2. This is close to that of Coronavirus. The number of dots is 4000, so if you wish to equate that with the UK population, each dot would represent around 15,000 people. The number of intensive care beds is set to 6.6 per 100,000 dots, this is the same as the UK, and enough for approximately one quarter of a dot to have a bed! If you wish to change this, the countries with the most intensive care beds have between 5 and 35.

What happens in the simulation

I’ll only mention here what happens with the default setup if you change nothing; you can play to see what happens when you use different settings. Note that every simulation is random, so you won’t get exactly the same as me and you’ll get a slightly different result each time, even with the same setup. In a few cases the virus will just die out and that will be the end of it, but for most runs the virus will spread. It will start off low level then suddenly the number of cases will seem to shoot up. This is due to exponential growth. Quickly after your cases shoot up, you will run out of intensive care beds and dots will start dying. Remember each dot that dies would represent about 15,000 UK deaths, so once two dots have died, this is worse than a regular UK flu season, which kills around 20,000 people each year.

Once the simulation has been running for a couple of minutes, if you are not hypnotised by the randomly moving dots, then you will notice the charts indicating the number of infectious andcarrier dots has stopped going up. This happens when about half the population have been infected. The reason is that the virus is running out of new hosts. Half the population is immune and this has halved the reproduction number. With a reproduction number of around 1, the virus stops spreading. However the death toll will have racked up. Soon after this, the number of cases starts falling. Eventually, the last case disappears and the outbreak is over.

In this default "do nothing" scenario, around 3000-3500 dots will have caught the virus, that 75-85% of all dots. between 150 and 200 dots probably died. That’s 3.7-5% of the population.
Have a go and see if you see the same, then have a play, to see how you can change things. Try reducing the amount of movement, to simulate social distancing or try doing lockdowns to eradicate the virus. Also, once the virus is gone, try reinfecting the population and see what happens. Feel free to add comments below to tell people what results you get.

Comments

Popular posts from this blog

UK covid-19 forecast 20th April 2020

Here are the results from my covid-19 prediction, updated with the figures from 20th April 2020. I have been tracking the progress of the UK cases and comparing the numbers with a simple model. The model seems to have been doing rather well - well enough, that I thought I would post its forecast. I haven't posted the forecast for two days. Since then the number of deaths per day has dropped two days in a row. The model is forecasting a rapid drop in deaths right now, with that figure dropping below 100 in the next few days. However, we often see a drop in deaths on Sundays and Mondays, due to delays in reporting deaths over the weekend. These dips are often followed by a spike on Tuesday. In addition, the model is predicting an even faster drop than we have seen and is underpredicting the total deaths at the moment.. I hope the drop we have seen is real and continues in today's figures. Meanwhile, the model continues to do a good job with representing w...

UK Covid-19 forecast 17th April 2020

These are the results from my covid-19 prediction, updated on 17th April 2020. I have been tracking the progress of the UK cases and comparing the numbers with a simple model. The model seems to have been doing rather well - well enough, that I thought I would post its forecast. This isn't an exact science, The model is very simple and I'm not an epidemiologist. Please take everything here with a pinch of salt. I have included an uncertainty estimate with the numbers, by saying give or take a certain amount or presenting a range. These are all 95% confidence, meaning that I think there is a 95% chance that reality will fall within the range - but this assumes that the simple model is right. Remember, this is a simple model, so the numbers may turn out to be totally wrong . Covid-19 is a coronavirus - one of eight strains of coronavirus that humans can catch. We do not have a vaccine for any coronavirus strain and typically people can catch coronaviruses ...

UK Covid-19 forecast 16th April 2020

I have been tracking the progress of the UK cases and comparing the numbers with a simple model. The model seems to have been doing rather well - well enough, that I thought I would post its forecast. This isn't an exact science, The model is very simple and I'm not an epidemiologist. Please take everything here with a pinch of salt. I have included an uncertainty estimate with the numbers, by saying give or take a certain amount or presenting a range. These are all 95% confidence, meaning that I think there is a 95% chance that reality will fall within the range - but this assumes that the simple model is right. Remember, this is a simple model, so the numbers may turn out to be totally wrong . Date that number of confirmed cases per day is expected to drop below one thousand 25th April 2020 give or take 2 days Expected total number of confirmed cases 133,000 give or take 20,000 Date that number of deaths per day is expected to drop below one hundred 21st Apr...