Skip to content

Commit

Permalink
Added De Leo scaling model
Browse files Browse the repository at this point in the history
  • Loading branch information
sdwfrost committed Oct 19, 2018
1 parent 3bc280b commit 4cf4aa8
Show file tree
Hide file tree
Showing 17 changed files with 2,841 additions and 4 deletions.
4 changes: 4 additions & 0 deletions SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
* [Javascript using Observable](notebooks/sir/js_observable.md)
* [SIS model](notebooks/sis/intro.md)
* [Javascript using Observable](notebooks/sis/js_observable.md)
* [Scaling model](notebooks/deleo1996/intro.md)
* [Julia](notebooks/deleo1996/julia.ipynb)
* [Python](notebooks/deleo1996/python.ipynb)
* [R using deSolve](notebooks/deleo1996/r_desolve.ipynb)
* [Simple stochastic models](notebooks/stochastic.md)
* [Continuous time SIR](notebooks/sir-stochastic-discretestate-continuoustime/intro.md)
* [R](notebooks/sir-stochastic-discretestate-continuoustime/r.ipynb)
Expand Down
33 changes: 33 additions & 0 deletions _chapters/deleo1996/intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
title: 'Scaling model'
permalink: 'chapters/deleo1996/intro'
previouschapter:
url: chapters/sis/js_observable
title: 'Javascript using Observable'
nextchapter:
url: chapters/deleo1996/julia
title: 'Julia'
redirect_from:
- 'chapters/deleo1996/intro'
---

## Basic microparasite model

*Author*: Christopher Davis

*Date*: 2018-10-02

### Description

A basic microparasite model of susceptibles and infecteds with the force of infection density dependent. $\beta_{\text{min}}$ is the minimum value of the transmission rate $\beta$, such that the disease will spread.

### Equations

$$
\frac{dS(t)}{dt} = (\nu - \mu)\left(1- \frac{S(t)}{K}\right) S(t)- \beta S(t) I(t)\\
\frac{dI(t)}{dt} = \beta S(t) I(t)- (\mu +\ \alpha) I(t)\\
$$

### References

