Dark theme

Showing disease spread

 

So our model lets us see the spread of the disease, but if we want to know how fast it spreads we have to sit there with a stopwatch timing it. Wouldn't it be better if it recorded the time it took itself? Well, we can sort this out...

1) We already have a variable that records how many sprites are infected, so that's useful. All we need now is a timer and some way of recording the time and infection numbers whenever they change. Here's the code (new bits arrowed). Note we use two new "list" variables to store the variable values: "Times" and "Infected". Lists store many values at once. You can use the "Make a list" button in the "data" code set to make a list. Make sure you set these as "For all sprites".

Screenshot: Recording code

 

2) Make sure you understand what this new code is doing, then put the code in and see how it runs. You should see two "lists" appear on your Stage:

Screenshot: Lists

If you right-click on the top of each list (as in the picture above) you'll see the option to export the data. This saves the data from that list in a text file. You can use this to make a graph of infection rates:

a) Export both lists as text files.

b) Open Excel with a new spreadsheet.

c) Open the two text files you've exported using something like Notepad or Word (double-click the file and see what options you get). Select the data in the timer file and copy it. Go to Excel, select the top-left cell and paste the data - it should put it into the "A" column for you. Now repeat with the infected numbers dataset and the "B" column.

c) Now, in Excel, select the data and go to the "Insert" tab on the ribbon. Click the arrow below "Scatter", and then choose a graph with smoothed lines and dots on it. You should see something like this:

Screenshot: Excel graph

 

Say each infected sprite infects another at a rate of one a second, and newly infected sprites can infect other sprites as well, what kind of graph might we expect for such a model? Why don't we get this graph in practice? How might this be reflected in the infection rate in a real disease, and how might we control real diseases?

 

When you're done head back to the start page.