Skip to content

Commit 0a5ac76

Browse files
authored
add helper functions for peak size new infections
1 parent 5e7cd45 commit 0a5ac76

1 file changed

Lines changed: 54 additions & 9 deletions

File tree

episodes/simulating-transmission.Rmd

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,8 @@ output %>%
454454
aes(
455455
x = time,
456456
y = value,
457-
colour = demography_group
457+
color = demography_group,
458+
linetype = compartment
458459
)
459460
) +
460461
scale_y_continuous(
@@ -472,22 +473,66 @@ output %>%
472473
::::::::::::::::::::::::::::::::::::: callout
473474
### Time increments
474475

475-
Note that there is a default argument of `increment = 1`. This relates to the time step of the ODE solver. When the parameters are specified on a daily time-scale and maximum number of time steps (`time_end`) is days, the default time step of the ODE solver one day.
476+
Note that there is a default argument of `increment = 1`. This relates to the time step of the ODE solver. When the parameters are specified on a daily time scale and the maximum number of time steps (`time_end`) is days, the default time step of the ODE solver is one day.
476477

477-
The choice of increment will depend on the time scale of the parameters, and the rate at which events can occur. In general, the increment should be smaller than the fastest event that can occur. For example:
478+
The choice of increment will depend on the time scale of the parameters and the rate at which events can occur. In general, the increment should be smaller than the fastest event that can occur. For example:
478479

479-
- if parameters are on a daily time scale, and all events are reported on a daily basis, then the increment should be equal to one day;
480-
- if parameters are on a monthly time scale, but some events will occur within a month, then the increment should be less than one month.
480+
- If parameters are on a *daily* time scale, and all events are reported on a daily basis, then the increment should be equal to one day;
481+
- If parameters are on a *monthly* time scale, but some events will occur within a month, then the increment should be less than one month.
481482

482483
::::::::::::::::::::::::::::::::::::::::::::::::
483484

485+
:::::::::::::::: testimonial
486+
487+
**Two helper functions in `{epidemics}`**
488+
489+
Use `epidemics::epidemic_peak()` to get the time and size of a compartment's highest peak for all demographic groups. By default, this will calculate for the infectious compartment.
490+
491+
```{r}
492+
epidemics::epidemic_peak(data = output)
493+
```
494+
495+
Use `epidemics::epidemic_size()` to get the size of the epidemic at any stage between the start and the end. This is calculated as the number of individuals *recovered* from infection at that stage of the epidemic.
496+
497+
```{r}
498+
epidemics::epidemic_size(data = output)
499+
```
500+
501+
These summary functions can help you get outputs relevant to scenario comparisons or any other downstream analysis.
502+
503+
::::::::::::::::
504+
505+
The figure above shows the total number or cumulative amount of individuals in the infectious compartment at each time.
506+
If you want to show the *total burden* of the disease, the `infectious` compartment is the most appropriate.
507+
On the other hand, if you want to show the *daily burden*, then you could use `epidemics::new_infections()` to get the daily incidence.
508+
509+
::::::::::::::::::::::: spoiler
510+
511+
Notice that the number of new infected individuals at each time (as in the figure below) is lower than the cumulative number of infectious individuals at each time (as in the figure above).
512+
513+
```{r}
514+
# New infections
515+
newinfections_bygroup <- epidemics::new_infections(data = output)
516+
517+
# Visualise the spread of the epidemic in terms of new infections
518+
newinfections_bygroup %>%
519+
ggplot(aes(time, new_infections, colour = demography_group)) +
520+
geom_line() +
521+
scale_y_continuous(
522+
breaks = scales::breaks_pretty(n = 10),
523+
labels = scales::comma
524+
)
525+
```
526+
527+
:::::::::::::::::::::::
528+
484529
## Accounting for uncertainty
485530

486531
The epidemic model is [deterministic](../learners/reference.md#deterministic), which means it runs like clockwork: the same parameters will always lead to the same trajectory. A deterministic model is one where the outcome is completely determined by the initial conditions and parameters, with no random variation. However, reality is not so predictable. There are two main reasons for this: the transmission process can involve randomness, and we may not know the exact epidemiological characteristics of the pathogen we're interested in. In the next episode, we will consider 'stochastic' models (i.e. models where we can define the process that creates randomness in transmission). In the meantime, we can include uncertainty in the value of the parameters that go into the deterministic model. To account for this, we must run our model for different parameter combinations.
487532

488-
We ran our model with $R_0= 1.5$. However, we believe that $R_0$ follows a normal distribution with mean 1.5 and standard deviation 0.05. To account for uncertainty we will run the model for different values of $R_0$. The steps we will follow to do this are:
533+
We ran our model with $R_0= 1.5$. However, we believe that $R_0$ follows a normal distribution with mean 1.5 and standard deviation 0.05. To account for uncertainty, we will run the model for different values of $R_0$. The steps we will follow to do this are:
489534

490-
1. Obtain 100 samples from the from a normal distribution
535+
1. Obtain 100 samples from a normal distribution
491536

492537
```{r normal, echo = TRUE}
493538
# specify the mean and standard deviation of R0
@@ -518,7 +563,7 @@ output_samples <- model_default(
518563
)
519564
```
520565

521-
3. Calculate the mean and 95% quantiles of number of infectious individuals across each model simulation and visualise output
566+
3. Calculate the mean and 95% quantiles of the number of infectious individuals across each model simulation and visualise the output
522567

523568
```{r plot, fig.width = 10}
524569
output_samples %>%
@@ -548,7 +593,7 @@ output_samples %>%
548593
```
549594

550595

551-
Deciding which parameters to include uncertainty in depends on a few factors: how well informed a parameter value is e.g. consistency of estimates from the literature; how sensitive model outputs are to parameter value changes; and the purpose of the modelling task. See [McCabe et al. 2021](https://doi.org/10.1016%2Fj.epidem.2021.100520) to learn about different types of uncertainty in infectious disease modelling.
596+
Deciding which parameters to include uncertainty in depends on a few factors: how well informed a parameter value is, e.g. consistency of estimates from the literature; how sensitive model outputs are to parameter value changes; and the purpose of the modelling task. See [McCabe et al. 2021](https://doi.org/10.1016%2Fj.epidem.2021.100520) to learn about different types of uncertainty in infectious disease modelling.
552597

553598
:::::::::::::::::: challenge
554599

0 commit comments

Comments
 (0)