- [De Leo GA, Dobson AP (February, 1996). "Allometry and simple epidemic models for microparasites". Nature. 379(6567):720](https://doi.org/10.1038/379720a0)
130 changes: 130 additions & 0 deletions _chapters/deleo1996/julia.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
---
interact_link: notebooks/deleo1996/julia.ipynb
title: 'Julia'
permalink: 'chapters/deleo1996/julia'
previouschapter:
url: chapters/deleo1996/intro
title: 'Scaling model'
nextchapter:
url: chapters/deleo1996/python
title: 'Python'
redirect_from:
- 'chapters/deleo1996/julia'
---

### De Leo et al. scaling model in Julia

*Author*: Christopher Davis

*Date*: 2018-10-02


{:.input_area}
```julia
using DifferentialEquations
```


{:.input_area}
```julia
micro_1 = @ode_def Micro1 begin
dS = r*(1-S/K)*S - β*S*I
dI = β*S*I-+α)*I
end β r μ K α
```




{:.output_data_text}
```
(::Micro1) (generic function with 4 methods)
```




{:.input_area}
```julia
w = 1;
m = 10;
β = 0.0247*m*w^0.44;
r = 0.6*w^-0.27;
μ = 0.4*w^-0.26;
K = 16.2*w^-0.7;
α = (m-1)*μ;
```


{:.input_area}
```julia
parms = [β,r,μ,K,α];
init = [K,1.];
tspan = (0.0,10.0);
```


{:.input_area}
```julia
sir_prob = ODEProblem(micro_1,init,tspan,parms)
```




{:.output_data_text}
```
DiffEqBase.ODEProblem with uType Array{Float64,1} and tType Float64. In-place: true
timespan: (0.0, 10.0)
u0: [16.2, 1.0]
```




{:.input_area}
```julia
sir_sol = solve(sir_prob);
```

#### Visualisation


{:.input_area}
```julia
using Plots
```


{:.input_area}
```julia
plot(sir_sol,xlabel="Time",ylabel="Number")
```




![svg](../../images/chapters/deleo1996/julia_10_0.svg)



#### Threshold criterion for transmission rate


{:.input_area}
```julia
m = [5,10,20,40]
ws = 10.^linspace(-3,3,601)
βs = zeros(601,4)
for i = 1:4
βs[:,i] = 0.0247*m[i]*ws.^0.44
end
plot(ws,βs,xlabel="Weight",ylabel="\\beta_min", xscale=:log10,yscale=:log10, label=["m = 5" "m = 10" "m = 20" "m = 40"],lw=3)
```




![svg](../../images/chapters/deleo1996/julia_12_0.svg)


126 changes: 126 additions & 0 deletions _chapters/deleo1996/python.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
---
interact_link: notebooks/deleo1996/python.ipynb
title: 'Python'
permalink: 'chapters/deleo1996/python'
previouschapter:
url: chapters/deleo1996/julia
title: 'Julia'
nextchapter:
url: chapters/deleo1996/r_desolve
title: 'R using deSolve'
redirect_from:
- 'chapters/deleo1996/python'
---

### Python using SciPy

*Author*: Christopher Davis

*Date*: 2018-10-02


{:.input_area}
```python
import numpy as np
from scipy.integrate import ode, solve_ivp
```


{:.input_area}
```python
def micro_1(times,init,parms):
beta, r, mu, K, alpha = parms
S,I = init
# ODEs
dS = r*(1-S/K)*S - beta*S*I
dI = beta*S*I-(mu + alpha)*I
return [dS,dI]
```


{:.input_area}
```python
w = 1
m = 10
beta = 0.0247*m*w**0.44
r = 0.6*w**-0.27
mu = 0.4*w**-0.26
K = 16.2*w**-0.7
alpha = (m-1)*mu
```


{:.input_area}
```python
parms = [beta,r,mu,K,alpha]
init = [K,1.]
times = np.linspace(0,10,101)
```


{:.input_area}
```python
sir_sol = solve_ivp(fun=lambda t, y: micro_1(t, y, parms), t_span=[min(times),max(times)], y0=init, t_eval=times)
```

#### Visualisation


{:.input_area}
```python
import matplotlib.pyplot as plt
```


{:.input_area}
```python
plt.plot(sir_sol.t,sir_sol.y[0],color="red",linewidth=2, label = "S(t)")
plt.plot(sir_sol.t,sir_sol.y[1],color="blue",linewidth=2, label = "I(t)")
plt.xlabel("Time")
plt.ylabel("Number")
plt.legend()
```




{:.output_data_text}
```
<matplotlib.legend.Legend at 0x7f776a919198>
```




![png](../../images/chapters/deleo1996/python_9_1.png)


#### Threshold criterion for transmission rate


{:.input_area}
```python
m = [5,10,20,40]
ws = 10**np.linspace(-3,3,601)
betas = np.zeros((601,4))
for i in range(4):
betas[:,i] = 0.0247*m[i]*ws**0.44
plt.loglog(ws,betas)
plt.xlabel("Weight")
plt.ylabel(r'$\beta_{min}$')
plt.legend(("m = 5", "m = 10", "m = 20", "m = 40"))
```




{:.output_data_text}
```
<matplotlib.legend.Legend at 0x7f7769b707f0>
```




![png](../../images/chapters/deleo1996/python_11_1.png)

153 changes: 153 additions & 0 deletions _chapters/deleo1996/r_desolve.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions _chapters/sis/js_observable.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ previouschapter:
url: chapters/sis/intro
title: 'SIS model'
nextchapter:
url: chapters/stochastic
title: 'Simple stochastic models'
url: chapters/deleo1996/intro
title: 'Scaling model'
redirect_from:
- 'chapters/sis/js-observable'
---
Expand Down
4 changes: 2 additions & 2 deletions _chapters/stochastic.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
title: 'Simple stochastic models'
permalink: 'chapters/stochastic'
previouschapter:
url: chapters/sis/js_observable
title: 'Javascript using Observable'
url: chapters/deleo1996/r_desolve
title: 'R using deSolve'
nextchapter:
url: chapters/sir-stochastic-discretestate-continuoustime/intro
title: 'Continuous time SIR'
Expand Down
12 changes: 12 additions & 0 deletions _data/textbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ chapters:
- class: level_2
title: Javascript using Observable
url: chapters/sis/js_observable
- class: level_1
title: Scaling model
url: chapters/deleo1996/intro
- class: level_2
title: Julia
url: chapters/deleo1996/julia
- class: level_2
title: Python
url: chapters/deleo1996/python
- class: level_2
title: R using deSolve
url: chapters/deleo1996/r_desolve
class: level_0
title: Simple deterministic models
url: chapters/simple
Expand Down
Loading

0 comments on commit 4cf4aa8

Please sign in to comment.