Skip to content

Commit a7648e9

Browse files
committed
differences for PR #106
1 parent 63ed833 commit a7648e9

7 files changed

+122
-13
lines changed

.DS_Store

-6 KB
Binary file not shown.
18.5 KB
Loading
25.1 KB
Loading
1.71 KB
Loading

md5sum.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
"index.md" "32bc80d6f4816435cc0e01540cb2a513" "site/built/index.md" "2025-07-15"
66
"links.md" "8184cf4149eafbf03ce8da8ff0778c14" "site/built/links.md" "2025-07-15"
77
"episodes/contact-matrices.Rmd" "19856620d33f9b7f4e8ee312460494f1" "site/built/contact-matrices.md" "2025-07-23"
8-
"episodes/simulating-transmission.Rmd" "668be08f7fd3035dd40628aa97ff14c3" "site/built/simulating-transmission.md" "2025-07-23"
8+
"episodes/simulating-transmission.Rmd" "aa64ca406d06170c58fc62939adb29f4" "site/built/simulating-transmission.md" "2025-07-24"
99
"episodes/model-choices.Rmd" "aa195e66455fb6a97b4930fd08c08001" "site/built/model-choices.md" "2025-07-15"
10-
"episodes/modelling-interventions.Rmd" "0f695729b90387ec3449f9c46c9b4ae7" "site/built/modelling-interventions.md" "2025-07-15"
10+
"episodes/modelling-interventions.Rmd" "fb61f62793722323eabe3bf90a4aaa2d" "site/built/modelling-interventions.md" "2025-07-24"
1111
"episodes/compare-interventions.Rmd" "2ef6697bbad9bcfb843ab9d50469123b" "site/built/compare-interventions.md" "2025-07-15"
1212
"episodes/vaccine-comparisons.Rmd" "a8fc8f333fc466dac9f53c5a17c24760" "site/built/vaccine-comparisons.md" "2025-07-15"
1313
"episodes/disease-burden.Rmd" "05199c08e0f4394b341dd67b00f7a130" "site/built/disease-burden.md" "2025-07-15"

modelling-interventions.md

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ vaccinate <- vaccination(
364364
)
365365
```
366366

367-
We pass our vaccination object into the model using argument `vaccination = vaccinate`:
367+
We pass our vaccination object into the model using the argument `vaccination = vaccinate`:
368368

369369

370370
``` r
@@ -424,12 +424,58 @@ output %>%
424424

425425
<img src="fig/modelling-interventions-rendered-plot_vaccinate-1.png" style="display: block; margin: auto;" />
426426

427-
From the plot we see that the peak number of total number of infectious individuals when vaccination is in place is much lower compared to school closures and mask wearing interventions.
427+
From the plot, we see that the peak number of total number of infectious individuals when vaccination is in place is much lower compared to school closures and mask-wearing interventions.
428428

429429
:::::::::::::::::::::::::::::::::
430430
::::::::::::::::::::::::::::::::::::::::::::::::
431431

432+
Lastly, if you are interested in plotting the trajectory of new infections from an `epidemics::model_default()` with a `vaccination` intervention, you need to specify one additional argument.
433+
At `epidemics::new_infections()` specify `compartments_from_susceptible = "vaccinated"` to name the model compartments into which individuals transition from the "susceptible" compartment, and which are not related to infection. In the scenario above, "vaccinated" individuals who are no longer susceptible should not be counted as infected.
432434

435+
::::::::::::::::::::: spoiler
436+
437+
Notice that if we use `by_group = FALSE` in `epidemics::new_infections()`, we get a summary of the new infections in all demographic groups.
438+
To get an age-stratified plot, keep the default `by_group = TRUE` and then add `linetype = demography_group` when declaring variables in `ggplot(aes(...))`.
439+
440+
441+
``` r
442+
infections_baseline <- epidemics::new_infections(
443+
data = output_baseline,
444+
compartments_from_susceptible = "vaccinated", # if vaccination
445+
by_group = FALSE
446+
)
447+
448+
infections_intervention <- epidemics::new_infections(
449+
data = output_vaccinate,
450+
compartments_from_susceptible = "vaccinated", # if vaccination
451+
by_group = FALSE
452+
)
453+
454+
# Assign scenario names
455+
infections_baseline$scenario <- "Baseline"
456+
infections_intervention$scenario <- "Vaccination"
457+
458+
# Combine the data from both scenarios
459+
infections_baseline_interv <- dplyr::bind_rows(
460+
infections_baseline,
461+
infections_intervention
462+
)
463+
464+
infections_baseline_interv %>%
465+
ggplot(aes(x = time, y = new_infections, colour = scenario)) +
466+
geom_line() +
467+
geom_vline(
468+
xintercept = c(vaccinate$time_begin, vaccinate$time_end),
469+
linetype = "dashed",
470+
linewidth = 0.2
471+
) +
472+
scale_y_continuous(labels = scales::comma) +
473+
theme_bw()
474+
```
475+
476+
<img src="fig/modelling-interventions-rendered-unnamed-chunk-6-1.png" style="display: block; margin: auto;" />
477+
478+
:::::::::::::::::::::
433479

