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

  • |

    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…

  • Photography

    Grafton Street, Dublin Originally uploaded by mineral2. I’m scanning old photos again. Its the first time in probably a month since I’ve been archiving photos. I skipped over a few and am doing a more “recent” set from the summer of 2001. Ireland. Its 6 rolls of color and one of black and white. I’ll probably post a few up here as I scan them, but expect the full set on the website when they are all completed. To scan after this: London 1999, 2000; Scotland 1999; Drew University 2000, 2001 and some random bits in between.

  • The Baby

    Mother and Child, originally uploaded by Matthew Singer. We had a baby. And by We, I mean Erin. And by Erin, I mean her horse. Thursday night (Friday morning) around 12:30, we went out to check on Mae and turn in for the night, but we heard groaning and grunting coming from the barn. So, Erin rushed up to see if she had gone into labor, and indeed she had. I grabbed boots and the camera and headed up. At first, there was just a hoof sticking out from Mae’s behind. Then she laid down and gave a few pushes….

  • |

    Nostalgia

    times square, originally uploaded by Matthew Singer. I’m going to start this post by sharing a few photos I shot on Kodak T-Max black and white film way back in 2001 during my freshman year of college. Film. Back then, my little school of 1600 had a darkroom that the photo club and art department shared. It was in the basement of one of the dorms. When the art department got its brand new building, it got a brand new state-of-the-art darkroom, and the club took complete ownership of the old darkroom. I’m not sure what’s left of the facility…

  • Elk Creek Falls

    I think I’ve mentioned Elk Creek Falls in passing, but haven’t actually written a featured post about it. Elk River is a small outdoor recreation town (read: hunting & fishing mostly) a little over an hour east of Moscow. This small community represents the “end of the road.” The paved road ends here and forest service roads pick up to take you into some remote places. While most people come back here to hunt, ride ATVs and snowmobile in the winter, there are some family-friendly hikes and other attractions that make Elk River worth a visit. There’s the giant cedar,…

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