Skip to content

Commit

Permalink
differences for PR #25
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Mar 30, 2024
1 parent b018a86 commit 2c2b200
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 75 deletions.
Binary file modified fig/quantify-transmissibility-rendered-unnamed-chunk-16-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion md5sum.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"config.yaml" "3dfcd01455f985757c946222d1b868c2" "site/built/config.yaml" "2024-03-28"
"index.md" "adfca1a79e0106ee8b3f7731d0678b59" "site/built/index.md" "2024-03-25"
"links.md" "8184cf4149eafbf03ce8da8ff0778c14" "site/built/links.md" "2024-03-25"
"episodes/quantify-transmissibility.Rmd" "eb679d95e103592ab1ddee6472ab77df" "site/built/quantify-transmissibility.md" "2024-03-28"
"episodes/quantify-transmissibility.Rmd" "8004fe0687f589649b125b4a46a8a8ec" "site/built/quantify-transmissibility.md" "2024-03-30"
"episodes/create-forecast.Rmd" "3fdb0f4223f220d061431f18846bf1f4" "site/built/create-forecast.md" "2024-03-25"
"episodes/severity-static.Rmd" "f04e6a34a8fa96eb0f5e846d31ba8e98" "site/built/severity-static.md" "2024-03-25"
"instructors/instructor-notes.md" "ca3834a1b0f9e70c4702aa7a367a6bb5" "site/built/instructor-notes.md" "2024-03-25"
Expand Down
210 changes: 136 additions & 74 deletions quantify-transmissibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,40 @@ To use the data, we must format the data to have two columns:
+ `date` : the date (as a date object see `?is.Date()`),
+ `confirm` : number of confirmed cases on that date.

Let's use `{dplyr}` for this:


```r
cases <- aggregate(
cases_new ~ date,
data = incidence2::covidregionaldataUK[, c("date", "cases_new")],
FUN = sum
)
colnames(cases) <- c("date", "confirm")
library(dplyr)
```

```{.output}
Attaching package: 'dplyr'
```

```{.output}
The following objects are masked from 'package:stats':
filter, lag
```

```{.output}
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
```

```r
cases <- incidence2::covidregionaldataUK %>%
select(date, cases_new) %>%
group_by(date) %>%
summarise(confirm = sum(cases_new, na.rm = TRUE)) %>%
ungroup()
```


There are case data available for 489 days, but in an outbreak situation it is likely we would only have access to the beginning of this data set. Therefore we assume we only have the first 90 days of this data.
There are case data available for 490 days, but in an outbreak situation it is likely we would only have access to the beginning of this data set. Therefore we assume we only have the first 90 days of this data.

<img src="fig/quantify-transmissibility-rendered-unnamed-chunk-4-1.png" style="display: block; margin: auto;" />

Expand All @@ -159,9 +181,9 @@ The number of delays and type of delay is a flexible input that depends on the d

| Data source | Delay(s) |
| ------------- |-------------|
|Time of symptom onset |Incubation period |
|Time of case report |Incubation period + time from symptom onset to case notification |
|Time of hospitalisation |Incubation period + time from symptom onset to hospitalisation |
|Time of symptom onset |Incubation period |

</center>

Expand Down Expand Up @@ -335,22 +357,58 @@ To find the maximum number of available cores on your machine, use `parallel::de

```r
reported_cases <- cases[1:90, ]

