Build an Epidemic Model (part 6 of 8)

Tagged:

Previous: Recovery (part 5 of 8)

Immunity

In many populations some individuals start out with some immunity to a disease. We can easily model that here, by giving some of the agents "immunity." We will create a new variable for each agent that can be set to True if the agent is immune to the disease, and False if the turtle can get sick. Go to the Variables tab and drag out a Agent Boolean block onto the Turtles space of the Canvas. You'll see that it gets labeled Turtles Agents Boolean. Change the name of this block to Immune by selecting and editing the Agents Boolean text.

Go to the My Blocks palette, open the Turtles tab and you'll see some new blocks there. These Turtles now have a new variable to work with, and you can get or set the Immunity variable with these blocks. We will set the Immunity variable to be true for some randomly selected turtles during Setup. Move to the Setup canvas section and grab a new If-Else block from the Logic tab. Attach the If-Else block beneath the Set Color block in the Setup block.

For the test condition, make it say random 100 <= 10, using the same structure as you did for the Infect block. Grab one of the new Set Immune blocks from the Turtle's tab and place it in the Then part of the If-Else block. Go to the Factory palette, click on the Logic tab, and drag out a True block to connect it to the Set Immune block. The first part of the block says with a 10% chance, a turtle agent sets the Immune variable to True (indicating immunity).

Get a second Set Immune block from the Turtles tab and attach it to the Else part of the If-Else block. Click on the Logic tab, drag out the False block and connect it to the Set Immune block. This says, if a turtle agent didn't get selected to be immune, the agent sets its Immunity variable to False. The Setup block should now look like this:

Now we have created some immune agents that are roughly 10% of the population. But they won't know what being "immune" means until you define it. Go to the Turtles section of the Canvas. Drag out a new Procedure block (like you did with Recover) from the Procedures tab. Rename the procedure Check for Immunity.

Get a new If block and attach it to the Check for Immunity procedure. For the test, get an = block from the Logic tab and then insert an Immune variable value from the Turtles Drawer (My Blocks palette) on the left side of the = block. Fill the right hand side with a False block (from Logic tab). This will check to see if the Immune variable for an agent is False (meaning not immune). For the Then part, fill in Set Color Red. This will only turn non-immune (susceptible) agents red.

Finally, go to the collision block and drag the two Set Color Reds to the trash.

In their place, drag out two Immunity procedure call blocks from the Turtles Drawer (My Blocks palette).

Run the model and you should see fewer red agents then you did before.

Next: Part 7 of 8 - Monitoring the Situation Back To Top