# Modelling COVID-19 in Julia and plotting AgentBasedModels on arbitrary networks

**URL:** <https://discourse.julialang.org/t/modelling-covid-19-in-julia-and-plotting-agentbasedmodels-on-arbitrary-networks/36005>\
**Category:** Modelling & Simulations\
**Created:** [March 15, 2020, 9:51am UTC](https://discourse.julialang.org/t/modelling-covid-19-in-julia-and-plotting-agentbasedmodels-on-arbitrary-networks/36005 "2020-03-15T09:51:40Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Post date:** [March 15, 2020, 9:51am UTC](https://discourse.julialang.org/t/modelling-covid-19-in-julia-and-plotting-agentbasedmodels-on-arbitrary-networks/36005/1 "2020-03-15T09:51:40Z")

</div>

Hi all!

Recently there was a paper introducing Pathogen.jl, which I found interesting. It is a Julia package for modelling disease spreading : [[2002.05850] Pathogen.jl: Infectious Disease Transmission Network Modelling with Julia](https://arxiv.org/abs/2002.05850)

One can also use DifferentialEquations.jl to model disease spreading, as mentioned in the article.

But one can also do Agent based modelling of disease spreading, so motivated by the recent situation, we also did a “toy model” for COVID19 in Agents.jl: [SIR model for the spread of COVID-19 · Agents.jl](https://juliadynamics.github.io/Agents.jl/dev/examples/sir/)

In doing so, we extended Agents.jl’s plotting capabilities to be able to plot any agent based model that is defined on any arbitrary network. It is still rough around the ages so let us know if you use it and how to improve it.

---

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [March 22, 2020, 4:36pm UTC](https://discourse.julialang.org/t/modelling-covid-19-in-julia-and-plotting-agentbasedmodels-on-arbitrary-networks/36005/2 "2020-03-22T16:36:13Z")

</div>

Thank you for putting this model together. I have found it very useful and interesting.

I have a question and a comment. First, how would you examine the effect of an intervention at different time steps, such as social distancing? Would you add a `model_step!` function that adjusts the parameters after a specified number of steps to implement the intervention?

I think there might be an error in the death rate calculations in `recover_or_die!`. The line `≥` in the line `if agent.days_infected ≥ model.properties[:infection_period]` should be changed to `=`. Otherwise, the patient will continue to die with the same probability after recovering.

Alternatively, you could find a uniform probability of death across the infection period like so:

```julia
1-(1-p)^N = .02
p = - 0.98^(1/N) + 1

```

Edit: I thought there was an error because the death rate in the results was higher than the nominal death rate of 2%. It exceeded 2% because of the reinfection probability \> 0. So there is no error.

---

<div class="post-metadata">

**Author:** ![johnh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnh/32/3615_2.png) [@johnh](https://discourse.julialang.org/u/johnh)\
**Post date:** [March 22, 2020, 6:26pm UTC](https://discourse.julialang.org/t/modelling-covid-19-in-julia-and-plotting-agentbasedmodels-on-arbitrary-networks/36005/3 "2020-03-22T18:26:26Z")

</div>

which version of Agents.jl is necessary here? I Cannot get the cenGraph type right.  
Agents 2.4.0 here

---

<div class="post-metadata">

**Author:** ![Iulian.Cioarca](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iulian.cioarca/32/30166_2.png) [@Iulian.Cioarca](https://discourse.julialang.org/u/Iulian.Cioarca)\
**Post date:** [March 22, 2020, 8:36pm UTC](https://discourse.julialang.org/t/modelling-covid-19-in-julia-and-plotting-agentbasedmodels-on-arbitrary-networks/36005/4 "2020-03-22T20:36:18Z")

</div>

I got: `LoadError: UndefVarError: GraphSpace not defined`  
EDIT: solved by adding `Agents#master`

---

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [March 22, 2020, 8:52pm UTC](https://discourse.julialang.org/t/modelling-covid-19-in-julia-and-plotting-agentbasedmodels-on-arbitrary-networks/36005/5 "2020-03-22T20:52:21Z")

</div>

On my system, it works with Agents 2.4 and AgentsPlots 0.2.1 .

---

<div class="post-metadata">

**Author:** ![johnh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnh/32/3615_2.png) [@johnh](https://discourse.julialang.org/u/johnh)\
**Post date:** [March 22, 2020, 10:06pm UTC](https://discourse.julialang.org/t/modelling-covid-19-in-julia-and-plotting-agentbasedmodels-on-arbitrary-networks/36005/6 "2020-03-22T22:06:07Z")

</div>

Thankyou. Agents#master ixes things for me

---

<div class="post-metadata">

**Author:** ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Post date:** [March 23, 2020, 12:46pm UTC](https://discourse.julialang.org/t/modelling-covid-19-in-julia-and-plotting-agentbasedmodels-on-arbitrary-networks/36005/7 "2020-03-23T12:46:54Z")

</div>

> [@Christopher\_Fisher](#):
>
> I have a question and a comment. First, how would you examine the effect of an intervention at different time steps, such as social distancing? Would you add a `model_step!` function that adjusts the parameters after a specified number of steps to implement the intervention?

Exactly. This one of the main scenarions `model_step!` targets.

Notice that we are also working on a social distancing model in continuous space that will be published soon!

---

<div class="post-metadata">

**Author:** ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Post date:** [March 23, 2020, 12:48pm UTC](https://discourse.julialang.org/t/modelling-covid-19-in-julia-and-plotting-agentbasedmodels-on-arbitrary-networks/36005/8 "2020-03-23T12:48:26Z")

</div>

@johnh , sorry, I posted a link to the _development_ version of the docs, instead of the stable (that was stupid of me). If you look at the _stable_ version of the docs (select it from the bottom of the sidebar), the example there has different code that indeed works with the stable releases.

---

<div class="post-metadata">

**Author:** ![johnh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnh/32/3615_2.png) [@johnh](https://discourse.julialang.org/u/johnh)\
**Post date:** [March 23, 2020, 2:48pm UTC](https://discourse.julialang.org/t/modelling-covid-19-in-julia-and-plotting-agentbasedmodels-on-arbitrary-networks/36005/9 "2020-03-23T14:48:05Z")

</div>

Thankyou @datseris please do not say sorry. This is important work you are doing.
