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

  • What have I been up to?

    It has been quite some time since I last made a post here, so I’d say I’m a bit overdue for an update. For the past two and a half years, I have been living in northwestern North Dakota. Saying this is an adjustment is an understatement. North Dakota is considerably flatter than any place I’ve lived, and there are almost no trees here. Winters are extremely harsh and long. We can have weeks where the daytime high does not exceed 0º F, and the wind will send a chill to your core. Our corner of the state doesn’t get…

  • LaTeX

        This semester, one of my classes has required me to turn in all of my assignments in LaTeX. LaTeX (la-tek) is built on TeX, a typesetting language meant to produce beautiful documents reminiscent of the days when papers were printed from engraved plates. Typesetting was an art that got lost in the digital age. When I first got the news that assignments were to be handed in using LaTeX, I admit I was a bit worried. The assignments were already going to be difficult enough since it is a bioinformatics class working with data types I have not…

  • Memorial Day Weekend and more

    On top of The World Originally uploaded by Matthew Singer. Its Memorial Day Weekend already! My how time flies. There’s been a lot happening lately, and between illnesses and deaths in the family, I haven’t been out exploring and backpacking as much as I would have liked. I’m finally going to get out on my three-day weekend. I will be hiking the Three Ridges Wilderness loop with two nights out on the trail. Next week, Erin and I leave for Las Vegas for a friend’s wedding. I’m more excited about our week at Zion National Park after all the festivities….

  • |

    Daffodils in the Snow

    Daffodils in the Snow, originally uploaded by Matthew Singer. I’ve heard of April showers bringing May flowers, but what do April snows bring? On Friday, I awoke to a white world with about an inch of snow covering everything. It was kind of a shock considering only a week before, there were promising signs of Spring. Of course, after the snow, the temperatures are back up and the weekend’s forecast is quite pleasant.

  • First Snow

    First Snow, originally uploaded by Matthew Singer. On Friday, I woke up to find a light layer of white on everything. At first, I thought it was a heavy frost, but when I put my glasses on, the truth was revealed. We had our first snowfall. It wasn’t much, less than an inch, and by late afternoon, all was gone. It wasn’t the first snow of the season either, but it was the first to stick on the ground, especially at our elevation. But Sunday night, it began to snow some more, and the accumulation was greater. It still wasn’t…

  • |

    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…