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

  • It’s going to be a busy semester

    Somehow,  I had arranged the semester to be fairly light allowing me to work on my research. I was only signed up for one class, the work of which parallelled the work I have to do for my degree, namely write up a dissertation project proposal. On top of that, I was slated to teach one lab section, so overall my class and teaching load would be light. Funny how things actually work out. I am taking 3 classes, though one not for credit, and teaching two sections of lab. 314 lab isn’t really that bad, it’s all computer-based, but…

  • |

    The latest hype in Moscow

    The latest rage in Moscow, Idaho is the sighting of an immigrant that shouldn’t be here. A Northern Hawk Owl (Surnia ulula) has been spotted in Moscow across Rt. 8 from the Safeway parking lot. The earliest sightings on eBird show that this individual has been hanging around since Tuesday, reliably in the same spot. This is an exciting discovery because the Northern Hawk Owl isn’t supposed to be seen this far south. It’s native range is exclusive to Canada, and visits to the United States are few and infrequent. It’s unclear at this time how long the owl will…

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

  • 2013: A Retrospective

    For all intents and purposes, 2013 was a shitty year. Just when we thought things couldn’t get any worse, something else would go wrong. And, so the trend continued until the final months. The year started out pretty good. Though we’ve been struggling financially since Erin lost her nursing job in 2011, by the fall of 2012, she had a job and had enrolled at the University of Idaho to finally earn a bachelor’s degree to get her into a new career field.  With snowshoes and a new (to me) pair of skis I acquired from the WSU swap in…

  • Spring has Sprung

    Spring is officially here on the Palouse, as temperatures soar to almost 80 degrees and graduation season is upon us. The University of Idaho had its commencement yesterday, though I did not attend. This marks the end of my first year in graduate school, and so far it has been a success. But this summer, I’ll be finishing up some projects in the lab and really hammering out ideas for my own disseration. Of course, the summer is not completely for work. I’ll be planning a few backpacking trips and other expeditions to explore the landscape around me. The real…

  • | |

    Exploring

    The past week, my parents were in town visiting and we spent the week exploring and showing them our favorite places in the area. We’d usually leave fairly early in the morning and get back kinda late, always exhausted. As a result, I haven’t been able to post some detailed updates on the awesome places that we’ve been. I’ll try to summarize the week here. Saturday, July 23: Picked my parents up from the Lewiston airport. Turns out, there was some kind of airplane festival going on so we decided to have a look. There were planes out on the…