From 71609b358b45831d5d3371cf10f72af2ca9e024a Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Tue, 19 Sep 2023 09:29:39 +0200 Subject: [PATCH] remove long run time examples --- R/estimate_infections.R | 137 +----------------------------------- R/get.R | 37 +--------- R/plot.R | 25 ++----- R/regional_epinow.R | 19 +---- R/report.R | 27 +------ R/summarise.R | 58 ++------------- man/estimate_infections.Rd | 137 +----------------------------------- man/get_regional_results.Rd | 37 +--------- man/plot_estimates.Rd | 25 ++----- man/regional_epinow.Rd | 19 +---- man/regional_runtimes.Rd | 27 +------ man/regional_summary.Rd | 31 +------- man/report_plots.Rd | 27 +------ 13 files changed, 30 insertions(+), 576 deletions(-) diff --git a/R/estimate_infections.R b/R/estimate_infections.R index 2574a45d6..d503c20cc 100644 --- a/R/estimate_infections.R +++ b/R/estimate_infections.R @@ -91,7 +91,7 @@ #' sd = convert_to_logsd(2, 1), sd_sd = 0, max = 10 #' ) #' -#' # default settings but assuming that delays are fixed rather than uncertain +#' # for more examples, see the "estimate_infections examples" vignette #' def <- estimate_infections(reported_cases, #' generation_time = generation_time_opts(generation_time), #' delays = delay_opts(incubation_period + reporting_delay), @@ -102,141 +102,6 @@ #' summary(def) #' # summary plot #' plot(def) -#' -#' # decreasing the accuracy of the approximate Gaussian to speed up -#' #computation. -#' # These settings are an area of active research. See ?gp_opts for details. -#' agp <- estimate_infections(reported_cases, -#' generation_time = generation_time_opts(generation_time), -#' delays = delay_opts(incubation_period + reporting_delay), -#' rt = rt_opts(prior = list(mean = 2, sd = 0.1)), -#' gp = gp_opts(ls_min = 10, basis_prop = 0.1), -#' stan = stan_opts(control = list(adapt_delta = 0.95)) -#' ) -#' summary(agp) -#' plot(agp) -#' -#' # Adjusting for future susceptible depletion -#' dep <- estimate_infections(reported_cases, -#' generation_time = generation_time_opts(generation_time), -#' delays = delay_opts(incubation_period + reporting_delay), -#' rt = rt_opts( -#' prior = list(mean = 2, sd = 0.1), -#' pop = 1000000, future = "latest" -#' ), -#' gp = gp_opts(ls_min = 10, basis_prop = 0.1), horizon = 21, -#' stan = stan_opts(control = list(adapt_delta = 0.95)) -#' ) -#' plot(dep) -#' -#' # Adjusting for truncation of the most recent data -#' # See estimate_truncation for an approach to estimating this from data -#' trunc_dist <- dist_spec( -#' mean = convert_to_logmean(0.5, 0.5), mean_sd = 0.1, -#' sd = convert_to_logsd(0.5, 0.5), sd_sd = 0.1, -#' max = 3 -#' ) -#' trunc <- estimate_infections(reported_cases, -#' generation_time = generation_time_opts(generation_time), -#' delays = delay_opts(incubation_period + reporting_delay), -#' truncation = trunc_opts(trunc_dist), -#' rt = rt_opts(prior = list(mean = 2, sd = 0.1)), -#' gp = gp_opts(ls_min = 10, basis_prop = 0.1), -#' stan = stan_opts(control = list(adapt_delta = 0.95)) -#' ) -#' plot(trunc) -#' -#' # using back calculation (combined here with under reporting) -#' # this model is in the order of 10 ~ 100 faster than the gaussian process -#' # method -#' # it is likely robust for retrospective Rt but less reliable for real time -#' # estimates -#' # the width of the prior window controls the reliance on observed data and -#' # can be optionally switched off using backcalc_opts(prior = "none"), -#' # see ?backcalc_opts for other options -#' backcalc <- estimate_infections(reported_cases, -#' generation_time = generation_time_opts(generation_time), -#' delays = delay_opts(incubation_period + reporting_delay), -#' rt = NULL, backcalc = backcalc_opts(), -#' obs = obs_opts(scale = list(mean = 0.4, sd = 0.05)), -#' horizon = 0 -#' ) -#' plot(backcalc) -#' -#' # Rt projected into the future using the Gaussian process -#' project_rt <- estimate_infections(reported_cases, -#' generation_time = generation_time_opts(generation_time), -#' delays = delay_opts(incubation_period + reporting_delay), -#' rt = rt_opts( -#' prior = list(mean = 2, sd = 0.1), -#' future = "project" -#' ) -#' ) -#' plot(project_rt) -#' -#' # default settings on a later snapshot of data -#' snapshot_cases <- example_confirmed[80:130] -#' snapshot <- estimate_infections(snapshot_cases, -#' generation_time = generation_time_opts(generation_time), -#' delays = delay_opts(incubation_period + reporting_delay), -#' rt = rt_opts(prior = list(mean = 1, sd = 0.1)) -#' ) -#' plot(snapshot) -#' -#' # stationary Rt assumption (likely to provide biased real-time estimates) -#' # with uncertain reporting delays -#' stat <- estimate_infections(reported_cases, -#' generation_time = generation_time_opts(generation_time), -#' delays = delay_opts(incubation_period_uncertain + reporting_delay), -#' rt = rt_opts(prior = list(mean = 2, sd = 0.1), gp_on = "R0") -#' ) -#' plot(stat) -#' -#' # no gaussian process (i.e fixed Rt assuming no breakpoints) -#' # with uncertain reporting delays -#' fixed <- estimate_infections(reported_cases, -#' generation_time = generation_time_opts(generation_time), -#' delays = delay_opts(incubation_period_uncertain + reporting_delay), -#' gp = NULL -#' ) -#' plot(fixed) -#' -#' # no delays -#' no_delay <- estimate_infections( -#' reported_cases, -#' generation_time = generation_time_opts(generation_time) -#' ) -#' plot(no_delay) -#' -#' # break point but otherwise static Rt -#' # with uncertain reporting delays -#' bp_cases <- data.table::copy(reported_cases) -#' bp_cases <- bp_cases[, -#' breakpoint := ifelse(date == as.Date("2020-03-16"), 1, 0) -#' ] -#' bkp <- estimate_infections(bp_cases, -#' generation_time = generation_time_opts(generation_time), -#' delays = delay_opts(incubation_period_uncertain + reporting_delay), -#' rt = rt_opts(prior = list(mean = 2, sd = 0.1)), -#' gp = NULL -#' ) -#' # break point effect -#' summary(bkp, type = "parameters", params = "breakpoints") -#' plot(bkp) -#' -#' # weekly random walk -#' # with uncertain reporting delays -#' rw <- estimate_infections(reported_cases, -#' generation_time = generation_time_opts(generation_time), -#' delays = delay_opts(incubation_period_uncertain + reporting_delay), -#' rt = rt_opts(prior = list(mean = 2, sd = 0.1), rw = 7), -#' gp = NULL -#' ) -#' -#' # random walk effects -#' summary(rw, type = "parameters", params = "breakpoints") -#' plot(rw) -#' #' options(old_opts) #' } estimate_infections <- function(reported_cases, diff --git a/R/get.R b/R/get.R index f0c21912e..fe01ab243 100644 --- a/R/get.R +++ b/R/get.R @@ -70,43 +70,10 @@ get_raw_result <- function(file, region, date, #' @importFrom purrr map safely #' @importFrom data.table rbindlist #' @examples -#' \donttest{ -#' # 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 <- estimate_delay(rlnorm(100, log(6), 1), max_value = 10) -#' -#' # example case vector -#' cases <- example_confirmed[1:30] -#' cases <- data.table::rbindlist(list( -#' data.table::copy(cases)[, region := "testland"], -#' cases[, region := "realland"] -#' )) -#' -#' # save results to tmp folder -#' dir <- file.path(tempdir(check = TRUE), "results") -#' # run multiregion estimates -#' regional_out <- regional_epinow( -#' reported_cases = cases, -#' generation_time = generation_time_opts(generation_time), -#' delays = delay_opts(incubation_period + reporting_delay), -#' rt = rt_opts(rw = 7), gp = NULL, -#' output = c("regions", "latest"), -#' target_folder = dir, -#' return_output = TRUE -#' ) +#' # get example multiregion estimates +#' regional_out <- example_regional_epinow #' # from output #' results <- get_regional_results(regional_out$regional, samples = FALSE) -#' names(results) -#' -#' # from a folder -#' folder_results <- get_regional_results(results_dir = dir, samples = FALSE) -#' names(folder_results) -#' } get_regional_results <- function(regional_output, results_dir, date, samples = TRUE, diff --git a/R/plot.R b/R/plot.R index 458efcc8e..5a92401d6 100644 --- a/R/plot.R +++ b/R/plot.R @@ -79,35 +79,19 @@ plot_CrIs <- function(plot, CrIs, alpha, linewidth) { #' @importFrom data.table setDT fifelse copy as.data.table #' @importFrom purrr map #' @examples -#' \donttest{ -#' # 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 <- estimate_delay(rlnorm(100, log(6), 1), max_value = 10) -#' -#' # run model -#' out <- estimate_infections(cases, -#' generation_time = generation_time_opts(generation_time), -#' delays = delay_opts(incubation_period + reporting_delay) -#' ) +#' # get example model results +#' out <- example_estimate_infections #' # plot infections #' plot_estimates( #' estimate = out$summarised[variable == "infections"], -#' reported = cases, +#' reported = out$observations, #' ylab = "Cases", max_plot = 2 #' ) + ggplot2::facet_wrap(~type, scales = "free_y") #' #' # plot reported cases estimated via Rt #' plot_estimates( #' estimate = out$summarised[variable == "reported_cases"], -#' reported = cases, +#' reported = out$observations, #' ylab = "Cases" #' ) #' @@ -124,7 +108,6 @@ plot_CrIs <- function(plot, CrIs, alpha, linewidth) { #' ylab = "Effective Reproduction No.", #' hline = 1, estimate_type = "Estimate" #' ) -#' } plot_estimates <- function(estimate, reported, ylab = "Cases", hline, obs_as_col = TRUE, max_plot = 10, estimate_type = NULL) { diff --git a/R/regional_epinow.R b/R/regional_epinow.R index dbb5a56cc..3001faa80 100644 --- a/R/regional_epinow.R +++ b/R/regional_epinow.R @@ -88,6 +88,7 @@ #' #' # run epinow across multiple regions and generate summaries #' # samples and warmup have been reduced for this example +#' # for more examples, see the "estimate_infections examples" vignette #' def <- regional_epinow( #' reported_cases = cases, #' generation_time = generation_time_opts(generation_time), @@ -99,24 +100,6 @@ #' ), #' verbose = interactive() #' ) -#' -#' # apply a different rt method per region -#' # (here a gaussian process and a weekly random walk) -#' gp <- opts_list(gp_opts(), cases) -#' gp <- update_list(gp, list(realland = NULL)) -#' rt <- opts_list(rt_opts(), cases, realland = rt_opts(rw = 7)) -#' region_rt <- regional_epinow( -#' reported_cases = cases, -#' generation_time = generation_time_opts(generation_time), -#' delays = delay_opts(incubation_period + reporting_delay), -#' rt = rt, gp = gp, -#' stan = stan_opts( -#' samples = 100, warmup = 200, -#' control = list(adapt_delta = 0.95) -#' ), -#' verbose = interactive() -#' ) -#' #' options(old_opts) #' } regional_epinow <- function(reported_cases, diff --git a/R/report.R b/R/report.R index 734f21b38..aa1f22de5 100644 --- a/R/report.R +++ b/R/report.R @@ -262,36 +262,15 @@ report_summary <- function(summarised_estimates, #' `summarised_estimates[variable == "growth_rate"]`, respectively. #' @export #' @examples -#' \donttest{ -#' # 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 <- bootstrapped_dist_fit( -#' rlnorm(100, log(6), 1), max_value = 30 -#' ) -#' -#' # run model -#' out <- estimate_infections(cases, -#' stan = stan_opts(samples = 500), -#' generation_time = generation_time_opts(generation_time), -#' delays = delay_opts(incubation_period + reporting_delay), -#' rt = NULL -#' ) +#' # get example output form estimate_infections +#' out <- example_estimate_infections #' #' # plot infections #' plots <- report_plots( #' summarised_estimates = out$summarised, -#' reported = cases +#' reported = out$observations #' ) #' plots -#' } report_plots <- function(summarised_estimates, reported, target_folder = NULL, ...) { # set input to data.table diff --git a/R/summarise.R b/R/summarise.R index c53f464dd..d5e821c23 100644 --- a/R/summarise.R +++ b/R/summarise.R @@ -165,37 +165,12 @@ summarise_results <- function(regions, #' @importFrom data.table setDT fcase #' @importFrom futile.logger flog.info #' @examples -#' \donttest{ -#' # 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 <- estimate_delay(rlnorm(100, log(6), 1), max_value = 30) -#' -#' # example case vector from EpiSoon -#' cases <- example_confirmed[1:30] -#' cases <- data.table::rbindlist(list( -#' data.table::copy(cases)[, region := "testland"], -#' cases[, region := "realland"] -#' )) -#' -#' # run basic nowcasting pipeline -#' out <- regional_epinow( -#' reported_cases = cases, -#' generation_time = generation_time_opts(generation_time), -#' delays = delay_opts(incubation_period + reporting_delay), -#' output = "region", -#' rt = NULL -#' ) -#' +#' # get example output from regional_epinow model +#' out <- example_regional_epinow #' regional_summary( #' regional_output = out$regional, -#' reported_cases = cases +#' reported_cases = out$summary$reported_cases #' ) -#' } regional_summary <- function(regional_output = NULL, reported_cases, results_dir = NULL, @@ -526,33 +501,8 @@ summarise_key_measures <- function(regional_results = NULL, #' @importFrom data.table data.table fwrite #' @importFrom purrr map safely #' @examples -#' \donttest{ -#' # 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 <- estimate_delay(rlnorm(100, log(6), 1), max_value = 15) -#' -#' cases <- example_confirmed[1:30] -#' cases <- data.table::rbindlist(list( -#' data.table::copy(cases)[, region := "testland"], -#' cases[, region := "realland"] -#' )) -#' -#' # run basic nowcasting pipeline -#' regional_out <- regional_epinow( -#' reported_cases = cases, -#' generation_time = generation_time_opts(generation_time), -#' delays = delay_opts(incubation_period + reporting_delay), -#' stan = stan_opts(samples = 100, warmup = 100), -#' output = c("region", "timing") -#' ) -#' +#' regional_out <- example_regional_epinow # get example run outputs #' regional_runtimes(regional_output = regional_out$regional) -#' } regional_runtimes <- function(regional_output = NULL, target_folder = NULL, target_date = NULL, diff --git a/man/estimate_infections.Rd b/man/estimate_infections.Rd index f31e9b6a3..37080f9cf 100644 --- a/man/estimate_infections.Rd +++ b/man/estimate_infections.Rd @@ -134,7 +134,7 @@ reporting_delay <- dist_spec( sd = convert_to_logsd(2, 1), sd_sd = 0, max = 10 ) -# default settings but assuming that delays are fixed rather than uncertain +# for more examples, see the "estimate_infections examples" vignette def <- estimate_infections(reported_cases, generation_time = generation_time_opts(generation_time), delays = delay_opts(incubation_period + reporting_delay), @@ -145,141 +145,6 @@ def <- estimate_infections(reported_cases, summary(def) # summary plot plot(def) - -# decreasing the accuracy of the approximate Gaussian to speed up -#computation. -# These settings are an area of active research. See ?gp_opts for details. -agp <- estimate_infections(reported_cases, - generation_time = generation_time_opts(generation_time), - delays = delay_opts(incubation_period + reporting_delay), - rt = rt_opts(prior = list(mean = 2, sd = 0.1)), - gp = gp_opts(ls_min = 10, basis_prop = 0.1), - stan = stan_opts(control = list(adapt_delta = 0.95)) -) -summary(agp) -plot(agp) - -# Adjusting for future susceptible depletion -dep <- estimate_infections(reported_cases, - generation_time = generation_time_opts(generation_time), - delays = delay_opts(incubation_period + reporting_delay), - rt = rt_opts( - prior = list(mean = 2, sd = 0.1), - pop = 1000000, future = "latest" - ), - gp = gp_opts(ls_min = 10, basis_prop = 0.1), horizon = 21, - stan = stan_opts(control = list(adapt_delta = 0.95)) -) -plot(dep) - -# Adjusting for truncation of the most recent data -# See estimate_truncation for an approach to estimating this from data -trunc_dist <- dist_spec( - mean = convert_to_logmean(0.5, 0.5), mean_sd = 0.1, - sd = convert_to_logsd(0.5, 0.5), sd_sd = 0.1, - max = 3 -) -trunc <- estimate_infections(reported_cases, - generation_time = generation_time_opts(generation_time), - delays = delay_opts(incubation_period + reporting_delay), - truncation = trunc_opts(trunc_dist), - rt = rt_opts(prior = list(mean = 2, sd = 0.1)), - gp = gp_opts(ls_min = 10, basis_prop = 0.1), - stan = stan_opts(control = list(adapt_delta = 0.95)) -) -plot(trunc) - -# using back calculation (combined here with under reporting) -# this model is in the order of 10 ~ 100 faster than the gaussian process -# method -# it is likely robust for retrospective Rt but less reliable for real time -# estimates -# the width of the prior window controls the reliance on observed data and -# can be optionally switched off using backcalc_opts(prior = "none"), -# see ?backcalc_opts for other options -backcalc <- estimate_infections(reported_cases, - generation_time = generation_time_opts(generation_time), - delays = delay_opts(incubation_period + reporting_delay), - rt = NULL, backcalc = backcalc_opts(), - obs = obs_opts(scale = list(mean = 0.4, sd = 0.05)), - horizon = 0 -) -plot(backcalc) - -# Rt projected into the future using the Gaussian process -project_rt <- estimate_infections(reported_cases, - generation_time = generation_time_opts(generation_time), - delays = delay_opts(incubation_period + reporting_delay), - rt = rt_opts( - prior = list(mean = 2, sd = 0.1), - future = "project" - ) -) -plot(project_rt) - -# default settings on a later snapshot of data -snapshot_cases <- example_confirmed[80:130] -snapshot <- estimate_infections(snapshot_cases, - generation_time = generation_time_opts(generation_time), - delays = delay_opts(incubation_period + reporting_delay), - rt = rt_opts(prior = list(mean = 1, sd = 0.1)) -) -plot(snapshot) - -# stationary Rt assumption (likely to provide biased real-time estimates) -# with uncertain reporting delays -stat <- estimate_infections(reported_cases, - generation_time = generation_time_opts(generation_time), - delays = delay_opts(incubation_period_uncertain + reporting_delay), - rt = rt_opts(prior = list(mean = 2, sd = 0.1), gp_on = "R0") -) -plot(stat) - -# no gaussian process (i.e fixed Rt assuming no breakpoints) -# with uncertain reporting delays -fixed <- estimate_infections(reported_cases, - generation_time = generation_time_opts(generation_time), - delays = delay_opts(incubation_period_uncertain + reporting_delay), - gp = NULL -) -plot(fixed) - -# no delays -no_delay <- estimate_infections( - reported_cases, - generation_time = generation_time_opts(generation_time) -) -plot(no_delay) - -# break point but otherwise static Rt -# with uncertain reporting delays -bp_cases <- data.table::copy(reported_cases) -bp_cases <- bp_cases[, - breakpoint := ifelse(date == as.Date("2020-03-16"), 1, 0) -] -bkp <- estimate_infections(bp_cases, - generation_time = generation_time_opts(generation_time), - delays = delay_opts(incubation_period_uncertain + reporting_delay), - rt = rt_opts(prior = list(mean = 2, sd = 0.1)), - gp = NULL -) -# break point effect -summary(bkp, type = "parameters", params = "breakpoints") -plot(bkp) - -# weekly random walk -# with uncertain reporting delays -rw <- estimate_infections(reported_cases, - generation_time = generation_time_opts(generation_time), - delays = delay_opts(incubation_period_uncertain + reporting_delay), - rt = rt_opts(prior = list(mean = 2, sd = 0.1), rw = 7), - gp = NULL -) - -# random walk effects -summary(rw, type = "parameters", params = "breakpoints") -plot(rw) - options(old_opts) } } diff --git a/man/get_regional_results.Rd b/man/get_regional_results.Rd index 5a16040c4..77432946c 100644 --- a/man/get_regional_results.Rd +++ b/man/get_regional_results.Rd @@ -37,43 +37,10 @@ Summarises results across regions either from input or from disk. See the examples for details. } \examples{ -\donttest{ -# 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 <- estimate_delay(rlnorm(100, log(6), 1), max_value = 10) - -# example case vector -cases <- example_confirmed[1:30] -cases <- data.table::rbindlist(list( - data.table::copy(cases)[, region := "testland"], - cases[, region := "realland"] -)) - -# save results to tmp folder -dir <- file.path(tempdir(check = TRUE), "results") -# run multiregion estimates -regional_out <- regional_epinow( - reported_cases = cases, - generation_time = generation_time_opts(generation_time), - delays = delay_opts(incubation_period + reporting_delay), - rt = rt_opts(rw = 7), gp = NULL, - output = c("regions", "latest"), - target_folder = dir, - return_output = TRUE -) +# get example multiregion estimates +regional_out <- example_regional_epinow # from output results <- get_regional_results(regional_out$regional, samples = FALSE) -names(results) - -# from a folder -folder_results <- get_regional_results(results_dir = dir, samples = FALSE) -names(folder_results) -} } \author{ Sam Abbott diff --git a/man/plot_estimates.Rd b/man/plot_estimates.Rd index 77b2e7a00..063a04b57 100644 --- a/man/plot_estimates.Rd +++ b/man/plot_estimates.Rd @@ -49,35 +49,19 @@ releases it may be depreciated in favour of increasing the functionality of the S3 plot methods. } \examples{ -\donttest{ -# 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 <- estimate_delay(rlnorm(100, log(6), 1), max_value = 10) - -# run model -out <- estimate_infections(cases, - generation_time = generation_time_opts(generation_time), - delays = delay_opts(incubation_period + reporting_delay) -) +# get example model results +out <- example_estimate_infections # plot infections plot_estimates( estimate = out$summarised[variable == "infections"], - reported = cases, + reported = out$observations, ylab = "Cases", max_plot = 2 ) + ggplot2::facet_wrap(~type, scales = "free_y") # plot reported cases estimated via Rt plot_estimates( estimate = out$summarised[variable == "reported_cases"], - reported = cases, + reported = out$observations, ylab = "Cases" ) @@ -95,4 +79,3 @@ plot_estimates( hline = 1, estimate_type = "Estimate" ) } -} diff --git a/man/regional_epinow.Rd b/man/regional_epinow.Rd index 05b1fe593..a022d977e 100644 --- a/man/regional_epinow.Rd +++ b/man/regional_epinow.Rd @@ -157,6 +157,7 @@ cases <- data.table::rbindlist(list( # run epinow across multiple regions and generate summaries # samples and warmup have been reduced for this example +# for more examples, see the "estimate_infections examples" vignette def <- regional_epinow( reported_cases = cases, generation_time = generation_time_opts(generation_time), @@ -168,24 +169,6 @@ def <- regional_epinow( ), verbose = interactive() ) - -# apply a different rt method per region -# (here a gaussian process and a weekly random walk) -gp <- opts_list(gp_opts(), cases) -gp <- update_list(gp, list(realland = NULL)) -rt <- opts_list(rt_opts(), cases, realland = rt_opts(rw = 7)) -region_rt <- regional_epinow( - reported_cases = cases, - generation_time = generation_time_opts(generation_time), - delays = delay_opts(incubation_period + reporting_delay), - rt = rt, gp = gp, - stan = stan_opts( - samples = 100, warmup = 200, - control = list(adapt_delta = 0.95) - ), - verbose = interactive() -) - options(old_opts) } } diff --git a/man/regional_runtimes.Rd b/man/regional_runtimes.Rd index f7f181f4d..d6bc48110 100644 --- a/man/regional_runtimes.Rd +++ b/man/regional_runtimes.Rd @@ -33,34 +33,9 @@ A data.table of region run times Used internally by \code{regional_epinow} to summarise region run times. } \examples{ -\donttest{ -# 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 <- estimate_delay(rlnorm(100, log(6), 1), max_value = 15) - -cases <- example_confirmed[1:30] -cases <- data.table::rbindlist(list( - data.table::copy(cases)[, region := "testland"], - cases[, region := "realland"] -)) - -# run basic nowcasting pipeline -regional_out <- regional_epinow( - reported_cases = cases, - generation_time = generation_time_opts(generation_time), - delays = delay_opts(incubation_period + reporting_delay), - stan = stan_opts(samples = 100, warmup = 100), - output = c("region", "timing") -) - +regional_out <- example_regional_epinow # get example run outputs regional_runtimes(regional_output = regional_out$regional) } -} \seealso{ regional_summary regional_epinow } diff --git a/man/regional_summary.Rd b/man/regional_summary.Rd index 834201ae6..fb64d2dd0 100644 --- a/man/regional_summary.Rd +++ b/man/regional_summary.Rd @@ -62,38 +62,13 @@ Used to produce summary output either internally in \code{regional_epinow} or externally. } \examples{ -\donttest{ -# 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 <- estimate_delay(rlnorm(100, log(6), 1), max_value = 30) - -# example case vector from EpiSoon -cases <- example_confirmed[1:30] -cases <- data.table::rbindlist(list( - data.table::copy(cases)[, region := "testland"], - cases[, region := "realland"] -)) - -# run basic nowcasting pipeline -out <- regional_epinow( - reported_cases = cases, - generation_time = generation_time_opts(generation_time), - delays = delay_opts(incubation_period + reporting_delay), - output = "region", - rt = NULL -) - +# get example output from regional_epinow model +out <- example_regional_epinow regional_summary( regional_output = out$regional, - reported_cases = cases + reported_cases = out$summary$reported_cases ) } -} \seealso{ regional_epinow } diff --git a/man/report_plots.Rd b/man/report_plots.Rd index ca2eba88d..da195ccc9 100644 --- a/man/report_plots.Rd +++ b/man/report_plots.Rd @@ -31,37 +31,16 @@ Returns key summary plots for estimates. May be depreciated in later releases as current S3 methods are enhanced. } \examples{ -\donttest{ -# 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 <- bootstrapped_dist_fit( - rlnorm(100, log(6), 1), max_value = 30 -) - -# run model -out <- estimate_infections(cases, - stan = stan_opts(samples = 500), - generation_time = generation_time_opts(generation_time), - delays = delay_opts(incubation_period + reporting_delay), - rt = NULL -) +# get example output form estimate_infections +out <- example_estimate_infections # plot infections plots <- report_plots( summarised_estimates = out$summarised, - reported = cases + reported = out$observations ) plots } -} \seealso{ \code{\link[=plot_estimates]{plot_estimates()}} of \code{summarised_estimates[variable == "infections"]},