| ... | ... | @@ -125,5 +125,47 @@ The trajectory can readily be plotted using the `plot()` function: |
|
|
|
plot(traj_dm)
|
|
|
|
```
|
|
|
|
|
|
|
|
<img src="vignettes/TiPS_files/figure-markdown_github/unnamed-chunk-13-1.png" width="576" style="display: block; margin: auto;" />
|
|
|
|
<img src="uploads/1763f73344d5ce4664ade2aa912215b6/unnamed-chunk-13-1.png" width="350" height="230">
|
|
|
|
|
|
|
|
### *τ*-leap method
|
|
|
|
|
|
|
|
The default mode of the simulator is the *τ*-leap method. The `method` argument must be specified and fixed to `àpproximate`. The time-step `tau` is by default set to 0.05. Let's fix its value to 0.009:
|
|
|
|
|
|
|
|
``` r
|
|
|
|
traj_tl <- safe_sir_simu(
|
|
|
|
paramValues = theta,
|
|
|
|
initialStates = initialStates,
|
|
|
|
times = time,
|
|
|
|
method = "approximate",
|
|
|
|
tau = 0.009)
|
|
|
|
```
|
|
|
|
|
|
|
|
We obtain the same type of output as with the direct method:
|
|
|
|
|
|
|
|
``` r
|
|
|
|
head(traj_tl$traj)
|
|
|
|
#> Time Reaction Nrep S I R
|
|
|
|
#> 1 0.000 init 1 9999 1 0
|
|
|
|
#> 2 0.342 S [beta*S*I] -> I 1 9998 2 0
|
|
|
|
#> 3 0.648 S [beta*S*I] -> I 1 9997 3 0
|
|
|
|
#> 4 0.963 S [beta*S*I] -> I 1 9996 4 0
|
|
|
|
#> 5 0.990 I [gamma*I] -> R 1 9996 3 1
|
|
|
|
#> 6 1.008 S [beta*S*I] -> I 1 9995 4 1
|
|
|
|
```
|
|
|
|
|
|
|
|
The trajectory can also be plotted using the `plot` function.
|
|
|
|
|
|
|
|
### Mixed method
|
|
|
|
|
|
|
|
To run simulations with the `mixed` algorithm (basically switching between the direct method and the *τ*-leap method depending on the number of reactions occurring per unit of time), the `method` argument must be specified and fixed to `mixed`. The time-step `tau` is by default set to 0.05. Let's fix its value to 0.009 :
|
|
|
|
|
|
|
|
``` r
|
|
|
|
traj_mm <- safe_sir_simu(
|
|
|
|
paramValues = theta,
|
|
|
|
initialStates = initialStates,
|
|
|
|
times = time,
|
|
|
|
method = "mixed",
|
|
|
|
tau = 0.009)
|
|
|
|
```
|
|
|
|
|
|
|
|
Outputs are similar to the other methods and the trajectory can also be plotted using the `plot` function. |