estimates <- epinow(
reported_cases = reported_cases,
generation_time = generation_time_opts(generation_time_fixed),
delays = delay_opts(incubation_period_fixed + reporting_delay_fixed),
rt = rt_opts(prior = list(mean = rt_log_mean, sd = rt_log_sd))
delays = delay_opts(
incubation_period_fixed + reporting_delay_fixed
),
rt = rt_opts(
prior = list(mean = rt_log_mean, sd = rt_log_sd)
)
)
```

```{.output}
WARN [2024-03-28 21:34:59] epinow: There were 8 divergent transitions after warmup. See
WARN [2024-03-30 14:30:18] epinow: There were 2 divergent transitions after warmup. See
https://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup
to find out why this is a problem and how to eliminate them. -
WARN [2024-03-28 21:34:59] epinow: Examine the pairs() plot to diagnose sampling problems
WARN [2024-03-30 14:30:18] epinow: Examine the pairs() plot to diagnose sampling problems
-
```

::::::::::::::::::::::::::::::::: spoiler

### Reduce computation time

Using an appropriate number of samples and chains is crucial for ensuring convergence and obtaining reliable estimates in Bayesian computations using Stan. Inadequate sampling or insufficient chains may lead to issues such as divergent transitions, impacting the accuracy and stability of the inference process.

For the purpose of this tutorial, we can add more configuration details to get an useful output in less time. You can specify a fixed number of `samples` and `chains` to the `stan` argument using the `stan_opts()` function:

The code in the previous chunk can take around 10 minutes. We expect this chunk below to take approximately 3 minutes:


```r
estimates <- epinow(
# same code as previous chunk
reported_cases = reported_cases,
generation_time = generation_time_opts(generation_time_fixed),
delays = delay_opts(
incubation_period_fixed + reporting_delay_fixed
),
rt = rt_opts(
prior = list(mean = rt_log_mean, sd = rt_log_sd)
),
# [new] set a fixed number of samples and chains
stan = stan_opts(
samples = 1000, chains = 3
)
)
```

:::::::::::::::::::::::::::::::::

### Results

We can extract and visualise estimates of the effective reproduction number through time:
Expand All @@ -360,7 +418,7 @@ We can extract and visualise estimates of the effective reproduction number thro
estimates$plots$R
```

<img src="fig/quantify-transmissibility-rendered-unnamed-chunk-15-1.png" style="display: block; margin: auto;" />
<img src="fig/quantify-transmissibility-rendered-unnamed-chunk-16-1.png" style="display: block; margin: auto;" />

The uncertainty in the estimates increases through time. This is because estimates are informed by data in the past - within the delay periods. This difference in uncertainty is categorised into **Estimate** (green) utilises all data and **Estimate based on partial data** (orange) estimates that are based on less data (because infections that happened at the time are more likely to not have been observed yet) and therefore have increasingly wider intervals towards the date of the last data point. Finally, the **Forecast** (purple) is a projection ahead of time.

Expand All @@ -370,7 +428,7 @@ We can also visualise the growth rate estimate through time:
estimates$plots$growth_rate
```

<img src="fig/quantify-transmissibility-rendered-unnamed-chunk-16-1.png" style="display: block; margin: auto;" />
<img src="fig/quantify-transmissibility-rendered-unnamed-chunk-17-1.png" style="display: block; margin: auto;" />

To extract a summary of the key transmission metrics at the *latest date* in the data:

Expand All @@ -382,22 +440,22 @@ summary(estimates)
```{.output}
measure estimate
<char> <char>
1: New confirmed cases by infection date 7232 (4047 -- 13301)
1: New confirmed cases by infection date 7240 (4042 -- 11945)
2: Expected change in daily cases Likely decreasing
3: Effective reproduction no. 0.89 (0.58 -- 1.4)
4: Rate of growth -0.015 (-0.063 -- 0.043)
5: Doubling/halving time (days) -47 (16 -- -11)
3: Effective reproduction no. 0.89 (0.57 -- 1.3)
4: Rate of growth -0.014 (-0.064 -- 0.036)
5: Doubling/halving time (days) -48 (19 -- -11)
```

As these estimates are based on partial data, they have a wide uncertainty interval.

+ From the summary of our analysis we see that the expected change in daily cases is Likely decreasing with the estimated new confirmed cases 7232 (4047 -- 13301).
+ From the summary of our analysis we see that the expected change in daily cases is Likely decreasing with the estimated new confirmed cases 7240 (4042 -- 11945).

+ The effective reproduction number $R_t$ estimate (on the last date of the data) is 0.89 (0.58 -- 1.4).
+ The effective reproduction number $R_t$ estimate (on the last date of the data) is 0.89 (0.57 -- 1.3).

+ The exponential growth rate of case numbers is -0.015 (-0.063 -- 0.043).
+ The exponential growth rate of case numbers is -0.014 (-0.064 -- 0.036).

+ The doubling time (the time taken for case numbers to double) is -47 (16 -- -11).
+ The doubling time (the time taken for case numbers to double) is -48 (19 -- -11).

::::::::::::::::::::::::::::::::::::: callout
### `Expected change in daily cases`
Expand Down Expand Up @@ -457,23 +515,27 @@ To find regional estimates, we use the same inputs as `epinow()` to the function
estimates_regional <- regional_epinow(
reported_cases = regional_cases,
generation_time = generation_time_opts(generation_time_fixed),
delays = delay_opts(incubation_period_fixed + reporting_delay_fixed),
rt = rt_opts(prior = list(mean = rt_log_mean, sd = rt_log_sd))
delays = delay_opts(
incubation_period_fixed + reporting_delay_fixed
),
rt = rt_opts(
prior = list(mean = rt_log_mean, sd = rt_log_sd)
)
)
```

