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

There is no covid-19 lockdown exit strategey

I have been discussing long term outcomes of the covid-19 outbreak since the UK had just a few dozen cases. It's clear that similar discussions, within the scientific and political community, have not borne fruit. On the BBC's Andrew Marr show today, advisor the UK government, Neil Fergusson, said the UK does not have an exit strategy, but hopefully will within the next week or two. South Korea, widely hailed as one of the countries that successfully dealt with the virus is also struggling with exactly the same question and has not yet reached any conclusions. In fact, as cases drop, South Korea is considering tightening restrictions. As far as I can see at this point, there is only one country in the world with an exit strategy - Sweden. There are exactly three outcomes to this pandemic We discover a vaccine or effective treatment, immunise/treat people so they become medically immune and the problem goes away. Eventually so many people catch the disease and become nat

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

Moral dilemma of choosing who dies

There is a classic thought experiment in ethics - in this experiment, by taking action you save some people but condemn others, what do you do? Here is a version, known as the trolley problem. Imagine you find out about the plan of a dastardly villain - he has tied five people to the train line and set a runaway train heading towards them. You have realised that there is a junction between the train and the people and you can put a lever and divert the train onto a sideline. Unfortunately, the dastardly villain has also spotted the sideline but in his haste to get away he only had time to tie a single person to the tracks in this direction. What do you do? Do you do nothing and let the actions of the villain be his responsibility solely or do you decide to take action, divert the train and choose to sacrifice the lone person in order to save the larger group? In studies, most people say that they will take action and save the larger group, but some do say they will do nothing