diff --git a/README.md b/README.md index 063952dd5..833c8ca33 100644 --- a/README.md +++ b/README.md @@ -181,28 +181,33 @@ runtimes*), ``` r reporting_delay <- dist_spec( - mean = convert_to_logmean(2, 1), sd = convert_to_logsd(2, 1), max = 10, + mean = convert_to_logmean(2, 1), + sd = convert_to_logsd(2, 1), + max = 10, dist = "lognormal" ) #> Warning: The meaning of the 'max' argument has changed compared to previous versions. It now indicates the maximum of a distribution rather than the length of the probability mass function (including 0) that it represented previously. To replicate previous behaviour reduce max by 1. #> This warning is displayed once every 8 hours. +reporting_delay +#> +#> Fixed distribution with PMF [0.11 0.48 0.27 0.093 0.029 0.0096 0.0033 0.0012 0.00045 0.00018 7.4e-05] ``` -Here we define the incubation period and generation time based on -literature estimates for Covid-19 (see +We use example literature estimates for the incubation period and +generation time of Covid-19 (see [here](https://github.com/epiforecasts/EpiNow2/tree/main/data-raw) for -the code that generates these estimates). *Note that these distributions -may not be applicable for your use case and that we have not included -uncertainty here to reduce the runtime of this example but in most -settings this is not recommended.* +the code that generates these estimates). *These distributions are +unlikely to be applicable for your use case and do not have uncertainty +associated with them. We strongly recommend investigating what might be +the best distributions to use in any given use case.* ``` r -generation_time <- get_generation_time( - disease = "SARS-CoV-2", source = "ganyani", max = 10, fixed = TRUE -) -incubation_period <- get_incubation_period( - disease = "SARS-CoV-2", source = "lauer", max = 10, fixed = TRUE -) +example_generation_time +#> +#> Uncertain gamma distribution with (untruncated) mean 3.6 (SD 0.71) and SD 3.1 (SD 0.77) +example_incubation_period +#> +#> Uncertain lognormal distribution with (untruncated) logmean 1.6 (SD 0.064) and logSD 0.42 (SD 0.069) ``` ### [epinow()](https://epiforecasts.io/EpiNow2/reference/epinow.html) @@ -239,12 +244,17 @@ For other formulations see the documentation for ``` r estimates <- epinow( reported_cases = reported_cases, - generation_time = generation_time_opts(generation_time), - delays = delay_opts(incubation_period + reporting_delay), + generation_time = generation_time_opts(example_generation_time), + delays = delay_opts(example_incubation_period + reporting_delay), rt = rt_opts(prior = list(mean = 2, sd = 0.2)), stan = stan_opts(cores = 4, control = list(adapt_delta = 0.99)), verbose = interactive() ) +#> WARN [2023-10-19 14:58:02] epinow: There were 1 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 [2023-10-19 14:58:02] epinow: Examine the pairs() plot to diagnose sampling problems +#> - names(estimates) #> [1] "estimates" "estimated_reported_cases" #> [3] "summary" "plots" @@ -262,11 +272,11 @@ knitr::kable(summary(estimates)) | measure | estimate | |:--------------------------------------|:----------------------| -| New confirmed cases by infection date | 2297 (1134 – 4496) | +| New confirmed cases by infection date | 2243 (1110 – 4278) | | Expected change in daily cases | Likely decreasing | -| Effective reproduction no. | 0.89 (0.62 – 1.2) | -| Rate of growth | -0.027 (-0.1 – 0.039) | -| Doubling/halving time (days) | -26 (18 – -6.8) | +| Effective reproduction no. | 0.87 (0.6 – 1.2) | +| Rate of growth | -0.029 (-0.1 – 0.034) | +| Doubling/halving time (days) | -24 (20 – -6.9) | Summarised parameter estimates can also easily be returned, either filtered for a single parameter or for all parameters. @@ -274,19 +284,19 @@ filtered for a single parameter or for all parameters. ``` r head(summary(estimates, type = "parameters", params = "R")) #> date variable strat type median mean sd lower_90 -#> 1: 2020-02-22 R NA estimate 2.155254 2.161351 0.14517723 1.937754 -#> 2: 2020-02-23 R NA estimate 2.121975 2.127980 0.12100600 1.935764 -#> 3: 2020-02-24 R NA estimate 2.088968 2.092729 0.10097692 1.928174 -#> 4: 2020-02-25 R NA estimate 2.054719 2.055714 0.08483110 1.920837 -#> 5: 2020-02-26 R NA estimate 2.016873 2.017134 0.07230558 1.901956 -#> 6: 2020-02-27 R NA estimate 1.977156 1.977250 0.06313689 1.875373 +#> 1: 2020-02-22 R estimate 2.207822 2.213146 0.14734173 1.982468 +#> 2: 2020-02-23 R estimate 2.179067 2.181507 0.12272435 1.987549 +#> 3: 2020-02-24 R estimate 2.147290 2.147666 0.10254391 1.981929 +#> 4: 2020-02-25 R estimate 2.112323 2.111719 0.08673504 1.968592 +#> 5: 2020-02-26 R estimate 2.072160 2.073838 0.07503794 1.949350 +#> 6: 2020-02-27 R estimate 2.035407 2.034248 0.06694049 1.923140 #> lower_50 lower_20 upper_20 upper_50 upper_90 -#> 1: 2.065064 2.121331 2.191464 2.249999 2.402681 -#> 2: 2.046891 2.096318 2.154105 2.204012 2.331598 -#> 3: 2.024262 2.065044 2.116088 2.157788 2.260738 -#> 4: 1.997118 2.033391 2.076033 2.111222 2.193523 -#> 5: 1.967295 1.998732 2.035722 2.064998 2.133431 -#> 6: 1.932713 1.961310 1.993938 2.019524 2.079810 +#> 1: 2.109908 2.171465 2.243879 2.306067 2.472346 +#> 2: 2.095397 2.147798 2.208251 2.260460 2.388300 +#> 3: 2.075982 2.119774 2.171586 2.214484 2.318126 +#> 4: 2.052561 2.088110 2.134212 2.171005 2.255303 +#> 5: 2.022640 2.053441 2.094597 2.125451 2.194531 +#> 6: 1.990618 2.018223 2.051017 2.078120 2.141441 ``` Reported cases are returned in a separate data frame in order to @@ -295,19 +305,19 @@ streamline the reporting of forecasts and for model evaluation. ``` r head(summary(estimates, output = "estimated_reported_cases")) #> date type median mean sd lower_90 lower_50 lower_20 -#> 1: 2020-02-22 gp_rt 64 65.9345 18.66876 40.00 53 60 -#> 2: 2020-02-23 gp_rt 77 79.2645 21.46606 48.00 64 72 -#> 3: 2020-02-24 gp_rt 76 78.7490 21.98367 48.00 64 71 -#> 4: 2020-02-25 gp_rt 74 76.7340 21.21429 45.95 62 69 -#> 5: 2020-02-26 gp_rt 79 81.5060 22.30854 50.00 65 74 -#> 6: 2020-02-27 gp_rt 113 115.6395 30.70588 70.00 94 105 +#> 1: 2020-02-22 gp_rt 66 68.3755 18.89108 41 56 62 +#> 2: 2020-02-23 gp_rt 78 79.6170 21.79236 47 65 73 +#> 3: 2020-02-24 gp_rt 76 78.1660 21.42169 47 62 71 +#> 4: 2020-02-25 gp_rt 73 75.1355 20.95688 44 60 68 +#> 5: 2020-02-26 gp_rt 79 80.2145 22.30202 48 64 73 +#> 6: 2020-02-27 gp_rt 110 112.6800 29.78451 70 91 103 #> upper_20 upper_50 upper_90 -#> 1: 68 76 100.00 -#> 2: 83 92 117.05 -#> 3: 82 91 120.00 -#> 4: 80 89 115.00 -#> 5: 85 95 120.00 -#> 6: 120 134 171.00 +#> 1: 71 80.00 102.00 +#> 2: 83 92.25 118.05 +#> 3: 82 92.00 115.00 +#> 4: 79 88.00 113.00 +#> 5: 84 94.00 119.00 +#> 6: 118 131.00 164.00 ``` A range of plots are returned (with the single summary plot shown @@ -350,25 +360,25 @@ us piecewise constant estimates by week. ``` r estimates <- regional_epinow( reported_cases = reported_cases, - generation_time = generation_time_opts(generation_time), - delays = delay_opts(incubation_period + reporting_delay), + generation_time = generation_time_opts(example_generation_time), + delays = delay_opts(example_incubation_period + reporting_delay), rt = rt_opts(prior = list(mean = 2, sd = 0.2), rw = 7), gp = NULL, stan = stan_opts(cores = 4, warmup = 250, samples = 1000) ) -#> INFO [2023-10-11 14:51:31] Producing following optional outputs: regions, summary, samples, plots, latest -#> INFO [2023-10-11 14:51:31] Reporting estimates using data up to: 2020-04-21 -#> INFO [2023-10-11 14:51:31] No target directory specified so returning output -#> INFO [2023-10-11 14:51:31] Producing estimates for: testland, realland -#> INFO [2023-10-11 14:51:31] Regions excluded: none -#> INFO [2023-10-11 14:51:54] Completed estimates for: testland -#> INFO [2023-10-11 14:52:19] Completed estimates for: realland -#> INFO [2023-10-11 14:52:19] Completed regional estimates -#> INFO [2023-10-11 14:52:19] Regions with estimates: 2 -#> INFO [2023-10-11 14:52:19] Regions with runtime errors: 0 -#> INFO [2023-10-11 14:52:19] Producing summary -#> INFO [2023-10-11 14:52:19] No summary directory specified so returning summary output -#> INFO [2023-10-11 14:52:19] No target directory specified so returning timings +#> INFO [2023-10-19 14:58:09] Producing following optional outputs: regions, summary, samples, plots, latest +#> INFO [2023-10-19 14:58:09] Reporting estimates using data up to: 2020-04-21 +#> INFO [2023-10-19 14:58:09] No target directory specified so returning output +#> INFO [2023-10-19 14:58:09] Producing estimates for: testland, realland +#> INFO [2023-10-19 14:58:09] Regions excluded: none +#> INFO [2023-10-19 14:58:46] Completed estimates for: testland +#> INFO [2023-10-19 14:59:22] Completed estimates for: realland +#> INFO [2023-10-19 14:59:22] Completed regional estimates +#> INFO [2023-10-19 14:59:22] Regions with estimates: 2 +#> INFO [2023-10-19 14:59:22] Regions with runtime errors: 0 +#> INFO [2023-10-19 14:59:23] Producing summary +#> INFO [2023-10-19 14:59:23] No summary directory specified so returning summary output +#> INFO [2023-10-19 14:59:23] No target directory specified so returning timings ``` Results from each region are stored in a `regional` list with across @@ -391,10 +401,10 @@ output. knitr::kable(estimates$summary$summarised_results$table) ``` -| Region | New confirmed cases by infection date | Expected change in daily cases | Effective reproduction no. | Rate of growth | Doubling/halving time (days) | -|:---------|:--------------------------------------|:-------------------------------|:---------------------------|:-----------------------|:-----------------------------| -| realland | 2199 (1118 – 4254) | Likely decreasing | 0.87 (0.63 – 1.2) | -0.03 (-0.098 – 0.038) | -23 (18 – -7.1) | -| testland | 2132 (1079 – 4492) | Likely decreasing | 0.86 (0.61 – 1.2) | -0.032 (-0.1 – 0.038) | -21 (18 – -6.6) | +| Region | New confirmed cases by infection date | Expected change in daily cases | Effective reproduction no. | Rate of growth | Doubling/halving time (days) | +|:---------|:--------------------------------------|:-------------------------------|:---------------------------|:------------------------|:-----------------------------| +| realland | 2147 (1101 – 4113) | Likely decreasing | 0.86 (0.63 – 1.1) | -0.032 (-0.094 – 0.029) | -22 (24 – -7.4) | +| testland | 2184 (1248 – 4345) | Likely decreasing | 0.86 (0.66 – 1.2) | -0.031 (-0.082 – 0.036) | -22 (19 – -8.5) | A range of plots are again returned (with the single summary plot shown below). diff --git a/man/figures/unnamed-chunk-15-1.png b/man/figures/unnamed-chunk-15-1.png index fbb92f085..fd563a9d2 100644 Binary files a/man/figures/unnamed-chunk-15-1.png and b/man/figures/unnamed-chunk-15-1.png differ diff --git a/man/figures/unnamed-chunk-19-1.png b/man/figures/unnamed-chunk-19-1.png index f6b247165..2d326e1a0 100644 Binary files a/man/figures/unnamed-chunk-19-1.png and b/man/figures/unnamed-chunk-19-1.png differ