My aim is to show how the percentage of immunisation affects the amount of infected. |
Yes, but I still don't see why you would be interested in finding out by a long winded simulation that an immunisation rate of 37% results in an infection rate of approx. 63%. In other words - all persons not immunized will get infected sooner or later in the long run. Deviations from the ideal line are due to the mentioned effects when unvaccinated people or the first infected person are surrounded by immunized.
I haven't used your sheet to obtain the results and thats one reason for not attaching it. I would not be patient enough to wait until a simulation, where every immunization rate would be averaged over 1000 runs, finishes with a grid bigger than 10x10 (as in the first pic).
Did you already change your iteration/infection routine?
You should build more function which should be dependend on all variables you would like to change later and they should not rely on calculations made outside the program. That way you can easy use them in loops or plotting functions.
As a hint a list of the functions I used in my sheet:
- make_grid(n,p,inf) ... returns a n x n matrix with p percent immunized and inf is the numer of initial infected people
- step(grid) ... takes the matrix grid, applies the infection algorithmus and returns the newly derived matrix
- steps(n,grid) ... routine which calls step() n-times; used for the animation
- make_points(grid) ... creates the datastructures needed for the graphical representation of the grid; used for animation
- infected_at_end(grid) ... will call step as long as the number of infected person changes and then returns the number of infected persons at the end
- count(nr,M) ... returns how often nr is found in matrix M
To plot the infection rate at the end over the immunization rate, I used the following

BTW, I had an error in my Infected() routine and so the plots in my previous post are wrong. They would all look more or less like the above and it seems that the effect for higher immunization rates of groups of healthy people being fully surrounded by immunized ones is getting bigger with growing poulation size (see below for poulation size 400). So you can't cope this with averaging over 1000 runs as for higher immunization rates and greater population (say 75% and 30x30) it will happen nearly all of the time. The pic below with all those islands of healthy and islands of infected people being separated by immunized ones is typical, not an outlier. But then - would this have much meaning for real life?
