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

  • Yes, I’m still alive.

    It’s been a long time since I’ve posted anything here. The purpose of this post is the reassure you that I’m still alive and kicking. There haven’t been many adventures and photo outings this winter for a number of reasons, the least of which is that it’s been a pretty lackluster winter in terms of snow fall. But I’ve also been busy with school and work and raising a child, and those add up. But as the snow melts and spring takes over the Palouse, I hope to get out more and stay active. So stand by and keep watching…

  • An update for 2018

    It’s occurred to me that I haven’t been good at writing posts recently. My last update was from May, and that was subsequently my last big hiking trip. Since then, I have been incredibly busy, and that means I haven’t had as much time for fun. I did get out a few times this summer with the family. But there’s a lot to talk about. So here’s what happened in 2017. I successfully defended my Ph.D. dissertation. On December 14, I defended my dissertation in front of my committee. This is why I haven’t been very active this year. I…

  • Hard drives and data storage

    I’ve come into a real conundrum lately. I’m running out of space on my hard drive. Earlier in the year when I thought my hard drive was dying, I bought an external drive which I use to move old files for storage and back up my current system. The problem is that using the external hard drive as a working drive is not an ideal solution when my primary (read: only) computer at the moment is a portable notebook. Thus, I don’t want to be using the external hard drive to store all of my music and photography, the two…

  • Illinois

    On Mount Moosilauke Originally uploaded by mineral2. I’m in Illinois now and will be here for a good majority of the year. While I’m living 40 miles in the Chicago suburbs, I’ve already taken a trip to the Mississippi River to see the Bald Eagles and am planning a weekend to Nebraska to watch the mass of Sandhill Cranes as they stopover on their migration north. As the spring approaches, I hope to go south to some terrain that is reminiscent of Alabma. I also plan to go northward to view the waterfowl and the flowers of the North Woods….

  • Perseoids

    Every summer at early-mid August, we enter a portion of the solar system rife with meteors, and ever year around this time, many of those chunks of rock and debris hit our atmosphere and burn up, giving us the Perseoid meteor shower. This year, the shower did not occur during a full moon, and so the skies were dark and the stars were bright. Some of the photo club folks wanted to have a camping trip this weekend, and that devolved into a fire and star photography night at our place. The meteor shower was pretty good Saturday night. There…

  • Happy March

    Wow, it’s March already. Yesterday, it began to snow. Let’s back up, all of last week, it snowed. We may have gotten a good combined foot of fresh, fluffy powder. We got a bit of a break over the weekend. Sunday it snowed a bit, but the accumulation wasn’t siginificant. But yesterday, it began to snow. In the course of the day, I probably blew 8 inches off the driveway, and the snow wouldn’t let up. This morning, I woke up to find that all my hard work of keeping the driveway clear was erased with potentially another 6-8 +…