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

  • Babies

      Out of nowhere, our dog population has increased four fold. Here’s the back story. Several weeks ago, I came home to find two extra dogs at the house. They were two German Shepherds, a male and a female, that Erin had decided to watch for a friend while she got on her feet and found a place to live with her dogs. Four big dogs in our tiny house is a bit much, and it didn’t help that the two we were watching were very active. Lana, the female, is a very nervous dog, especially around men, and she…

  • |

    Fireworks in the Mountains

    A garden update from the last post: I’m happy to announce that the lettuce that the chickens ate down to the soil is growing back quite nicely and will be ready for consumption within a few days. And now on to the main post: Elk River hosts an annual Independence Day celebration they call “Fireworks in the Mountains,” but they don’t necessarily hold it on the 4th of July, but on the weekend before or after if the 4th happens to be mid-week. The event attracts a lot of people and the general store stays open late to sell its…

  • October Update

    Where has time gone? It’s already October, which means I missed out on September. Well, I didn’t really miss it. I was busy with a graduate school ritual known as the preliminary examination. Prelims are, without a doubt, the most stressful event for a graduate student. You might think it’s writing the dissertation or even giving your final defense. The truth is, by that time, you know your subject inside and out. Writing takes time, and the stress is making the deadlines, but overall, unless you slept through your graduate student experience, writing up the dissertation isn’t that difficult. The…

  • 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…

  • I wish I had my Camera with me

    One of the properties of Moscow is a wet winter and spring. We’re close enough to the coast to get the rainy weather patterns, yet far enough inland to incur the effects of the Cascades rain shadow. Though I suppose being at the foothills of the next major mountain divide, it’s only natural for the moisture to build up and then drop before passing into Montana. The rain here is more of a constant drizzle than the short, hard rains we’d get in the summer in the Appalachians. The drizzle will last all day. It’s the sort of grey rain…

  • |

    The Ski Trip to End All Ski Trips

    February 17th began as any other trip to McCall. I rolled out of bed around 5:00 am, packed the car with my gear, and 20 minutes later, I was leaving for Moscow to meet up with Tyler and Genevieve. We made it to Brundage around 10:30 local time and headed straight to the Centenial chair where we met up with Chloe, Ben, and some of Chloe’s family. We had a good day on the mountain, but stuck to the groomed runs and trails because there hadn’t been any fresh powder in over a week.The first thing we noticed was how…