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

  • Garden Produce

    The tomato plants have fruit, but I’m awaiting them to ripen. The pepper plants are starting to produce. The strawberries are on their second round of harvest. In the mean time, the squash and zucchini are providing us with food of plenty. Yesterday I picked four zucchini, all from the same plant. This morning, I grabbed two more before leaving for work. This doesn’t include the half-dozen or so that we’ve already picked and are awaiting consumption in the kitchen. We’ve also got several variety of yellow summer squash as well as two green stripped squash/zucchini plants, both producing about…

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

  • |

    My Research: What I have been up to

    Last week, the fruits of my last three year’s work has finally come to fruition in the journal PLoS One. The premise is that the personality behavior we call boldness, or the bold-shy continuum, is not only heritable, but a genetically correlated multivariate trait. The research is essentially a continuation of a project Mary Oswald completed for her dissertation, however upon first submission, reviewers criticized the study for its lack of replication. So, in the Summer of 2010, she set up a second selection experiment which I took over and have been maintaining since. Boldness is an interesting behavior to…

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

  • An update on the Hawk Owl

    It’s been over a week since a Northern Hawk Owl was spotted hanging out across a busy street from a shopping mall in Moscow, Idaho, but the bird is still here and reliably seen in the same locations. I’ve now seen the bird four times and may continue to watch and observe it until it is no longer a novelty. Of course, that might be all winter, and the owl might actually leave town before seeing it is no longer exciting. Today’s viewing was special. The sun came out and temperatures finally rose above freezing, making it bearable to actually…

  • Mount Rogers, VA

    Well, my time in Alabama has come to an end. To catch up on this thing, I spent the fall season at the McDowell Environmental Center as an educator down in northern Alabama. I enjoyed it so much that I returned for the spring season. The area is a sandstone highlands carved into canyons by the rivers. Its beautiful and biologically diverse and very interesting. I had a great birding season with 117 species this spring, lots of wildflowers, and good herping. The season ended May 19, and on Sunday the 21st, I headed north with Damascus, VA as my…