diff --git a/R/epinow.R b/R/epinow.R index 619d10efc..4e027168d 100644 --- a/R/epinow.R +++ b/R/epinow.R @@ -39,20 +39,11 @@ #' # set number of cores to use #' old_opts <- options() #' options(mc.cores = ifelse(interactive(), 4, 1)) -#' # construct example distributions -#' generation_time <- get_generation_time( -#' disease = "SARS-CoV-2", source = "ganyani" -#' ) -#' incubation_period <- get_incubation_period( -#' disease = "SARS-CoV-2", source = "lauer" -#' ) -#' reporting_delay <- dist_spec( -#' mean = convert_to_logmean(2, 1), -#' mean_sd = 0.1, -#' sd = convert_to_logsd(2, 1), -#' sd_sd = 0.1, -#' max = 10 -#' ) +#' +#' # get example delays +#' generation_time <- example_generation_time +#' incubation_period <- example_incubation_period +#' reporting_delay <- example_reporting_delay #' #' # example case data #' reported_cases <- example_confirmed[1:40] diff --git a/R/estimate_infections.R b/R/estimate_infections.R index 93315ee1f..a55f286e0 100644 --- a/R/estimate_infections.R +++ b/R/estimate_infections.R @@ -74,22 +74,10 @@ #' # get example case counts #' reported_cases <- example_confirmed[1:60] #' -#' # set up example generation time -#' generation_time <- get_generation_time( -#' disease = "SARS-CoV-2", source = "ganyani", fixed = TRUE -#' ) -#' # set delays between infection and case report -#' incubation_period <- get_incubation_period( -#' disease = "SARS-CoV-2", source = "lauer", fixed = TRUE -#' ) -#' # delays between infection and case report, with uncertainty -#' incubation_period_uncertain <- get_incubation_period( -#' disease = "SARS-CoV-2", source = "lauer" -#' ) -#' reporting_delay <- dist_spec( -#' mean = convert_to_logmean(2, 1), mean_sd = 0, -#' sd = convert_to_logsd(2, 1), sd_sd = 0, max = 10 -#' ) +#' # get example delays +#' generation_time <- example_generation_time +#' incubation_period <- example_incubation_period +#' reporting_delay <- example_reporting_delay #' #' # for more examples, see the "estimate_infections examples" vignette #' def <- estimate_infections(reported_cases, diff --git a/R/opts.R b/R/opts.R index ae6dc3812..e71b7a71b 100644 --- a/R/opts.R +++ b/R/opts.R @@ -35,8 +35,8 @@ #' dist_spec(mean = 3, sd = 2, mean_sd = 1, sd_sd = 0.5, max = 15) #' ) #' -#' # A generation time sourced from the literature -#' dist <- get_generation_time(disease = "SARS-CoV-2", source = "ganyani") +#' # An example generation time +#' dist <- example_generation_time #' generation_time_opts(dist) generation_time_opts <- function(dist = dist_spec(mean = 1), ..., disease, source, max = 15L, fixed = FALSE, diff --git a/R/regional_epinow.R b/R/regional_epinow.R index 5367fa7d5..b329e022a 100644 --- a/R/regional_epinow.R +++ b/R/regional_epinow.R @@ -65,19 +65,10 @@ #' old_opts <- options() #' options(mc.cores = ifelse(interactive(), 4, 1)) #' -#' # construct example distributions -#' generation_time <- get_generation_time( -#' disease = "SARS-CoV-2", source = "ganyani" -#' ) -#' incubation_period <- get_incubation_period( -#' disease = "SARS-CoV-2", source = "lauer" -#' ) -#' reporting_delay <- dist_spec( -#' mean = convert_to_logmean(2, 1), -#' mean_sd = 0.1, -#' sd = convert_to_logsd(2, 1), -#' sd_sd = 0.1, max = 15 -#' ) +#' # use example distributions +#' generation_time <- example_generation_time +#' incubation_period <- example_incubation_period +#' reporting_delay <- example_reporting_delay #' #' # uses example case vector #' cases <- example_confirmed[1:60] diff --git a/R/report.R b/R/report.R index 13f55ba7f..71e3cfb74 100644 --- a/R/report.R +++ b/R/report.R @@ -32,17 +32,10 @@ #' # define example cases #' cases <- example_confirmed[1:40] #' -#' # set up example delays -#' generation_time <- get_generation_time( -#' disease = "SARS-CoV-2", source = "ganyani" -#' ) -#' incubation_period <- get_incubation_period( -#' disease = "SARS-CoV-2", source = "lauer" -#' ) -#' reporting_delay <- dist_spec( -#' mean = convert_to_logmean(2, 1), mean_sd = 0.1, -#' sd = convert_to_logsd(2, 1), sd_sd = 0.1, max = 10 -#' ) +#' # get example delays +#' generation_time <- example_generation_time +#' incubation_period <- example_incubation_period +#' reporting_delay <- example_reporting_delay #' #' # Instead of running them model we use example #' # data for speed in this example. diff --git a/R/simulate_infections.R b/R/simulate_infections.R index 49282369f..60625fd41 100644 --- a/R/simulate_infections.R +++ b/R/simulate_infections.R @@ -46,18 +46,11 @@ #' # get example case counts #' reported_cases <- example_confirmed[1:50] #' -#' # set up example generation time -#' generation_time <- get_generation_time( -#' disease = "SARS-CoV-2", source = "ganyani" -#' ) +#' # use example generation times provided with the package +#' generation_time <- example_generation_time #' # set delays between infection and case report -#' incubation_period <- get_incubation_period( -#' disease = "SARS-CoV-2", source = "lauer" -#' ) -#' reporting_delay <- dist_spec( -#' mean = convert_to_logmean(2, 1), mean_sd = 0.1, -#' sd = convert_to_logsd(2, 1), sd_sd = 0.1, max = 15 -#' ) +#' incubation_period <- example_incubation_period +#' reporting_delay <- example_reporting_delay #' #' # fit model to data to recover Rt estimates #' est <- estimate_infections(reported_cases, diff --git a/README.Rmd b/README.Rmd index 8f463e2e4..dd6665066 100644 --- a/README.Rmd +++ b/README.Rmd @@ -107,21 +107,14 @@ reporting_delay <- estimate_delay( If data was not available we could instead make an informed estimate of the likely delay (*this is a synthetic example and not applicable to real world use cases and we have not included uncertainty to decrease runtimes*), ```{r} -reporting_delay <- dist_spec( - mean = convert_to_logmean(2, 1), sd = convert_to_logsd(2, 1), max = 10, - dist = "lognormal" -) +reporting_delay <- example_reporting_delay ``` -Here we define the incubation period and generation time based on literature estimates for 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.* +Here we define the incubation period and generation time based on example literature estimates for Covid-19 (see [here](https://github.com/epiforecasts/EpiNow2/tree/main/data-raw) for 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 -) +generation_time <- example_generation_time +incubation_period <- example_incubation_period ``` ### [epinow()](https://epiforecasts.io/EpiNow2/reference/epinow.html) diff --git a/data-raw/estimate-infections.R b/data-raw/estimate-infections.R index 835d0e7b3..6a0561e6d 100644 --- a/data-raw/estimate-infections.R +++ b/data-raw/estimate-infections.R @@ -6,24 +6,11 @@ options(mc.cores = 4) # get example case counts reported_cases <- example_confirmed[1:60] -# set up example generation time -generation_time <- get_generation_time( - disease = "SARS-CoV-2", source = "ganyani", fixed = TRUE -) -# set delays between infection and case report -incubation_period <- get_incubation_period( - disease = "SARS-CoV-2", source = "lauer", fixed = TRUE -) -# delays between infection and case report, with uncertainty -incubation_period_uncertain <- get_incubation_period( - disease = "SARS-CoV-2", source = "lauer" -) -reporting_delay <- dist_spec( - mean = convert_to_logmean(2, 1), mean_sd = 0, - sd = convert_to_logsd(2, 1), sd_sd = 0, max = 10 -) +#' # use example distributions +generation_time <- example_generation_time +incubation_period <- example_incubation_period +reporting_delay <- example_reporting_delay -# default settings but assuming that delays are fixed rather than uncertain example_estimate_infections <- estimate_infections(reported_cases, generation_time = generation_time_opts(generation_time), delays = delay_opts(incubation_period + reporting_delay), diff --git a/inst/dev/recover-synthetic/rt.R b/inst/dev/recover-synthetic/rt.R index 9ab84a919..8d5ba0552 100644 --- a/inst/dev/recover-synthetic/rt.R +++ b/inst/dev/recover-synthetic/rt.R @@ -6,14 +6,10 @@ source(here::here("inst", "dev", "recover-synthetic", "plot.R")) old_opts <- options() options(mc.cores = 4) -# set up example generation time -generation_time <- get_generation_time(disease = "SARS-CoV-2", source = "ganyani") -# set delays between infection and case report -incubation_period <- get_incubation_period(disease = "SARS-CoV-2", source = "lauer") -reporting_delay <- dist_spec( - mean = convert_to_logmean(2, 1), mean_sd = 0.1, - sd = convert_to_logsd(2, 1), sd_sd = 0.1, max = 15 -) +#' get example delays +generation_time <- example_generation_time +incubation_period <- example_incubation_period +reporting_delay <- example_reporting_delay obs <- obs_opts(scale = list(mean = 0.1, sd = 0.025), return_likelihood = TRUE) diff --git a/man/epinow.Rd b/man/epinow.Rd index e0237dcbf..872696df7 100644 --- a/man/epinow.Rd +++ b/man/epinow.Rd @@ -127,20 +127,11 @@ set intervals on a deidcated server. # set number of cores to use old_opts <- options() options(mc.cores = ifelse(interactive(), 4, 1)) -# construct example distributions -generation_time <- get_generation_time( - disease = "SARS-CoV-2", source = "ganyani" -) -incubation_period <- get_incubation_period( - disease = "SARS-CoV-2", source = "lauer" -) -reporting_delay <- dist_spec( - mean = convert_to_logmean(2, 1), - mean_sd = 0.1, - sd = convert_to_logsd(2, 1), - sd_sd = 0.1, - max = 10 -) + +# get example delays +generation_time <- example_generation_time +incubation_period <- example_incubation_period +reporting_delay <- example_reporting_delay # example case data reported_cases <- example_confirmed[1:40] diff --git a/man/estimate_infections.Rd b/man/estimate_infections.Rd index 4613570e3..be2af06ba 100644 --- a/man/estimate_infections.Rd +++ b/man/estimate_infections.Rd @@ -117,22 +117,10 @@ options(mc.cores = ifelse(interactive(), 4, 1)) # get example case counts reported_cases <- example_confirmed[1:60] -# set up example generation time -generation_time <- get_generation_time( - disease = "SARS-CoV-2", source = "ganyani", fixed = TRUE -) -# set delays between infection and case report -incubation_period <- get_incubation_period( - disease = "SARS-CoV-2", source = "lauer", fixed = TRUE -) -# delays between infection and case report, with uncertainty -incubation_period_uncertain <- get_incubation_period( - disease = "SARS-CoV-2", source = "lauer" -) -reporting_delay <- dist_spec( - mean = convert_to_logmean(2, 1), mean_sd = 0, - sd = convert_to_logsd(2, 1), sd_sd = 0, max = 10 -) +# get example delays +generation_time <- example_generation_time +incubation_period <- example_incubation_period +reporting_delay <- example_reporting_delay # for more examples, see the "estimate_infections examples" vignette def <- estimate_infections(reported_cases, diff --git a/man/generation_time_opts.Rd b/man/generation_time_opts.Rd index 2674b201e..4eef0a9b6 100644 --- a/man/generation_time_opts.Rd +++ b/man/generation_time_opts.Rd @@ -55,8 +55,8 @@ generation_time_opts( dist_spec(mean = 3, sd = 2, mean_sd = 1, sd_sd = 0.5, max = 15) ) -# A generation time sourced from the literature -dist <- get_generation_time(disease = "SARS-CoV-2", source = "ganyani") +# An example generation time +dist <- example_generation_time generation_time_opts(dist) } \seealso{ diff --git a/man/regional_epinow.Rd b/man/regional_epinow.Rd index 671f530c5..293273d6b 100644 --- a/man/regional_epinow.Rd +++ b/man/regional_epinow.Rd @@ -134,19 +134,10 @@ progressr::handlers and enable it in batch by setting old_opts <- options() options(mc.cores = ifelse(interactive(), 4, 1)) -# construct example distributions -generation_time <- get_generation_time( - disease = "SARS-CoV-2", source = "ganyani" -) -incubation_period <- get_incubation_period( - disease = "SARS-CoV-2", source = "lauer" -) -reporting_delay <- dist_spec( - mean = convert_to_logmean(2, 1), - mean_sd = 0.1, - sd = convert_to_logsd(2, 1), - sd_sd = 0.1, max = 15 -) +# use example distributions +generation_time <- example_generation_time +incubation_period <- example_incubation_period +reporting_delay <- example_reporting_delay # uses example case vector cases <- example_confirmed[1:60] diff --git a/man/report_cases.Rd b/man/report_cases.Rd index 6575ace52..a7eeb5d53 100644 --- a/man/report_cases.Rd +++ b/man/report_cases.Rd @@ -53,17 +53,10 @@ the \code{stan} implementation. # define example cases cases <- example_confirmed[1:40] -# set up example delays -generation_time <- get_generation_time( - disease = "SARS-CoV-2", source = "ganyani" -) -incubation_period <- get_incubation_period( - disease = "SARS-CoV-2", source = "lauer" -) -reporting_delay <- dist_spec( - mean = convert_to_logmean(2, 1), mean_sd = 0.1, - sd = convert_to_logsd(2, 1), sd_sd = 0.1, max = 10 -) +# get example delays +generation_time <- example_generation_time +incubation_period <- example_incubation_period +reporting_delay <- example_reporting_delay # Instead of running them model we use example # data for speed in this example. diff --git a/man/simulate_infections.Rd b/man/simulate_infections.Rd index 6605551ed..793c4ed8a 100644 --- a/man/simulate_infections.Rd +++ b/man/simulate_infections.Rd @@ -57,18 +57,11 @@ options(mc.cores = ifelse(interactive(), 4, 1)) # get example case counts reported_cases <- example_confirmed[1:50] -# set up example generation time -generation_time <- get_generation_time( - disease = "SARS-CoV-2", source = "ganyani" -) +# use example generation times provided with the package +generation_time <- example_generation_time # set delays between infection and case report -incubation_period <- get_incubation_period( - disease = "SARS-CoV-2", source = "lauer" -) -reporting_delay <- dist_spec( - mean = convert_to_logmean(2, 1), mean_sd = 0.1, - sd = convert_to_logsd(2, 1), sd_sd = 0.1, max = 15 -) +incubation_period <- example_incubation_period +reporting_delay <- example_reporting_delay # fit model to data to recover Rt estimates est <- estimate_infections(reported_cases, diff --git a/tests/testthat/test-epinow.R b/tests/testthat/test-epinow.R index ed9d2867c..fc4a9852b 100644 --- a/tests/testthat/test-epinow.R +++ b/tests/testthat/test-epinow.R @@ -1,13 +1,9 @@ skip_on_cran() - -generation_time <- get_generation_time(disease = "SARS-CoV-2", source = "ganyani", max_value = 15) -incubation_period <- get_incubation_period(disease = "SARS-CoV-2", source = "lauer", max_value = 15) -reporting_delay <- dist_spec( - mean = convert_to_logmean(2, 1), mean_sd = 0.1, - sd = convert_to_logsd(2, 1), sd_sd = 0.1, - max = 10 -) +# get example delays +generation_time <- example_generation_time +incubation_period <- example_incubation_period +reporting_delay <- example_reporting_delay reported_cases <- EpiNow2::example_confirmed[1:30] diff --git a/tests/testthat/test-estimate_infections.R b/tests/testthat/test-estimate_infections.R index cc639d858..403a98b6f 100644 --- a/tests/testthat/test-estimate_infections.R +++ b/tests/testthat/test-estimate_infections.R @@ -2,13 +2,12 @@ futile.logger::flog.threshold("FATAL") +# get example delays +generation_time <- example_generation_time +incubation_period <- example_incubation_period +reporting_delay <- example_reporting_delay + reported_cases <- EpiNow2::example_confirmed[1:30] -generation_time <- get_generation_time(disease = "SARS-CoV-2", source = "ganyani", max_value = 10) -incubation_period <- get_incubation_period(disease = "SARS-CoV-2", source = "lauer", max_value = 10) -reporting_delay <- dist_spec( - mean = convert_to_logmean(2, 1), mean_sd = 0.1, - sd = convert_to_logsd(2, 1), sd_sd = 0.1, max = 10 -) default_estimate_infections <- function(..., add_stan = list(), delay = TRUE) { futile.logger::flog.threshold("FATAL") diff --git a/tests/testthat/test-models/estimate_infections.R b/tests/testthat/test-models/estimate_infections.R index 0ba61d1c6..812cb7275 100644 --- a/tests/testthat/test-models/estimate_infections.R +++ b/tests/testthat/test-models/estimate_infections.R @@ -1,11 +1,7 @@ -reported_cases <- EpiNow2::example_confirmed[1:30] -generation_time <- get_generation_time( - disease = "SARS-CoV-2", source = "ganyani", max_value = 10 -) -incubation_period <- get_incubation_period( - disease = "SARS-CoV-2", source = "lauer", max_value = 10 -) +#' get example delays +generation_time <- example_generation_time +incubation_period <- example_incubation_period # static model fit <- estimate_infections( diff --git a/tests/testthat/test-models/regional_epinow.R b/tests/testthat/test-models/regional_epinow.R index ee6342b85..17214de8f 100644 --- a/tests/testthat/test-models/regional_epinow.R +++ b/tests/testthat/test-models/regional_epinow.R @@ -1,9 +1,6 @@ -generation_time <- EpiNow2::get_generation_time( - disease = "SARS-CoV-2", source = "ganyani", max_value = 10 -) -incubation_period <- EpiNow2::get_incubation_period( - disease = "SARS-CoV-2", source = "lauer", max_value = 10 -) +#' get example delays +generation_time <- example_generation_time +incubation_period <- example_incubation_period cases <- EpiNow2::example_confirmed[1:30] cases <- data.table::rbindlist(list( diff --git a/tests/testthat/test-regional_epinow.R b/tests/testthat/test-regional_epinow.R index bb718e2d0..5042c243b 100644 --- a/tests/testthat/test-regional_epinow.R +++ b/tests/testthat/test-regional_epinow.R @@ -1,11 +1,9 @@ skip_on_cran() -generation_time <- get_generation_time(disease = "SARS-CoV-2", source = "ganyani", max_value = 5) -reporting_delay <- dist_spec( - mean = log(3), mean_sd = 0.1, - sd = log(2), sd_sd = 0.1, max = 5 -) +# get example delays +generation_time <- example_generation_time +reporting_delay <- example_reporting_delay futile.logger::flog.threshold("FATAL") diff --git a/tests/testthat/test-regional_runtimes.R b/tests/testthat/test-regional_runtimes.R index 13ce6f5ae..0e4c32390 100644 --- a/tests/testthat/test-regional_runtimes.R +++ b/tests/testthat/test-regional_runtimes.R @@ -1,8 +1,6 @@ -generation_time <- get_generation_time(disease = "SARS-CoV-2", source = "ganyani", max_value = 5) -reporting_delay <- dist_spec( - mean = log(3), mean_sd = 0.1, - sd = log(2), sd_sd = 0.1, max = 5 -) +#' # get example delays +generation_time <- example_generation_time +reporting_delay <- example_reporting_delay futile.logger::flog.threshold("FATAL") # uses example case vector diff --git a/tests/testthat/test-report_cases.R b/tests/testthat/test-report_cases.R index 54fa17df5..0e67502e9 100644 --- a/tests/testthat/test-report_cases.R +++ b/tests/testthat/test-report_cases.R @@ -2,17 +2,10 @@ test_that("report_cases can simulate infections forward", { # define example cases cases <- example_confirmed[1:10] - # set up example delays - generation_time <- get_generation_time( - disease = "SARS-CoV-2", source = "ganyani" - ) - incubation_period <- get_incubation_period( - disease = "SARS-CoV-2", source = "lauer" - ) - reporting_delay <- dist_spec( - mean = convert_to_logmean(2, 1), mean_sd = 0.1, - sd = convert_to_logsd(2, 1), sd_sd = 0.1, max = 5 - ) + #' get example delays + generation_time <- example_generation_time + incubation_period <- example_incubation_period + reporting_delay <- example_reporting_delay # Instead of running them model we use example # data for speed in this example. diff --git a/tests/testthat/test-simulate_infections.R b/tests/testthat/test-simulate_infections.R index 422788db6..282b96fef 100644 --- a/tests/testthat/test-simulate_infections.R +++ b/tests/testthat/test-simulate_infections.R @@ -2,12 +2,9 @@ skip_on_cran() # Setup for testing ------------------------------------------------------- futile.logger::flog.threshold("FATAL") reported_cases <- EpiNow2::example_confirmed[1:50] -generation_time <- get_generation_time(disease = "SARS-CoV-2", source = "ganyani", max_value = 10) -incubation_period <- get_incubation_period(disease = "SARS-CoV-2", source = "lauer", max_value = 10) -reporting_delay <- dist_spec( - mean = convert_to_logmean(2, 1), mean_sd = 0.1, - sd = convert_to_logsd(2, 1), sd_sd = 0.1, max = 10 -) +#' get example delays +generation_time <- example_generation_time +reporting_delay <- example_reporting_delay out <- suppressWarnings(estimate_infections(reported_cases, generation_time = generation_time_opts(generation_time), diff --git a/touchstone/setup.R b/touchstone/setup.R index d06725aae..e9cf3f6ef 100644 --- a/touchstone/setup.R +++ b/touchstone/setup.R @@ -2,36 +2,16 @@ library("EpiNow2") reported_cases <- example_confirmed[1:60] -# set up example generation time -generation_time <- get_generation_time( - disease = "SARS-CoV-2", source = "ganyani", fixed = TRUE -) - -# set delays between infection and case report -incubation_period <- get_incubation_period( - disease = "SARS-CoV-2", source = "lauer", fixed = TRUE -) - -reporting_delay <- dist_spec( - mean = convert_to_logmean(2, 1), mean_sd = 0, - sd = convert_to_logsd(2, 1), sd_sd = 0, max = 10 -) +# get example delays +generation_time <- fix_dist(example_generation_time) +incubation_period <- fix_dist(example_incubation_period) +reporting_delay <- fix_dist(example_reporting_delay) delays <- delay_opts(incubation_period + reporting_delay) # set up example generation time -u_generation_time <- get_generation_time( - disease = "SARS-CoV-2", source = "ganyani", fixed = FALSE -) - -# set delays between infection and case report -u_incubation_period <- get_incubation_period( - disease = "SARS-CoV-2", source = "lauer", fixed = FALSE -) - -u_reporting_delay <- dist_spec( - mean = convert_to_logmean(2, 1), mean_sd = 0.1, - sd = convert_to_logsd(2, 1), sd_sd = 0.1, max = 10 -) +u_generation_time <- example_generation_time +u_incubation_period <- example_incubation_period +u_reporting_delay <- example_reporting_delay u_delays <- delay_opts(u_incubation_period + u_reporting_delay)