Why you’re working from home, Part 2: A Shiny Model

Immediately after I published my last post, I wasn’t content with the manner in which I conveyed the SIR model. Simply posting graphs from scenarios that I ran isn’t exciting. It’s passive, and it doesn’t actively demonstrate for the reader how social distancing does work to reduce infection rates. I wanted something interactive. Something that you, my readers, can play with. So I built the model in Shiny.

Shiny is a tool for R that makes data visualization interactive. I had never used Shiny. But with a few hours of reading the introductory tutorial, I had my own custom application built with a basic SIR model. And I’m ready to share it with you.

As a reminder, here is our basic model, graphically and mathematically with a description of the parameters:

 \frac{dS}{dt} = -\frac{\beta I S}{N} \newline \frac{dI}{dt} = \frac{\beta I S}{N} - \gamma I \newline \frac{dR}{dt} = \gamma I

The parameters are \beta, a composite that includes the probability any one person interacts with another and the probability that successful transfer occurs with an interaction; \gamma, a composite that includes the probability an infected individual recovers or dies (from the disease or naturally); S, I, and R, the number of susceptible, infected, and removed individuals; and N, the total population size which should be equal to S + I + R.

Here’s how you can play with my interactive model. If you are an R user, grab the code here: https://github.com/matthew-singer/ShinyToys. The file you want is called sirapp.r. You will need to install the shiny package, but it’s worth having.

If you are not an R user, you can play with the app which is hosted here: http://mineral2.shinyapps.io/SIRModel. If you are an R user, please download my script from the first link and run it locally because I only get 25 hours of active app time with my shinyapps.io account, and I’d like it to be available for educational purposes to non-science people.

Remember that social distancing acts to reduce the value of \beta. As you play with different scenarios, note that as \beta increases or decreases, what happens to the Infectious curve (Red)? Note the approximate time that infections peak, as well as the quantity of infections at peak.
How long does it take for the disease to disappear from the population? How does population size affect the response?

Remember that this isn’t an accurate model of COVId-19. It is a basic and generic model of infectious disease spread. However it is still useful in understanding how our collective and individual behaviors can affect the way diseases spread through the population.

Similar Posts

  • Garden Produce

    The tomato plants have fruit, but I’m awaiting them to ripen. The pepper plants are starting to produce. The strawberries are on their second round of harvest. In the mean time, the squash and zucchini are providing us with food of plenty. Yesterday I picked four zucchini, all from the same plant. This morning, I grabbed two more before leaving for work. This doesn’t include the half-dozen or so that we’ve already picked and are awaiting consumption in the kitchen. We’ve also got several variety of yellow summer squash as well as two green stripped squash/zucchini plants, both producing about…

  • Heading West

    The Palouse, originally uploaded by Matthew Singer. Holy Smokes, it’s March already? My how time flies. It’s funny how time goes by when life is mundane and you feel like you’ve wasted the days. On the other hand, when you’ve got something to look forward to, it just can’t come fast enough. I suppose I ought to let you, my readers, up to speed on my future. In January, I received a notice of acceptance to the University of Idaho. So last week, Erin and I went out that way to visit the school and the area. Long story short,…

  • |

    The Birds at our Feeder

    We get lots of birds in our trees in the front yard. This could be contributed to the source of food we are supplying to them. The list of winter birds is less than the summer residents. For example, I haven’t seen a bluebird in months, and most of the woodpeckers have left the yard too. And of course, the hummingbirds have gone since they don’t have the proper gear to tolerate the cold. But even with the few remaining species, watching the feeders has been a delight. In Idaho, we have the possibility to see four different kinds of…

  • The Last One

    Since last week, we had been down to three puppies. Three is much more manageable than seven, but still a crowd. In fact, having two out at a time was still a handful. Tuesday, I made up posters advertising the rest of the pups, and in less than 24 hours, we had two more sold. This left us with one Pink Girl to care for. Having one puppy isn’t so bad. They’re a lot more mellow by themselves, they don’t eat as much, and most importantly, there’s not as much pee and poop to clean up. Of the three that…

  • |

    Aurora, part II

    Well, I made my last post a bit too soon. After spending the evening on Freezeout Ridge (story and photos to come soon), Erin reminded us that the aurora might still be occuring and that we could possibly see it tonight. Clarkia isn’t the best place to test this hypothesis because its surrounded by tall mountains in all directions, so as we passed through Bovill, I noticed a glow on the northern horizon. At this point, it was only 10:00, still early enough that the glow could be residual light from the sun. I pulled the car over and set…

  • Flight Paths

    [map style=”width: auto; height:400px; margin:20px 0px 20px 0px; border: 1px solid black;” maptype=”ROADMAP” gpx=”http://www.mineral2.com/wp-content/uploads/Flights.GPX”] If you don’t already know me, I have a thing for maps and geography. It’s an absolute delight to see the landscape from the air. I’ve been bringing my GPS with me when I fly, mostly to keep track of flight progress and to identify what I’m seeing out the window. But it’s also interesting to see how the FAA routes flights. Spoiler Alert: it’s not a direct path between cities. The two tracks above show the flight path between Phoenix and Cancun in both directions….