```{.output}
INFO [2024-03-28 21:35:04] Producing following optional outputs: regions, summary, samples, plots, latest
INFO [2024-03-28 21:35:04] Reporting estimates using data up to: 2020-04-28
INFO [2024-03-28 21:35:04] No target directory specified so returning output
INFO [2024-03-28 21:35:04] Producing estimates for: East Midlands, East of England, England, London, North East, North West, Northern Ireland, Scotland, South East, South West, Wales, West Midlands, Yorkshire and The Humber
INFO [2024-03-28 21:35:04] Regions excluded: none
INFO [2024-03-28 22:21:26] Completed regional estimates
INFO [2024-03-28 22:21:26] Regions with estimates: 13
INFO [2024-03-28 22:21:26] Regions with runtime errors: 0
INFO [2024-03-28 22:21:26] Producing summary
INFO [2024-03-28 22:21:26] No summary directory specified so returning summary output
INFO [2024-03-28 22:21:26] No target directory specified so returning timings
INFO [2024-03-30 14:30:23] Producing following optional outputs: regions, summary, samples, plots, latest
INFO [2024-03-30 14:30:23] Reporting estimates using data up to: 2020-04-28
INFO [2024-03-30 14:30:23] No target directory specified so returning output
INFO [2024-03-30 14:30:23] Producing estimates for: East Midlands, East of England, England, London, North East, North West, Northern Ireland, Scotland, South East, South West, Wales, West Midlands, Yorkshire and The Humber
INFO [2024-03-30 14:30:23] Regions excluded: none
INFO [2024-03-30 15:14:29] Completed regional estimates
INFO [2024-03-30 15:14:29] Regions with estimates: 13
INFO [2024-03-30 15:14:29] Regions with runtime errors: 0
INFO [2024-03-30 15:14:29] Producing summary
INFO [2024-03-30 15:14:29] No summary directory specified so returning summary output
INFO [2024-03-30 15:14:30] No target directory specified so returning timings
```