434480

435481
## Summary

simulating-transmission.md

Lines changed: 72 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,8 @@ output %>%
360360
aes(
361361
x = time,
362362
y = value,
363-
colour = demography_group
363+
color = demography_group,
364+
linetype = compartment
364365
)
365366
) +
366367
scale_y_continuous(
@@ -380,22 +381,84 @@ output %>%
380381
::::::::::::::::::::::::::::::::::::: callout
381382
### Time increments
382383

383-
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.
384+
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.
384385

385-
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:
386+
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:
386387

387-
- 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;
388-
- 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.
388+
- 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;
389+
- 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.
389390

390391
::::::::::::::::::::::::::::::::::::::::::::::::
391392

393+
:::::::::::::::: testimonial
394+
395+
**Two helper functions in `{epidemics}`**
396+
397+
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.
398+
399+
400+
``` r
401+
epidemics::epidemic_peak(data = output)
402+
```
403+
404+
``` output
405+
demography_group compartment time value
406+
<char> <char> <num> <num>
407+
1: [0,20) infectious 315 651944.3
408+
2: [20,40) infectious 319 625863.8
409+
3: 40+ infectious 322 858259.1
410+
```
411+
412+
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.
413+
414+
415+
``` r
416+
epidemics::epidemic_size(data = output)
417+
```
418+
419+
``` output
420+
[1] 9285873 9040679 12540088
421+
```
422+
423+
These summary functions can help you get outputs relevant to scenario comparisons or any other downstream analysis.
424+
425+
::::::::::::::::
426+
427+
The figure above shows the total number or cumulative amount of individuals in the infectious compartment at each time.
428+
If you want to show the *total burden* of the disease, the `infectious` compartment is the most appropriate.
429+
On the other hand, if you want to show the *daily burden*, then you could use `epidemics::new_infections()` to get the daily incidence.
430+
431+
::::::::::::::::::::::: spoiler
432+
433+
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).
434+
435+
436+
``` r
437+
# New infections
438+
newinfections_bygroup <- epidemics::new_infections(data = output)
439+
440+
# Visualise the spread of the epidemic in terms of new infections
441+
newinfections_bygroup %>%
442+
ggplot(aes(x = time, y = new_infections, colour = demography_group)) +
443+
geom_line() +
444+
scale_y_continuous(
445+
breaks = scales::breaks_pretty(n = 5),
446+
labels = scales::comma
447+
) +
448+
theme_bw()
449+
```
450+
451+
<img src="fig/simulating-transmission-rendered-unnamed-chunk-6-1.png" style="display: block; margin: auto;" />
452+
453+
:::::::::::::::::::::::
454+
392455
## Accounting for uncertainty
393456

394457
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.
395458

396-
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:
459+
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:
397460

398-
1. Obtain 100 samples from the from a normal distribution
461+
1. Obtain 100 samples from a normal distribution
399462

400463

401464
``` r
@@ -428,7 +491,7 @@ output_samples <- model_default(
428491
)
429492
```
430493

431-
3. Calculate the mean and 95% quantiles of number of infectious individuals across each model simulation and visualise output
494+
3. Calculate the mean and 95% quantiles of the number of infectious individuals across each model simulation and visualise the output
432495

433496

434497
``` r
@@ -461,7 +524,7 @@ output_samples %>%
461524
<img src="fig/simulating-transmission-rendered-plot-1.png" style="display: block; margin: auto;" />
462525

463526

464-
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.
527+
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.
465528

466529
:::::::::::::::::: challenge
467530

0 commit comments

Comments
 (0)