# My crude attempt at the SIR model

**URL:** https://discourse.julialang.org/t/my-crude-attempt-at-the-sir-model/33919
**Category:** Offtopic
**Created:** [January 29, 2020, 8:29am UTC](https://discourse.julialang.org/t/my-crude-attempt-at-the-sir-model/33919 "2020-01-29T08:29:06Z")
**Posts on this page:** 10
**Page:** 2

<div class="post-metadata">

### Author: ![StevenSiew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensiew/32/218393_2.png) [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)
#### Post date: [February 22, 2020, 3:29am UTC](https://discourse.julialang.org/t/my-crude-attempt-at-the-sir-model/33919/21 "2020-02-22T03:29:12Z")

</div>

One word: **PANDEMIC**

Number of cases outside China

Date Predictions Actual Comments  
2020-02-21 1260 1378 under\_predicted  
2020-02-22 1386  
2020-02-23 1524  
2020-02-24 1675  
2020-02-25 1840  
2020-02-26 2022  
2020-02-27 2220  
2020-02-28 2438  
2020-02-29 2676  
2020-03-01 2937  
2020-03-02 3223  
2020-03-03 3536  
2020-03-04 3879  
2020-03-05 4255

y = 37.68\*exp(x \* 0.09116) + (-58.54)  
where x is number of days since 13th Jan 2020  
x == 0 at 13th Jan 2020

[https://www.worldometers.info/coronavirus/coronavirus-cases/#active-cases](https://www.worldometers.info/coronavirus/coronavirus-cases/#active-cases)  
look for “Total Cases excluding mainland China”  
it has both Linear and Logarithmic graphs

 ![Screen Shot 2020-02-22 at 3.56.25 PM](https://global.discourse-cdn.com/julialang/original/3X/3/0/30740b1bfc0dec91d6af231bf0e8220d4fe4d341.png)

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [February 22, 2020, 6:12am UTC](https://discourse.julialang.org/t/my-crude-attempt-at-the-sir-model/33919/22 "2020-02-22T06:12:29Z")

</div>

> [@StevenSiew](#):
>
> y = 37.68\*exp(x \* 0.09116) + (-58.54)  
> where x is number of days since 13th Jan 2020  
> x == 0 at 13th Jan 2020

```julia
julia> g(x) = 37.68*exp(x * 0.09116) + (-58.54)
g (generic function with 1 method)

julia> g(365)
1.063077455599333e16

```

😉

---

<div class="post-metadata">

### Author: ![StevenSiew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensiew/32/218393_2.png) [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)
#### Post date: [February 22, 2020, 10:26am UTC](https://discourse.julialang.org/t/my-crude-attempt-at-the-sir-model/33919/23 "2020-02-22T10:26:04Z")

</div>

> [@Tamas\_Papp](#):
>
> julia\> g(x) = 37.68\*exp(x \* 0.09116) + (-58.54)  
> g (generic function with 1 method)
> 
> julia\> g(365)  
> 1.063077455599333e16

**Oh come on!** Tamas Papp, you are an educated man and not a dum dum like me.  
You know that early in a pandemic, the growth is exponential but late in a pandemic the growth becomes a logistic function.

---

<div class="post-metadata">

### Author: ![mschauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mschauer/32/13946_2.png) [@mschauer](https://discourse.julialang.org/u/mschauer)
#### Post date: [February 22, 2020, 11:26am UTC](https://discourse.julialang.org/t/my-crude-attempt-at-the-sir-model/33919/24 "2020-02-22T11:26:35Z")

</div>

It is okay to discuss how to use Julia to let the data speak, but let’s not use this thread to try convince each other about how to assess a global health thread.

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [February 22, 2020, 12:44pm UTC](https://discourse.julialang.org/t/my-crude-attempt-at-the-sir-model/33919/25 "2020-02-22T12:44:35Z")

</div>

Sorry if I was coming across as sarcastic. I was just trying to highlight the fact that it is very difficult add value to this question without

1. a more detailed model (preferably grounded in science, even in a stylized form, driven by some model of transmissions, incubation periods, etc)
2. quantification of estimation uncertainty (this is key, and often neglected in news reports),
3. somewhat more micro-level data,
4. model checking (preferably, posterior predictive checks).

In particular, just doing a simple log-linear transformation and estimating the 2–3 parameters is going to give a very poor predictive model.

I don’t know how much detailed data is accessible about this subject, but for the rest, Julia has great tools for answering these questions. For example, for using a simple model based on ODEs,

> **[GitHub - SciML/DiffEqBayes.jl: Extension functionality which uses Stan.jl,...](https://github.com/SciML/DiffEqBayes.jl)**
>
> Extension functionality which uses Stan.jl, DynamicHMC.jl, and Turing.jl to estimate the parameters to differential equations and perform Bayesian probabilistic scientific machine learning - GitHub...

would be a starting point.

---

<div class="post-metadata">

### Author: ![mschauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mschauer/32/13946_2.png) [@mschauer](https://discourse.julialang.org/u/mschauer)
#### Post date: [February 22, 2020, 12:58pm UTC](https://discourse.julialang.org/t/my-crude-attempt-at-the-sir-model/33919/26 "2020-02-22T12:58:41Z")

</div>

More starting points with BridgeSDEInference.jl addressing point 2: [BridgeSDEInference.jl/sir.jl at sir · mmider/BridgeSDEInference.jl · GitHub](https://github.com/mmider/BridgeSDEInference.jl/blob/sir/scripts/inference/sir.jl)

---

<div class="post-metadata">

### Author: ![StevenSiew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensiew/32/218393_2.png) [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)
#### Post date: [February 24, 2020, 1:02am UTC](https://discourse.julialang.org/t/my-crude-attempt-at-the-sir-model/33919/27 "2020-02-24T01:02:38Z")

</div>

People should be preparing for PANDEMIC

Coronavirus is going global and containment is no longer an option

The coronavirus containment has broken, with cases exploding across the  
world. Now experts have revealed what to do to prepare.  
Jamie Seidel  
news.com.auFebruary 24, 202011:10am

Coronavirus: Australia’s $2.3 billion epidemic

Billions of dollars are at stake for the Australian economy. Which  
industry will be most affected by coronavirus?

Coronavirus has broken containment. It’s exploding across the world,  
from Italy to Singapore, South Korea and Japan.

Now Australian medicos are sounding the alarm: we must prepare for this  
pandemic to strike home, Soon.

There’s been a profound shift in the Covid-19 epidemic.

Health officials are being taken by surprise. New cases of the virus  
are appearing seemingly everywhere. And not all of them can be traced  
back to travellers.

That means it’s already loose. Deep inside communities, such as Italy  
and Japan.

That means it’s entering a new phase.

Last week, the World Health Organisation (WHO) warned that the “window  
of opportunity” to contain the disease was narrowing.

But many epidemiologists fear that may have already passed.

It’s in hospitals. It’s in prisons. It’s on cruise ships.

It seems to be spread by carriers long before they show symptoms  
themselves.

And that makes the virus almost impossible to contain.

So how bad is it?

University of Queensland associate professor in virology Ian Mackay  
yesterday queried a disease risk-assessment think-tank. He wanted to  
know the most responsible way to discuss the worsening Covid-19  
outbreak.

So, he asked risk communicators Lanard & Sandman about whether it was  
time to start using the `P word’.

“Yes,” came the blunt reply.

“It is past time to say `pandemic’.”

The virus is likely to soon be loose in our own country, cities and  
towns.

ACTION STATIONS

The Centres for Disease Control (CDC) announced on Saturday it was  
initiating preparations for a “likely” spread of Covid-19 in the United  
States.

“We are reviewing all of our pandemic preparedness materials and  
adapting them to Covid-19,” an official told media.

On Sunday, Victoria’s Chief Health Officer Brett Sutton responded in  
kind.

“It’s clear that with local transmission in several countries that a  
pandemic is very likely, if not inevitable,” his official Twitter  
account reads. “We are working rapidly on planning and surge with our  
health sector.”

```
 Our latest analysis support that of @mlipsitch and colleagues: At
 least 2/3 of cases in travellers from China to other countries have
 likely been missed. Surveillance is never perfect.
 https://t.co/NXUHzdJkRz
 -- neil_ferguson (@neil_ferguson) February 21, 2020

```

A new assessment by the Imperial College London warns the outbreak is  
likely dramatically worse than believed:

“We estimated that about two-thirds of Covid-19 cases exported from  
mainland China have remained undetected worldwide, potentially  
resulting in multiple chains of as yet undetected human-to-human  
transmission outside mainland China.”

This is sending shockwaves through international health circles.

```
 In sum, many countries likely be dealing w COVID epidemic soon. They
 should be quickly preparing to deal, to do best they can w pt
 medical
 care, work to blunt overall impact, protect HCWs and keep health
 care system functioning safely, communicate clearly to public et al.
 16/x
 -- Tom Inglesby (@T_Inglesby) February 23, 2020

```

“In sum, many countries likely be dealing with a Covid epidemic soon,”  
responded the director of the Johns Hopkins Centre for Health Security  
in Baltimore, Tom Inglesby. “They should be quickly preparing to deal,  
to do best they can with medical care, work to blunt (its) overall  
impact, protect health care workers, keep health care system  
functioning safely and communicate clearly to the public.”

Risk group Lanard and Sandman say it’s important to point out that,  
while it looks like Covid-19 will go global, we don’t yet know how  
severe the disease is.

But, they add, the most “crucial (and overdue) risk communication task  
for the next few days” is to prepare the public for when the `keeping  
it out’ - containment - approach fails.

In other words, get ready for quarantine lockdowns.

`TAKE THE RISK OF SCARING PEOPLE’

“In most countries - including our United States and your Australia -  
ordinary citizens have not been asked to prepare,” Lanard and Sandman  
write. “Instead, they have been led to expect that their governments  
will keep the virus from their doors.”

But such expectations are set to backfire.

And the risk assessors warn concerned academics and medicos to stand  
resolute in the face of accusations of `fear-mongering’.

“Take the risk of scaring people … It is better to get through this  
OMG moment now rather than later,” they write.

"Respond that hiding your strong professional opinion about this  
pandemic-to-be would be immoral, or not in keeping with your commitment  
to transparency, or unforgivably unprofessional, or derelict in your  
duty to warn, or whatever feels truest in your heart.

“You’re only darned if you warn about something that turns out minor,”  
Lanard and Sandman write. “But you’re damned, and rightly so, if you  
fail to warn about something that turns out serious.”

Australian National University infectious disease specialist Dr Sanjaya  
Senanayake agrees it is time to get prepared. But not to panic.

“Even though we don’t know at this point whether or not a pandemic will  
occur, governments should be prepared for one and send out reassuring  
messages to the public,” he told News Corp last night.

He says indications are it will be a disruptive disease. But not  
devastating.

“While a lot isn’t known about this virus, at this stage it appears to  
cause mild illness in the majority of people with a low case fatality  
rate. So while it will cause disruption for a time to health services  
and economies, they will eventually recover as more and more people  
become immune.”

CHANGING TACTICS

The director of the Center for Communicable Disease Dynamics at Harvard  
University, Marc Lipsitch, says containment no longer appears to be an  
option.

Instead, countermeasures must be identified and implemented.

“Most things we can do to slow the virus’s spread - isolation,  
quarantine, social distancing, cancelling public gatherings, treating  
cases with antivirals - are temporary,” he wrote. “Once let up,  
transmission can resurge.”

When a disease is established in a community, international travel bans  
become pointless. Instead of slowing its spread, it makes it harder to  
bring in urgently needed supplies and support.

So, Lanard and Sandman write, public health messages must switch from  
`stopping them from infecting us' to `keeping us from infecting each  
other’.

That means cancelling mass events, considering school closures - and  
preparing for community lockdowns.

“We are near-certain that the desperate-sounding last-ditch containment  
messaging of recent days is contributing to a massive global  
misperception about the near-term future,” they write.

To counter this, public health officials should be talking about  
slowing the spread of the virus. Not stopping it.

“One horrible effect of this continued `stop the pandemic' daydream masquerading as a policy goal (is that) it is driving counter-productive and outrage-inducing measures by many countries against travellers," they write. "But possibly more horrible: The messaging is driving resources toward `stopping,’ and away from the  
main potential benefit of containment - slowing the spread of the  
pandemic and thereby buying a little more time to prepare for what’s  
coming.”

BUYING TIME

Lipsitch says slowing Covid-19’s spread will be difficult. Strict  
quarantine measures worked well for SARS in 2003 because isolating sick  
individuals prevented the disease from spreading.

Not so now.

“For Covid-19 it seems clear from individual well-documented cases that  
people can transmit before symptoms (become distinctive),” he wrote.  
“The key question - for which we (desperately) need good data - is  
whether this is common or rare. Some circumstantial evidence suggests  
it could be common.”

This limits the effectiveness of regular medical interventions. So  
practices such as social distancing (self-isolation), as well as  
“quarantine or lockdown” must be considered.

Slowing the spread of a virus through the community causes an epidemic  
to last longer - but with less `peak strain’ on health facilities.

"That is beneficial because: 1) fewer individuals get infected in  
total; 2) the burden on the health system is spread out, with lower  
peak demand for scarce resources; 3) we will know more as time goes on  
about how to care for patients, so it is better to get it late than  
early; 4) if we can spread it out enough there may be new drugs,  
vaccines, or other countermeasures to aid in preventing and treating  
infection.

“Summary: Delay is good.”

Another essential piece of unknown information is how the virus affects  
children.

So far, they seem strangely immune to Covid-19’s symptoms.

But are they innocent carriers?

“If kids are important for transmission, school closures may help; if  
not, less so,” Lipsitch writes.

And the delaying tactics are already producing results.

“Although a vaccine program is many months away, there are promising  
therapeutic options for treating people with the virus,” Dr Senanayake  
says.

BE PREPARED

In China, Covid-19 came from nowhere on January 1 to put the entire  
province of Wuhan in lockdown by February. Its rapid rate of spread can  
be seen again in Italy and Japan.

Can we cope?

“We’ve provided guidance to practitioners and many communications  
materials but are now focused on the models of care that will need to  
be in place - clinics, phone triage, home care, right through to ICU  
and aged care,” Sutton says.

```
 Without rapid diagnostics ready to go, healthcare infrastructure may
 become rapidly inundated, even if cases turn out all negative - an
 abundance of caution will require quarantines until test rules out a
 case. Any backlog can quickly hamper hospitals. 4/7...
 -- Michael Mina (@michaelmina_lab) February 23, 2020

```

“Victoria and Australia nonetheless remain completely in containment  
mode - identifying any possible case; isolating those who are  
infectious; and quarantining contacts. Regardless of developments  
internationally, this gives all of us time and space to plan and  
prepare.”

But the response must be at all levels, Inglesby warns.

“Given the developments and trends of last few days, it’s clear  
governments need to be working intently with hospitals and health care  
systems to prepare to take care of Covid patients, possibly in high  
numbers,” he says.

Key among concerning Covid-19 developments is the number of cases  
appearing in countries outside China. And many of these aren’t linked  
to travellers … indicating the virus is established in their general  
populations.

Inglesby says that, based on China’s experience, preparations should  
include:

o Preparing for a substantial increase in the numbers of patients who  
need oxygen and mechanical ventilation;

o Getting people with symptoms of Covid-19 diagnosed rapidly and  
correctly;

establishing the highest possible infection control procedures;

ensuring health care workers have high-quality personal protection  
equipment to keep them from being infected

o Preparing to give those with Covid-19 who are not sick enough to be  
in the hospital, instructions for home isolation and self-care, so they  
do not pose risks to hospitalised

o Evaluating whether there are public health interventions at community  
levels that might slow Covid-19 spread to create fewer numbers of very  
sick people all being in hospital at the same time

WHAT TO DO

Lanard and Sandman say preparedness advice must be spread: “Hardly any  
officials are telling civil society and the general public how to get  
ready for this pandemic.”

To allay panic, they say, health officials should be providing  
preparedness guidelines. This way worried people won’t be left feeling  
helpless. And the more people getting prepared, the more people will  
feel their community is ready.

“We are all stakeholders, and we don’t just want to hear what officials  
are doing. We want to hear what we can do, too,” they write.

"We want - and need - to hear advice like this:

o Try to get a few extra months’ worth of prescription meds, if  
possible.

o Don’t panic buy. But slowly build up your long-life grocery stocks to  
enough for a few weeks.

o Think through now how we will take care of sick family members while  
trying not to get infected.

o Cross-train key staff at work, so one person’s absence won’t derail  
our organisation’s ability to function.

o Practice touching our faces less. So how about a face-counter app  
like the step-counters so many of us use?

o Replace handshakes with elbow-bumps (the “ebola handshake”).

o Start practicing harm-reduction habits like pushing elevator buttons  
with a knuckle instead of a fingertip.

But the impact of a pandemic could also reach deep into businesses,  
supply chains and essential services.

“We have seen almost nothing in mainstream media citing this guidance,  
or recommending business continuity strategies like urgent  
cross-training so that core functions won’t be derailed because certain  
key employees are out sick, for instance.”

```
 I'm speaking to my CHO counterparts daily and briefing the sector -
 and indeed all sectors - through our emergency management
 arrangements, under @CommissionerEMV. This is critical - pandemics
 challenge all sectors with effects on supply, workforce and business
 continuity. (4/6)
 -- Chief Health Officer, Victoria (@VictorianCHO) February 23, 2020

```

That message is now starting to get out.

At least at a state level.

“Australia absolutely has world-class healthcare, but even the best  
healthcare in the world is challenged during pandemics,” Sutton says.  
“We’ve got some of the brightest minds in the world in our health  
services, laboratories, research sector and emergency management  
sector. I’m confident we’re well placed to meet the challenges ahead,  
whatever they might be. Hoping for the best and planning for the  
worst.”

Dr Senanayake agrees: “Again, it is important to communicate the  
message to the public that a pandemic doesn’t always mean a  
catastrophic outcome, especially since the majority of cases with this  
virus seem to be mild. It will certainly be an imposition, but likely a  
temporary one.”

---

<div class="post-metadata">

### Author: ![Albert\_Zevelev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albert_zevelev/32/11844_2.png) [@Albert\_Zevelev](https://discourse.julialang.org/u/Albert_Zevelev)
#### Post date: [February 24, 2020, 2:12am UTC](https://discourse.julialang.org/t/my-crude-attempt-at-the-sir-model/33919/28 "2020-02-24T02:12:49Z")

</div>

My understanding is that the mortality rate ~2.3%.  
Higher for elderly & those w chronic illness

[https://www.google.com/amp/s/www.forbes.com/sites/ninashapiro/2020/02/22/sex-does-matter-when-it-comes-to-coronavirus/amp/](https://www.google.com/amp/s/www.forbes.com/sites/ninashapiro/2020/02/22/sex-does-matter-when-it-comes-to-coronavirus/amp/)

---

<div class="post-metadata">

### Author: ![StevenSiew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensiew/32/218393_2.png) [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)
#### Post date: [February 24, 2020, 2:27pm UTC](https://discourse.julialang.org/t/my-crude-attempt-at-the-sir-model/33919/29 "2020-02-24T14:27:14Z")

</div>

**THERE WILL NEVER BE A PANDEMIC - WHO**  
[Link to Reuters article](https://www.reuters.com/article/us-china-health-who/who-says-no-longer-uses-pandemic-category-but-virus-still-emergency-idUSKCN20I0N8)

# WHO find a loop hole that enables them not to declare a pandemic. The classic goal posts moved approached. Brilliant.

NEW: WHO says it no longer has a process to declare a pandemic, says old system with 6 phases is no longer being used - Reuters

11:31 PM · Feb 24, 2020

THIS IS A HORROR MOVIE. THIS CANNOT BE REAL. I MUST BE DREAMING. YOU CANT MAKE THIS SHIT UP IN A FICTIONAL NOVEL. NO ONE WILL BELIEVE YOU!

Postscript: Next week, WHO will change the definition of DEATH

---

<div class="post-metadata">

### Author: ![klaff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/klaff/32/7637_2.png) [@klaff](https://discourse.julialang.org/u/klaff)
#### Post date: [March 12, 2020, 3:01am UTC](https://discourse.julialang.org/t/my-crude-attempt-at-the-sir-model/33919/30 "2020-03-12T03:01:38Z")

</div>

[https://www.ijidonline.com/article/S1201-9712(20)30117-X/fulltext](https://www.ijidonline.com/article/S1201-9712(20)30117-X/fulltext)

And a start at their model:

```julia
using DifferentialEquations, Plots

function corona!(du,u,p,t)
    S,E,I,R,N,D,C = u
    F, β0,α,κ,μ,σ,γ,d,λ = p
    du[1] = -β0*S*F/N - β(t,β0,D,N,κ,α)*S*I/N -μ*S # susceptible
    du[2] = β0*S*F/N + β(t,β0,D,N,κ,α)*S*I/N -(σ+μ)*E # exposed
    du[3] = σ*E - (γ+μ)*I # infected
    du[4] = γ*I - μ*R # removed (recovered + dead)
    du[5] = -μ*N # total population
    du[6] = d*γ*I - λ*D # severe, critical cases, and deaths
    du[7] = σ*E # +cumulative cases
end

β(t,β0,D,N,κ,α) = β0*(1-α)*(1-D/N)^κ
S0 = 14e6
u0 = [0.9*S0, 0.0, 0.0, 0.0, S0, 0.0, 0.0]
p = [10.0, 0.5944, 0.4239, 1117.3, 0.02, 1/3, 1/5,0.2, 1/11.2]
R0 = p[2]/p[7]*p[6]/(p[6]+p[5])
tspan = [0.0, 365.0]

prob = ODEProblem(corona!, u0, tspan, p)
@time sol = solve(prob, Tsit5())
plot(sol, vars=[2,3,4])

```

[Previous page](https://discourse.julialang.org/t/my-crude-attempt-at-the-sir-model/33919.md?page=1)