```r
Expand All @@ -483,56 +545,56 @@ estimates_regional$summary$summarised_results$table
```{.output}
Region New confirmed cases by infection date
<char> <char>
1: East Midlands 347 (216 -- 568)
2: East of England 540 (331 -- 840)
3: England 3621 (2184 -- 5730)
4: London 293 (191 -- 456)
5: North East 251 (144 -- 412)
6: North West 561 (326 -- 869)
7: Northern Ireland 44 (24 -- 85)
8: Scotland 288 (160 -- 538)
9: South East 588 (343 -- 975)
10: South West 415 (290 -- 598)
11: Wales 94 (63 -- 134)
12: West Midlands 272 (145 -- 495)
13: Yorkshire and The Humber 476 (280 -- 787)
1: East Midlands 341 (216 -- 558)
2: East of England 535 (333 -- 837)
3: England 3531 (2208 -- 5617)
4: London 298 (189 -- 459)
5: North East 253 (147 -- 432)
6: North West 548 (332 -- 887)
7: Northern Ireland 43 (23 -- 83)
8: Scotland 290 (158 -- 545)
9: South East 594 (352 -- 998)
10: South West 422 (292 -- 593)
11: Wales 95 (63 -- 140)
12: West Midlands 272 (149 -- 475)
13: Yorkshire and The Humber 480 (291 -- 808)
Expected change in daily cases Effective reproduction no.
<fctr> <char>
1: Likely increasing 1.2 (0.87 -- 1.6)
1: Likely increasing 1.2 (0.86 -- 1.6)
2: Likely increasing 1.2 (0.83 -- 1.6)
3: Likely decreasing 0.92 (0.63 -- 1.3)
4: Likely decreasing 0.78 (0.56 -- 1.1)
5: Likely decreasing 0.91 (0.59 -- 1.3)
6: Likely decreasing 0.87 (0.58 -- 1.2)
7: Likely decreasing 0.66 (0.4 -- 1.1)
8: Likely decreasing 0.91 (0.58 -- 1.4)
9: Stable 0.99 (0.66 -- 1.4)
10: Increasing 1.4 (1.1 -- 1.8)
11: Decreasing 0.56 (0.41 -- 0.74)
12: Likely decreasing 0.71 (0.42 -- 1.1)
13: Stable 1 (0.69 -- 1.4)
3: Likely decreasing 0.91 (0.64 -- 1.3)
4: Likely decreasing 0.8 (0.56 -- 1.1)
5: Likely decreasing 0.91 (0.61 -- 1.3)
6: Likely decreasing 0.86 (0.58 -- 1.2)
7: Likely decreasing 0.64 (0.38 -- 1)
8: Likely decreasing 0.91 (0.59 -- 1.4)
9: Stable 1 (0.67 -- 1.4)
10: Increasing 1.4 (1.1 -- 1.7)
11: Decreasing 0.56 (0.41 -- 0.76)
12: Likely decreasing 0.71 (0.44 -- 1.1)
13: Stable 1 (0.7 -- 1.5)
Rate of growth Doubling/halving time (days)
<char> <char>
1: 0.024 (-0.018 -- 0.069) 29 (10 -- -39)
2: 0.022 (-0.023 -- 0.066) 31 (11 -- -30)
3: -0.01 (-0.054 -- 0.033) -68 (21 -- -13)
4: -0.03 (-0.066 -- 0.01) -23 (67 -- -11)
5: -0.012 (-0.06 -- 0.034) -57 (20 -- -12)
6: -0.017 (-0.063 -- 0.022) -40 (32 -- -11)
7: -0.05 (-0.097 -- 0.0067) -14 (100 -- -7.1)
8: -0.012 (-0.062 -- 0.049) -58 (14 -- -11)
9: -0.0017 (-0.049 -- 0.049) -410 (14 -- -14)
10: 0.046 (0.013 -- 0.085) 15 (8.2 -- 55)
11: -0.065 (-0.095 -- -0.036) -11 (-19 -- -7.3)
12: -0.041 (-0.092 -- 0.014) -17 (50 -- -7.5)
13: 0.0025 (-0.045 -- 0.051) 270 (14 -- -15)
1: 0.023 (-0.019 -- 0.068) 30 (10 -- -37)
2: 0.022 (-0.023 -- 0.064) 32 (11 -- -31)
3: -0.012 (-0.052 -- 0.031) -58 (22 -- -13)
4: -0.028 (-0.067 -- 0.012) -25 (59 -- -10)
5: -0.012 (-0.057 -- 0.036) -57 (19 -- -12)
6: -0.019 (-0.063 -- 0.023) -36 (30 -- -11)
7: -0.053 (-0.1 -- 0.0061) -13 (110 -- -6.9)
8: -0.012 (-0.06 -- 0.047) -60 (15 -- -12)
9: -5e-04 (-0.048 -- 0.049) -1400 (14 -- -15)
10: 0.047 (0.014 -- 0.083) 15 (8.3 -- 51)
11: -0.065 (-0.095 -- -0.033) -11 (-21 -- -7.3)
12: -0.041 (-0.088 -- 0.0085) -17 (82 -- -7.9)
13: 0.0025 (-0.043 -- 0.054) 280 (13 -- -16)
```

```r
estimates_regional$summary$plots$R
```

<img src="fig/quantify-transmissibility-rendered-unnamed-chunk-19-1.png" style="display: block; margin: auto;" />
<img src="fig/quantify-transmissibility-rendered-unnamed-chunk-20-1.png" style="display: block; margin: auto;" />


## Summary
Expand Down

0 comments on commit 2c2b200

Please sign in to comment.