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

  • |

    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…

  • |

    Aurora

      This story begins Friday night when I learned that a large coronal mass ejection (CME) sent a burst of solar radiation from the sun headed toward Earth. It was predicted to intercept our atmosphere on the evening of the 8th, producing auroral activity in the high latitudes. Given the size of this solar storm, as described by spaceweather.com, I was a bit suspicious that the auroras migh be big enough to see all the way down here in northern Idaho. So, I kept a watch looking for evidence of such activity. On the evening of the 8th, I checked…

  • Jerry Johnson

    We’ve gotten a lot of snow this winter. And then it got cold. Like, really cold. Night time lows below zero, and daytime highs hovering around 20.  So the only thing to do with this kind of weather is go swimming. Last year, we took Clara to a developed hot spring near McCall and she loved it. This year we decided to give the undeveloped hot spring a try. Spoiler: She had a blast. Our biggest concern was keeping her warm during the one-mile hike to and from the springs. She did fine in her little blue down suit, but…

  • |

    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…

  • A new Mineral2.com

    For the longest time, I have been wanting to re-design my site to make it easy to update and manage content. At first, I thought a content management system would suit me, but I found them to be a bit daunting. Perhaps later I’ll re-visit the idea, but for the amount of content that I actually publish, a blogging platform would do me much better. I still have the photography up using Gallery2 and the main website is now using WordPress. I figured if I’m going to provide stories and updates, I might as well do it in blog form…

  • Camping at Hazard Lake

    In May we bought a new tent to accommodate our growing family on camping trips. I guess the two-person backpacking tent just won’t do it anymore for thee people and two large dogs. So after we bought it, we took it out for its maiden test at a nearby campground. This summer was dubbed the summer of no fun. I was busy writing and Erin was working an internship. To make the summer a bit more bearable, we thought we’d go camping for a night or two once a month just to get out of the house and have some…