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

  • I went to Florida

    I went to Florida, originally uploaded by Matthew Singer. Taking a break from the usual trips into the mountains, I went to Florida last weekend to celebrate the marriage of one of my good buddies. The wedding was in Pensacola Beach, with the actual ceremony on the beach outside of town. I’ve been to Florida before, but not the Gulf coast, and especially not the panhandle, and so when I got there, I was quite surprised at just how built up it was. When I think of Florida, it’s usually the Tampa/Orlando area, which I try to avoid, or the…

  • Bad Ass Sunset

    Last night was full of bad-assery. Yeah, that’s right, it was so bad-ass that I made up a word to describe it. After a cold spell, temperatures quickly rose into the 80’s yesterday making for a hot and somewhat muggy day. The conditions were ripe for evening thunderstorms. As I arrived home, I heard reports on the radio that there were some severe storms just west of Orofino. But looking around, all I saw was sunshine and blue skies. The storms were passing to the south of us. As I was washing my car, dark clouds crept in over the…

  • The New Kitchen

    Three months ago, we had some pipes leak in our kitchen that caused some damage to the flooring and the cabinets and resulted in us basically getting a brand new kitchen. We contacted State Farm to see about getting any coverage, and thankfully, they agreed to help cover some of the damage. So, we set about getting a contractor in to look at the damage and give us an estimate. We ended up using one that works directly with State Farm, a decision that may have caused us more strife that we were hoping to avoid, but after several delays,…

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

  • |

    A Walk Around the Yard

        When you live somewhere long enough and see the same scenery day after day, you sort of become numb to it. It no longer thrills you the way it did when you first moved in. That’s sort of how I feel. Don’t get me wrong, I love my house and its location, but it feels like I could have better scenery out my window living somewhere else. The scenery here is never actually dull. I’ve got a great view of Spud Hill, Deary’s local “mountain” that stands over 1000 feet above the town, and most evenings, we get…

  • A Spiritual Moment

    My trip to the Redwoods had a profound effect on me. I can’t really explain what it was or why. I’ve been to many amazing and beautiful places never come back as humbled and rejuvenated as I had on this last trip. But everything about it just put me at ease and at awe. It was a combination of spending time with the kids while experiencing a mature old-growth forest among some of the oldest and tallest trees on the planet. I came back to Williston ready to take on the world and maybe inspired to leave in search of…