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

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

  • Merry Holidays!

    I had a good Christmas this year. It began with a week of continuous snow fall. We’d have 3-6 inches here and there with warm days compacting the wet and heavy accumulation. But all of that still adds up so that by the time Christmas rolled around, the snow was over a foot deep in parts of our yard. Meanwhile the mountains have been getting hammered. Moscow Mountain has over 40 inches in the upper elevations, Brundage has over 90 inches at the summit, and I’m not sure of the current depths at Freezeout and Lolo Pass as the snotels…

  • Publications

    I don’t usually like to gloat about my accomplishments, but sometimes a little self promotion doesn’t hurt. I’ll start with the announcement of my first publication, which officially rolled off the presses last month. Last year, our lab was contacted to write a book chapter in a methods and protocol book on assessing anxiety behaviors in Zebrafish. So Barrie, Maia, Mary, and I set out to publish our behaviortyping protocol for assessing observer preference, depth preference, and feeding latency for high-throughput experiments. Robison, BD, MJ Benner, ML Singer, ME Oswald. A High Throughput and Inexpensive Assay for Anxiety Related Behaviors…

  • Puppies for Sale

    The puppies are now over 8 weeks old and oh so cute. As you can imagine, seven growing pups indoors can create quite a mess that is hard to keep on top of. On top of that, any time you step into their room, they all mob you for attention. So, as spring weather has descended upon the Palouse, we found scrap lumber and fencing and built an outdoor playpen for the dogs. So far it is doing the job. It’s also giving the pups some much needed fresh air and sunshine, which in turn tires them out so all…

  • 5000 feet

    It snowed in Moscow for the first time this season on Thursday. And although the accumulation didn’t amount to much in town, the mountains were turned white the next day. But two days of sunshine, and evidence of the snow is all but gone. The mountains around Moscow are back to their baren self. But at 5000 feet, winter has begun. Today I drove up to the Bald Mountain lookout tower on Palouse Divide, mostly to find a geocache, but also to enjoy the view, hike in the forest, and see just how much snow may have fallen at higher…

  • The Last One

    Since last week, we had been down to three puppies. Three is much more manageable than seven, but still a crowd. In fact, having two out at a time was still a handful. Tuesday, I made up posters advertising the rest of the pups, and in less than 24 hours, we had two more sold. This left us with one Pink Girl to care for. Having one puppy isn’t so bad. They’re a lot more mellow by themselves, they don’t eat as much, and most importantly, there’s not as much pee and poop to clean up. Of the three that…