# Help me model event of pandemic proportion

**URL:** https://discourse.julialang.org/t/help-me-model-event-of-pandemic-proportion/33831
**Category:** Offtopic
**Created:** [January 27, 2020, 1:13am UTC](https://discourse.julialang.org/t/help-me-model-event-of-pandemic-proportion/33831 "2020-01-27T01:13:50Z")
**Posts on this page:** 8
**Page:** 1

<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: [January 27, 2020, 1:13am UTC](https://discourse.julialang.org/t/help-me-model-event-of-pandemic-proportion/33831/1 "2020-01-27T01:13:50Z")

</div>

Please help me model the event of  
global cases of coronavirus with  
a Logistic function.

I am trying the find the values of these three parameters

1. L
2. X0 (X\_zero)
3. k

 ![IMG_6571](https://global.discourse-cdn.com/julialang/original/3X/e/c/ecb14c00e6566bf28ae30797e4d350868925b002.jpeg)

```julia
$ cat data.txt
17.0,41.0
19.0,62.0
20.0,201.0
21.0,291.0
22.0,440.0
24.0,830.0
25.0,1287.0
26.0,1975.0

```

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [January 27, 2020, 1:22am UTC](https://discourse.julialang.org/t/help-me-model-event-of-pandemic-proportion/33831/2 "2020-01-27T01:22:19Z")

</div>

According to desmos, L is around 6000.

---

<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: [January 27, 2020, 1:23am UTC](https://discourse.julialang.org/t/help-me-model-event-of-pandemic-proportion/33831/3 "2020-01-27T01:23:43Z")

</div>

Only 6000? That’s not much of a pandemic. Latest figures

[https://www.scmp.com/news/china/scie…onavirus-china](https://www.scmp.com/news/china/science/article/3047709/genetic-and-drug-trail-contain-deadly-coronavirus-china)

Total 2748 cases including 80 deaths (CHINA)  
Total 2806 cases including 80 deaths (GLOBAL)

… (and also discuss the antivirals being trialed)

The National Health Commission said that  
[a combination of antiretroviral drugs used to treat HIV – lopinavir and ritonavir – had been given to some patients](https://www.scmp.com/news/china/society/article/3047667/china-coronavirus-beijing-confirms-use-anti-hiv-drugs-some)  
infected with the Wuhan coronavirus at three of the capital’s hospitals…

---

<div class="post-metadata">

### Author: ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)
#### Post date: [January 27, 2020, 1:44am UTC](https://discourse.julialang.org/t/help-me-model-event-of-pandemic-proportion/33831/4 "2020-01-27T01:44:12Z")

</div>

maybe using the [SIR](https://www.maa.org/press/periodicals/loci/joma/the-sir-model-for-spread-of-disease-the-differential-equation-model) model?

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [January 27, 2020, 1:44am UTC](https://discourse.julialang.org/t/help-me-model-event-of-pandemic-proportion/33831/5 "2020-01-27T01:44:34Z")

</div>

Agreed, however this curve fits pretty well. [Coronavirus](https://www.desmos.com/calculator/x4sqsc8naw) R^2=.998. Much of the problem will be that the Chinese government is somewhat notorious for lying about disease spread to make things look better than they really are. This might be a case of GIGO

---

<div class="post-metadata">

### Author: ![jebej](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jebej/32/1784_2.png) [@jebej](https://discourse.julialang.org/u/jebej)
#### Post date: [January 27, 2020, 2:43am UTC](https://discourse.julialang.org/t/help-me-model-event-of-pandemic-proportion/33831/6 "2020-01-27T02:43:19Z")

</div>

Fitting for the maximum value is pretty useless with data like this. You would need to be able to see the data curve down to make this prediction. (e.g. it still fits with L=1E9, [Coronavirus](https://www.desmos.com/calculator/ggpijibn4a)).

---

<div class="post-metadata">

### Author: ![jebej](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jebej/32/1784_2.png) [@jebej](https://discourse.julialang.org/u/jebej)
#### Post date: [January 27, 2020, 3:18am UTC](https://discourse.julialang.org/t/help-me-model-event-of-pandemic-proportion/33831/7 "2020-01-27T03:18:48Z")

</div>

To answer the question, this is how you would fit this in julia:

```julia
julia> using LsqFit

julia> d = [17,19,20,21,22,24,25,26];

julia> C = [41,62,201,291,440,830,1287,1975];

julia> model(x,p) = @. p[1]/(1+exp(p[2]*(p[3]-x)));

julia> fit = curve_fit(model,d,C,[10000,0.5,10]);

julia> coef(fit)
3-element Array{Float64,1}:
  3.2851466556639015e6
  0.40385634551986366
 44.38662397812089

julia> confidence_interval(fit, 0.05)
3-element Array{Tuple{Float64,Float64},1}:
 (-3.1459929604011664e9, 3.1525632537124944e9)
 (0.27660508963623914, 0.5311076014034881)
 (-2336.174503656719, 2424.947751612961)

```

Interestingly we get a different value for L, not sure why. However, as expected, the confidence interval is huge, showing that this parameter is not important to the fit.

Note that LsqFit currently returns symmetric confidence intervals, which is why the lower bound makes no sense here.

---

<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: [January 27, 2020, 4:30am UTC](https://discourse.julialang.org/t/help-me-model-event-of-pandemic-proportion/33831/8 "2020-01-27T04:30:00Z")

</div>

> [@jebej](#):
>
> confidence\_interval(fit, 0.05)

Thank you, I got it

```julia
using LsqFit, CSV, DataFrames

csv = CSV.File("/Users/ssiew/juliascript/coronavirus/data.txt")
df = DataFrame!(csv)

day = df[:,:day]
cases = df[:,:cases]

model(x,p) = @. p[1]/(1+exp(p[2]*(p[3]-x)));
fit = curve_fit(model,day,cases,[10000,0.5,10]);

parameter = coef(fit)
conf_interval = confidence_interval(fit, 0.05)
display(parameter)
display(conf_interval)

```

```julia
$ cat data.txt
"day","cases"
17.0,41.0
19.0,62.0
20.0,201.0
21.0,291.0
22.0,440.0
24.0,830.0
25.0,1287.0
26.0,1975.0
27.0,2806.0

```
