diff --git a/NAMESPACE b/NAMESPACE index 67293c2f2..3d7391fe8 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -62,6 +62,7 @@ export(get_pmf) export(get_regional_results) export(gp_opts) export(growth_to_R) +export(gt_opts) export(lognorm_dist_def) export(make_conf) export(map_prob_change) diff --git a/NEWS.md b/NEWS.md index 49245a920..e54865d39 100644 --- a/NEWS.md +++ b/NEWS.md @@ -11,6 +11,7 @@ ## Documentation - Updated the documentation of the dots argument of the `stan_sampling_opts()` to add that the dots are passed to `cmdstanr::sample()`. By @jamesmbaazam in #699 and reviewed by @sbfnk. +- `generation_time_opts()` has been shortened to `gt_opts()` to make it easier to specify. Calls to both functions are equivalent. By @jamesmbaazam in #698 and reviewed by @seabbs and @sbfnk . # EpiNow2 1.5.2 diff --git a/R/epinow.R b/R/epinow.R index 8915106df..c4d4c7b70 100644 --- a/R/epinow.R +++ b/R/epinow.R @@ -64,7 +64,7 @@ #' # estimate Rt and nowcast/forecast cases by date of infection #' out <- epinow( #' data = reported_cases, -#' generation_time = generation_time_opts(generation_time), +#' generation_time = gt_opts(generation_time), #' rt = rt_opts(prior = list(mean = 2, sd = 0.1)), #' delays = delay_opts(incubation_period + reporting_delay) #' ) @@ -80,7 +80,7 @@ #' } # nolint start: cyclocomp_linter epinow <- function(data, - generation_time = generation_time_opts(), + generation_time = gt_opts(), delays = delay_opts(), truncation = trunc_opts(), rt = rt_opts(), diff --git a/R/estimate_infections.R b/R/estimate_infections.R index 11bced120..35e36946b 100644 --- a/R/estimate_infections.R +++ b/R/estimate_infections.R @@ -22,9 +22,9 @@ #' #' @param reported_cases Deprecated; use `data` instead. #' -#' @param generation_time A call to [generation_time_opts()] defining the -#' generation time distribution used. For backwards compatibility a list of -#' summary parameters can also be passed. +#' @param generation_time A call to [gt_opts()] (or its alias +#' [generation_time_opts()]) defining the generation time distribution used. +#' For backwards compatibility a list of summary parameters can also be passed. #' #' @param delays A call to [delay_opts()] defining delay distributions and #' options. See the documentation of [delay_opts()] and the examples below for @@ -99,7 +99,7 @@ #' #' # for more examples, see the "estimate_infections examples" vignette #' def <- estimate_infections(reported_cases, -#' generation_time = generation_time_opts(generation_time), +#' generation_time = gt_opts(generation_time), #' delays = delay_opts(incubation_period + reporting_delay), #' rt = rt_opts(prior = list(mean = 2, sd = 0.1)), #' stan = stan_opts(control = list(adapt_delta = 0.95)) @@ -111,7 +111,7 @@ #' options(old_opts) #' } estimate_infections <- function(data, - generation_time = generation_time_opts(), + generation_time = gt_opts(), delays = delay_opts(), truncation = trunc_opts(), rt = rt_opts(), diff --git a/R/opts.R b/R/opts.R index a9e7ef6f0..c1860f018 100644 --- a/R/opts.R +++ b/R/opts.R @@ -3,6 +3,7 @@ #' @description `r lifecycle::badge("stable")` #' Returns generation time parameters in a format for lower level model use. #' +#' @rdname generation_time_opts #' @param dist A delay distribution or series of delay distributions . If no #' distribution is given a fixed generation time of 1 will be assumed. #' @@ -40,8 +41,8 @@ #' ) #' #' # An example generation time -#' generation_time_opts(example_generation_time) -generation_time_opts <- function(dist = Fixed(1), ..., +#' gt_opts(example_generation_time) +gt_opts <- function(dist = Fixed(1), ..., disease, source, max = 14, fixed = FALSE, tolerance = 0.001, weight_prior = TRUE) { dot_options <- list(...) @@ -75,6 +76,10 @@ generation_time_opts <- function(dist = Fixed(1), ..., return(dist) } +#' @rdname generation_time_opts +#' @export +generation_time_opts <- gt_opts + #' Secondary Reports Options #' #' @description `r lifecycle::badge("stable")` diff --git a/R/regional_epinow.R b/R/regional_epinow.R index 23ccb52eb..e43471c4b 100644 --- a/R/regional_epinow.R +++ b/R/regional_epinow.R @@ -79,7 +79,7 @@ #' # for more examples, see the "estimate_infections examples" vignette #' def <- regional_epinow( #' data = cases, -#' generation_time = generation_time_opts(example_generation_time), +#' generation_time = gt_opts(example_generation_time), #' delays = delay_opts(example_incubation_period + example_reporting_delay), #' rt = rt_opts(prior = list(mean = 2, sd = 0.2)), #' stan = stan_opts( @@ -91,7 +91,7 @@ #' options(old_opts) #' } regional_epinow <- function(data, - generation_time = generation_time_opts(), + generation_time = gt_opts(), delays = delay_opts(), truncation = trunc_opts(), rt = rt_opts(), diff --git a/data-raw/estimate-infections.R b/data-raw/estimate-infections.R index 4645f29bd..24f1215c1 100644 --- a/data-raw/estimate-infections.R +++ b/data-raw/estimate-infections.R @@ -12,7 +12,7 @@ reported_cases <- example_confirmed[1:60] reporting_delay <- LogNormal(mean = 2, sd = 1, max = 10L) example_estimate_infections <- estimate_infections(reported_cases, - generation_time = generation_time_opts(example_generation_time), + generation_time = gt_opts(example_generation_time), delays = delay_opts(example_incubation_period + reporting_delay), rt = rt_opts(prior = list(mean = 2, sd = 0.1)), stan = stan_opts(samples = 200, control = list(adapt_delta = 0.95)) @@ -25,8 +25,8 @@ cases <- data.table::rbindlist(list( )) example_regional_epinow <- regional_epinow( + generation_time = gt_opts(example_generation_time), data = cases, - 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(samples = 200, control = list(adapt_delta = 0.95)) diff --git a/inst/dev/benchmark-functions.R b/inst/dev/benchmark-functions.R index d83651d25..3e884e72b 100644 --- a/inst/dev/benchmark-functions.R +++ b/inst/dev/benchmark-functions.R @@ -15,7 +15,7 @@ create_profiles <- function(dir = file.path("inst", "stan"), set.seed(x) fit <- estimate_infections( data = reported_cases, - generation_time = generation_time_opts(fixed_generation_time), + generation_time = gt_opts(fixed_generation_time), delays = delay_opts(delays), rt = rt_opts(prior = list(mean = 2, sd = 0.2)), stan = stan_opts( diff --git a/inst/dev/recover-synthetic/rt.R b/inst/dev/recover-synthetic/rt.R index b6dce1aa1..a20428701 100644 --- a/inst/dev/recover-synthetic/rt.R +++ b/inst/dev/recover-synthetic/rt.R @@ -12,7 +12,7 @@ obs <- obs_opts(scale = list(mean = 0.1, sd = 0.025), return_likelihood = TRUE) # fit model to data to recover realistic parameter estimates and define settings # shared simulation settings init <- estimate_infections(example_confirmed[1:100], - generation_time = generation_time_opts(example_generation_time), + generation_time = gt_opts(example_generation_time), delays = delay_opts(example_incubation_period + example_reporting_delay), rt = rt_opts(prior = list(mean = 2, sd = 0.1), rw = 14), gp = NULL, horizon = 0, @@ -57,7 +57,7 @@ for (method in c("nuts")) { # GP gp[[method]] <- estimate_infections(sim_cases, - generation_time = generation_time_opts(example_generation_time), + generation_time = gt_opts(example_generation_time), delays = delay_opts(example_incubation_period + example_reporting_delay), rt = rt_opts(prior = list(mean = 2, sd = 0.25)), stan = stanopts, @@ -72,7 +72,7 @@ for (method in c("nuts")) { # Backcalculation backcalc[[method]] <- estimate_infections(sim_cases, - generation_time = generation_time_opts(example_generation_time), + generation_time = gt_opts(example_generation_time), delays = delay_opts(example_incubation_period + example_reporting_delay), rt = NULL, stan = stanopts, @@ -87,7 +87,7 @@ for (method in c("nuts")) { # RW (weekly) weekly_rw[[method]] <- estimate_infections(sim_cases, - generation_time = generation_time_opts(example_generation_time), + generation_time = gt_opts(example_generation_time), delays = delay_opts(example_incubation_period + example_reporting_delay), rt = rt_opts( prior = list(mean = 2, sd = 0.25), @@ -106,7 +106,7 @@ for (method in c("nuts")) { # RW (every month) + stationary Guassian process gp_rw[[method]] <- estimate_infections(sim_cases, - generation_time = generation_time_opts(example_generation_time), + generation_time = gt_opts(example_generation_time), delays = delay_opts(example_incubation_period + example_reporting_delay), rt = rt_opts( prior = list(mean = 2, sd = 0.25), rw = 14, gp_on = "R0" @@ -125,7 +125,7 @@ for (method in c("nuts")) { if (fit_daily) { daily_rw[[method]] <- estimate_infections(sim_cases, - generation_time = generation_time_opts(example_generation_time), + generation_time = gt_opts(example_generation_time), delays = delay_opts( example_incubation_period + example_reporting_delay ), diff --git a/man/epinow.Rd b/man/epinow.Rd index c44770f93..1545f5703 100644 --- a/man/epinow.Rd +++ b/man/epinow.Rd @@ -6,7 +6,7 @@ \usage{ epinow( data, - generation_time = generation_time_opts(), + generation_time = gt_opts(), delays = delay_opts(), truncation = trunc_opts(), rt = rt_opts(), @@ -33,9 +33,9 @@ epinow( \item{data}{A \verb{} of confirmed cases (confirm) by date (date). \code{confirm} must be numeric and \code{date} must be in date format.} -\item{generation_time}{A call to \code{\link[=generation_time_opts]{generation_time_opts()}} defining the -generation time distribution used. For backwards compatibility a list of -summary parameters can also be passed.} +\item{generation_time}{A call to \code{\link[=gt_opts]{gt_opts()}} (or its alias +\code{\link[=generation_time_opts]{generation_time_opts()}}) defining the generation time distribution used. +For backwards compatibility a list of summary parameters can also be passed.} \item{delays}{A call to \code{\link[=delay_opts]{delay_opts()}} defining delay distributions and options. See the documentation of \code{\link[=delay_opts]{delay_opts()}} and the examples below for @@ -157,7 +157,7 @@ reported_cases <- example_confirmed[1:40] # estimate Rt and nowcast/forecast cases by date of infection out <- epinow( data = reported_cases, - generation_time = generation_time_opts(generation_time), + generation_time = gt_opts(generation_time), rt = rt_opts(prior = list(mean = 2, sd = 0.1)), delays = delay_opts(incubation_period + reporting_delay) ) diff --git a/man/estimate_infections.Rd b/man/estimate_infections.Rd index ca9a549af..080db1bbc 100644 --- a/man/estimate_infections.Rd +++ b/man/estimate_infections.Rd @@ -7,7 +7,7 @@ Growth} \usage{ estimate_infections( data, - generation_time = generation_time_opts(), + generation_time = gt_opts(), delays = delay_opts(), truncation = trunc_opts(), rt = rt_opts(), @@ -29,9 +29,9 @@ estimate_infections( \item{data}{A \verb{} of confirmed cases (confirm) by date (date). \code{confirm} must be numeric and \code{date} must be in date format.} -\item{generation_time}{A call to \code{\link[=generation_time_opts]{generation_time_opts()}} defining the -generation time distribution used. For backwards compatibility a list of -summary parameters can also be passed.} +\item{generation_time}{A call to \code{\link[=gt_opts]{gt_opts()}} (or its alias +\code{\link[=generation_time_opts]{generation_time_opts()}}) defining the generation time distribution used. +For backwards compatibility a list of summary parameters can also be passed.} \item{delays}{A call to \code{\link[=delay_opts]{delay_opts()}} defining delay distributions and options. See the documentation of \code{\link[=delay_opts]{delay_opts()}} and the examples below for @@ -142,7 +142,7 @@ reporting_delay <- LogNormal(mean = 2, sd = 1, max = 10) # for more examples, see the "estimate_infections examples" vignette def <- estimate_infections(reported_cases, - generation_time = generation_time_opts(generation_time), + generation_time = gt_opts(generation_time), delays = delay_opts(incubation_period + reporting_delay), rt = rt_opts(prior = list(mean = 2, sd = 0.1)), stan = stan_opts(control = list(adapt_delta = 0.95)) diff --git a/man/generation_time_opts.Rd b/man/generation_time_opts.Rd index 844e8157c..5cf19c2f1 100644 --- a/man/generation_time_opts.Rd +++ b/man/generation_time_opts.Rd @@ -1,9 +1,21 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/opts.R -\name{generation_time_opts} +\name{gt_opts} +\alias{gt_opts} \alias{generation_time_opts} \title{Generation Time Distribution Options} \usage{ +gt_opts( + dist = Fixed(1), + ..., + disease, + source, + max = 14, + fixed = FALSE, + tolerance = 0.001, + weight_prior = TRUE +) + generation_time_opts( dist = Fixed(1), ..., @@ -63,7 +75,7 @@ generation_time_opts( ) # An example generation time -generation_time_opts(example_generation_time) +gt_opts(example_generation_time) } \seealso{ \code{\link[=convert_to_logmean]{convert_to_logmean()}} \code{\link[=convert_to_logsd]{convert_to_logsd()}} diff --git a/man/get_seeding_time.Rd b/man/get_seeding_time.Rd index 5bf04b32c..e240824fa 100644 --- a/man/get_seeding_time.Rd +++ b/man/get_seeding_time.Rd @@ -11,9 +11,9 @@ get_seeding_time(delays, generation_time, rt = rt_opts()) options. See the documentation of \code{\link[=delay_opts]{delay_opts()}} and the examples below for details.} -\item{generation_time}{A call to \code{\link[=generation_time_opts]{generation_time_opts()}} defining the -generation time distribution used. For backwards compatibility a list of -summary parameters can also be passed.} +\item{generation_time}{A call to \code{\link[=gt_opts]{gt_opts()}} (or its alias +\code{\link[=generation_time_opts]{generation_time_opts()}}) defining the generation time distribution used. +For backwards compatibility a list of summary parameters can also be passed.} \item{rt}{A list of options as generated by \code{\link[=rt_opts]{rt_opts()}} defining Rt estimation. Defaults to \code{\link[=rt_opts]{rt_opts()}}. Set to \code{NULL} to switch to using back diff --git a/man/regional_epinow.Rd b/man/regional_epinow.Rd index f2e7567bf..5106c9a39 100644 --- a/man/regional_epinow.Rd +++ b/man/regional_epinow.Rd @@ -6,7 +6,7 @@ \usage{ regional_epinow( data, - generation_time = generation_time_opts(), + generation_time = gt_opts(), delays = delay_opts(), truncation = trunc_opts(), rt = rt_opts(), @@ -32,9 +32,9 @@ regional_epinow( \item{data}{A \verb{} of confirmed cases (confirm) by date (date), and region (\code{region}).} -\item{generation_time}{A call to \code{\link[=generation_time_opts]{generation_time_opts()}} defining the -generation time distribution used. For backwards compatibility a list of -summary parameters can also be passed.} +\item{generation_time}{A call to \code{\link[=gt_opts]{gt_opts()}} (or its alias +\code{\link[=generation_time_opts]{generation_time_opts()}}) defining the generation time distribution used. +For backwards compatibility a list of summary parameters can also be passed.} \item{delays}{A call to \code{\link[=delay_opts]{delay_opts()}} defining delay distributions and options. See the documentation of \code{\link[=delay_opts]{delay_opts()}} and the examples below for @@ -152,7 +152,7 @@ cases <- data.table::rbindlist(list( # for more examples, see the "estimate_infections examples" vignette def <- regional_epinow( data = cases, - generation_time = generation_time_opts(example_generation_time), + generation_time = gt_opts(example_generation_time), delays = delay_opts(example_incubation_period + example_reporting_delay), rt = rt_opts(prior = list(mean = 2, sd = 0.2)), stan = stan_opts( diff --git a/man/run_region.Rd b/man/run_region.Rd index b4936b7d0..802b7b8f3 100644 --- a/man/run_region.Rd +++ b/man/run_region.Rd @@ -30,9 +30,9 @@ run_region( \arguments{ \item{target_region}{Character string indicating the region being evaluated} -\item{generation_time}{A call to \code{\link[=generation_time_opts]{generation_time_opts()}} defining the -generation time distribution used. For backwards compatibility a list of -summary parameters can also be passed.} +\item{generation_time}{A call to \code{\link[=gt_opts]{gt_opts()}} (or its alias +\code{\link[=generation_time_opts]{generation_time_opts()}}) defining the generation time distribution used. +For backwards compatibility a list of summary parameters can also be passed.} \item{delays}{A call to \code{\link[=delay_opts]{delay_opts()}} defining delay distributions and options. See the documentation of \code{\link[=delay_opts]{delay_opts()}} and the examples below for diff --git a/man/simulate_infections.Rd b/man/simulate_infections.Rd index 1853b67ec..70bad6010 100644 --- a/man/simulate_infections.Rd +++ b/man/simulate_infections.Rd @@ -39,9 +39,9 @@ numerical vector of length specified in \code{\link[=obs_opts]{obs_opts()}} as \ gives the weight given to reporting on this day (normalised to 1). The default is \code{NULL}.} -\item{generation_time}{A call to \code{\link[=generation_time_opts]{generation_time_opts()}} defining the -generation time distribution used. For backwards compatibility a list of -summary parameters can also be passed.} +\item{generation_time}{A call to \code{\link[=gt_opts]{gt_opts()}} (or its alias +\code{\link[=generation_time_opts]{generation_time_opts()}}) defining the generation time distribution used. +For backwards compatibility a list of summary parameters can also be passed.} \item{delays}{A call to \code{\link[=delay_opts]{delay_opts()}} defining delay distributions and options. See the documentation of \code{\link[=delay_opts]{delay_opts()}} and the examples below for diff --git a/tests/testthat/test-delays.R b/tests/testthat/test-delays.R index 2480166d9..b2fdfee94 100644 --- a/tests/testthat/test-delays.R +++ b/tests/testthat/test-delays.R @@ -1,4 +1,4 @@ -test_stan_delays <- function(generation_time = generation_time_opts(Fixed(1)), +test_stan_delays <- function(generation_time = gt_opts(Fixed(1)), delays = delay_opts(), truncation = trunc_opts(), params = c()) { @@ -21,14 +21,14 @@ test_that("generation times can be specified in different ways", { ) expect_equal( test_stan_delays( - generation_time = generation_time_opts(Fixed(value = 3)), + generation_time = gt_opts(Fixed(value = 3)), params = delay_params ), c(0, 0, 0, 1, 1, 1) ) expect_equal( round(test_stan_delays( - generation_time = generation_time_opts( + generation_time = gt_opts( LogNormal(meanlog = 3, sdlog = 1, max = 4) ), params = delay_params @@ -69,7 +69,7 @@ test_that("truncation parameters can be specified in different ways", { }) test_that("distributions incompatible with stan models are caught", { - expect_error(generation_time_opts( + expect_error(gt_opts( Gamma(2, 2) ), "maximum") expect_error(delay_opts( diff --git a/tests/testthat/test-epinow.R b/tests/testthat/test-epinow.R index b1857ebb5..bc3188fa2 100644 --- a/tests/testthat/test-epinow.R +++ b/tests/testthat/test-epinow.R @@ -20,7 +20,7 @@ test_that("epinow produces expected output when run with default settings", { outputs <- capture.output(suppressMessages(suppressWarnings( out <- epinow( data = reported_cases, - generation_time = generation_time_opts(example_generation_time), + generation_time = gt_opts(example_generation_time), delays = delay_opts(c(example_incubation_period, reporting_delay)), stan = stan_opts( samples = 25, warmup = 25, @@ -46,7 +46,7 @@ test_that("epinow produces expected output when run with the output <- capture.output(suppressMessages(suppressWarnings( out <- epinow( data = reported_cases, - generation_time = generation_time_opts(example_generation_time), + generation_time = gt_opts(example_generation_time), delays = delay_opts(example_incubation_period + reporting_delay), stan = stan_opts(backend = "cmdstanr"), logs = NULL, verbose = FALSE @@ -70,7 +70,7 @@ test_that("epinow produces expected output when run with the output <- capture.output(suppressMessages(suppressWarnings( out <- epinow( data = reported_cases, - generation_time = generation_time_opts(example_generation_time), + generation_time = gt_opts(example_generation_time), delays = delay_opts(example_incubation_period + reporting_delay), stan = stan_opts(method = "laplace", backend = "cmdstanr"), logs = NULL, verbose = FALSE @@ -93,7 +93,7 @@ test_that("epinow produces expected output when run with the output <- capture.output(suppressMessages(suppressWarnings( out <- epinow( data = reported_cases, - generation_time = generation_time_opts(example_generation_time), + generation_time = gt_opts(example_generation_time), delays = delay_opts(example_incubation_period + reporting_delay), stan = stan_opts(method = "pathfinder", backend = "cmdstanr"), logs = NULL, verbose = FALSE @@ -114,7 +114,7 @@ test_that("epinow runs without error when saving to disk", { output <- capture.output(suppressMessages(suppressWarnings( out <- epinow( data = reported_cases, - generation_time = generation_time_opts(example_generation_time), + generation_time = gt_opts(example_generation_time), delays = delay_opts(example_incubation_period + reporting_delay), stan = stan_opts( samples = 25, warmup = 25, cores = 1, chains = 2, @@ -131,7 +131,7 @@ test_that("epinow can produce partial output as specified", { output <- capture.output(suppressMessages(suppressWarnings( out <- epinow( data = reported_cases, - generation_time = generation_time_opts( + generation_time = gt_opts( example_generation_time, weight_prior = FALSE ), delays = delay_opts(example_incubation_period + reporting_delay), @@ -157,7 +157,7 @@ test_that("epinow can produce partial output as specified", { test_that("epinow fails as expected when given a short timeout", { expect_error(suppressWarnings(x = epinow( data = reported_cases, - generation_time = generation_time_opts(example_generation_time), + generation_time = gt_opts(example_generation_time), delays = delay_opts(example_incubation_period + reporting_delay), stan = stan_opts( samples = 100, warmup = 100, @@ -174,7 +174,7 @@ test_that("epinow fails if given NUTs arguments when using variational inference expect_error(capture.output(suppressMessages(suppressWarnings( epinow( data = reported_cases, - generation_time = generation_time_opts(example_generation_time), + generation_time = gt_opts(example_generation_time), delays = delay_opts(example_incubation_period + reporting_delay), stan = stan_opts( samples = 100, warmup = 100, @@ -191,7 +191,7 @@ test_that("epinow fails if given variational inference arguments when using NUTs expect_error(capture.output(suppressMessages(suppressWarnings( epinow( data = reported_cases, - generation_time = generation_time_opts(example_generation_time), + generation_time = gt_opts(example_generation_time), delays = delay_opts(example_incubation_period + reporting_delay), stan = stan_opts(method = "sampling", tol_rel_obj = 1), logs = NULL, verbose = FALSE diff --git a/tests/testthat/test-estimate_infections.R b/tests/testthat/test-estimate_infections.R index 64dafd376..447c845ed 100644 --- a/tests/testthat/test-estimate_infections.R +++ b/tests/testthat/test-estimate_infections.R @@ -17,7 +17,7 @@ default_estimate_infections <- function(..., add_stan = list(), gt = TRUE, suppressWarnings(estimate_infections(..., generation_time = fifelse( - gt, generation_time_opts(example_generation_time), generation_time_opts() + gt, gt_opts(example_generation_time), gt_opts() ), delays = ifelse(delay, list(delay_opts(example_reporting_delay)), list(delay_opts()))[[1]], stan = stan_args, verbose = FALSE diff --git a/tests/testthat/test-forecast-infections.R b/tests/testthat/test-forecast-infections.R index d43c81eaf..cfb122693 100644 --- a/tests/testthat/test-forecast-infections.R +++ b/tests/testthat/test-forecast-infections.R @@ -4,7 +4,7 @@ futile.logger::flog.threshold("FATAL") reported_cases <- EpiNow2::example_confirmed[1:50] out <- suppressWarnings(estimate_infections(reported_cases, - generation_time = generation_time_opts(example_generation_time), + generation_time = gt_opts(example_generation_time), delays = delay_opts(example_reporting_delay), gp = NULL, rt = rt_opts(rw = 14), stan = stan_opts( diff --git a/tests/testthat/test-regional_runtimes.R b/tests/testthat/test-regional_runtimes.R index 92435951c..35aac2707 100644 --- a/tests/testthat/test-regional_runtimes.R +++ b/tests/testthat/test-regional_runtimes.R @@ -12,7 +12,7 @@ df_non_zero <- function(df) { out <- suppressWarnings(regional_epinow( data = cases, - generation_time = generation_time_opts(example_generation_time), + generation_time = gt_opts(example_generation_time), delays = delay_opts(example_reporting_delay), stan = stan_opts( samples = 25, warmup = 25, diff --git a/tests/testthat/test-simulate-infections.R b/tests/testthat/test-simulate-infections.R index b7e0b4741..d8ce11f74 100644 --- a/tests/testthat/test-simulate-infections.R +++ b/tests/testthat/test-simulate-infections.R @@ -18,7 +18,7 @@ test_simulate_infections <- function(obs = obs_opts(family = "poisson"), ...) { test_that("simulate_infections works as expected with standard parameters", { set.seed(123) sim <- test_simulate_infections( - generation_time = generation_time_opts(Fixed(1)) + generation_time = gt_opts(Fixed(1)) ) expect_equal(nrow(sim), 2 * nrow(R)) expect_snapshot_output(sim) @@ -28,7 +28,7 @@ test_that("simulate_infections works as expected with standard parameters", { test_that("simulate_infections works as expected with additional parameters", { set.seed(123) sim <- test_simulate_infections( - generation_time = generation_time_opts(fix_dist(example_generation_time)), + generation_time = gt_opts(fix_dist(example_generation_time)), delays = delay_opts(fix_dist(example_reporting_delay)), obs = obs_opts(family = "negbin", phi = list(mean = 0.5, sd = 0)), seeding_time = 10 @@ -41,21 +41,21 @@ test_that("simulate_infections works as expected with additional parameters", { test_that("simulate_infections fails with uncertain parameters", { expect_error( test_simulate_infections( - generation_time = generation_time_opts(Fixed(1)), + generation_time = gt_opts(Fixed(1)), obs = obs_opts(family = "negbin") ), "uncertain" ) expect_error( test_simulate_infections( - generation_time = generation_time_opts(Fixed(1)), + generation_time = gt_opts(Fixed(1)), obs = obs_opts(scale = list(mean = 1, sd = 1)) ), "uncertain" ) expect_error( test_simulate_infections( - generation_time = generation_time_opts(Fixed(1)), + generation_time = gt_opts(Fixed(1)), delays = delay_opts(example_incubation_period) ), "uncertain" diff --git a/vignettes/EpiNow2.Rmd b/vignettes/EpiNow2.Rmd index 2fa8edbc3..e3350e134 100644 --- a/vignettes/EpiNow2.Rmd +++ b/vignettes/EpiNow2.Rmd @@ -115,7 +115,7 @@ Estimate cases by date of infection, the time-varying reproduction number, the r ```r estimates <- epinow( data = reported_cases, - generation_time = generation_time_opts(example_generation_time), + generation_time = gt_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)), @@ -232,7 +232,7 @@ Calling `regional_epinow()` runs the `epinow()` on each region in turn (or in pa ```r estimates <- regional_epinow( data = reported_cases, - generation_time = generation_time_opts(example_generation_time), + generation_time = gt_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, diff --git a/vignettes/EpiNow2.Rmd.orig b/vignettes/EpiNow2.Rmd.orig index 615c4b5fa..bbac82e46 100644 --- a/vignettes/EpiNow2.Rmd.orig +++ b/vignettes/EpiNow2.Rmd.orig @@ -79,7 +79,7 @@ Estimate cases by date of infection, the time-varying reproduction number, the r ```{r, message = FALSE, warning = FALSE} estimates <- epinow( data = reported_cases, - generation_time = generation_time_opts(example_generation_time), + generation_time = gt_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)), @@ -133,7 +133,7 @@ Calling `regional_epinow()` runs the `epinow()` on each region in turn (or in pa ```{r, message = FALSE, warning = FALSE} estimates <- regional_epinow( data = reported_cases, - generation_time = generation_time_opts(example_generation_time), + generation_time = gt_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, diff --git a/vignettes/estimate_infections_options.Rmd b/vignettes/estimate_infections_options.Rmd index 956b15ec2..9cb36493e 100644 --- a/vignettes/estimate_infections_options.Rmd +++ b/vignettes/estimate_infections_options.Rmd @@ -173,7 +173,7 @@ Putting all the data and parameters together and tweaking the Gaussian Process t ```r def <- estimate_infections(reported_cases, - generation_time = generation_time_opts(example_generation_time), + generation_time = gt_opts(example_generation_time), delays = delay_opts(delay), rt = rt_opts(prior = rt_prior) ) @@ -210,7 +210,7 @@ To speed up the calculation of the Gaussian Process we could decrease its accura ```r agp <- estimate_infections(reported_cases, - generation_time = generation_time_opts(example_generation_time), + generation_time = gt_opts(example_generation_time), delays = delay_opts(delay), rt = rt_opts(prior = rt_prior), gp = gp_opts(basis_prop = 0.1) @@ -250,7 +250,7 @@ Note that this only affects the forecasts and is done using a crude adjustment ( ```r dep <- estimate_infections(reported_cases, - generation_time = generation_time_opts(example_generation_time), + generation_time = gt_opts(example_generation_time), delays = delay_opts(delay), rt = rt_opts( prior = rt_prior, @@ -321,7 +321,7 @@ We can then use this in the `esimtate_infections()` function using the `truncati ```r trunc <- estimate_infections(reported_cases, - generation_time = generation_time_opts(example_generation_time), + generation_time = gt_opts(example_generation_time), delays = delay_opts(delay), truncation = trunc_opts(trunc_dist), rt = rt_opts(prior = rt_prior) @@ -348,7 +348,7 @@ This will lead to wider uncertainty, and the researcher should check whether thi ```r project_rt <- estimate_infections(reported_cases, - generation_time = generation_time_opts(example_generation_time), + generation_time = gt_opts(example_generation_time), delays = delay_opts(delay), rt = rt_opts( prior = rt_prior, future = "project" @@ -387,7 +387,7 @@ We might want to estimate a fixed reproduction number, i.e. assume that it does ```r fixed <- estimate_infections(reported_cases, - generation_time = generation_time_opts(example_generation_time), + generation_time = gt_opts(example_generation_time), delays = delay_opts(delay), gp = NULL ) @@ -432,7 +432,7 @@ We then use this instead of `reported_cases` in the `estimate_infections()` func ```r bkp <- estimate_infections(bp_cases, - generation_time = generation_time_opts(example_generation_time), + generation_time = gt_opts(example_generation_time), delays = delay_opts(delay), rt = rt_opts(prior = rt_prior), gp = NULL @@ -467,7 +467,7 @@ This can be achieved using the `rw` option which defines the length of the time ```r rw <- estimate_infections(reported_cases, - generation_time = generation_time_opts(example_generation_time), + generation_time = gt_opts(example_generation_time), delays = delay_opts(delay), rt = rt_opts(prior = rt_prior, rw = 7), gp = NULL @@ -502,7 +502,7 @@ Whilst _EpiNow2_ allows the user to specify delays, it can also run directly on ```r no_delay <- estimate_infections( reported_cases, - generation_time = generation_time_opts(example_generation_time) + generation_time = gt_opts(example_generation_time) ) #> Warning: There were 32 divergent transitions after warmup. See #> https://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup @@ -546,7 +546,7 @@ It also means that the model is questionable for forecasting, which is why were ```r non_parametric <- estimate_infections(reported_cases, - generation_time = generation_time_opts(example_generation_time), + generation_time = gt_opts(example_generation_time), delays = delay_opts(delay), rt = NULL, backcalc = backcalc_opts(), diff --git a/vignettes/estimate_infections_options.Rmd.orig b/vignettes/estimate_infections_options.Rmd.orig index add78a2e0..bdfaaa138 100644 --- a/vignettes/estimate_infections_options.Rmd.orig +++ b/vignettes/estimate_infections_options.Rmd.orig @@ -111,7 +111,7 @@ Putting all the data and parameters together and tweaking the Gaussian Process t ```{r default} def <- estimate_infections(reported_cases, - generation_time = generation_time_opts(example_generation_time), + generation_time = gt_opts(example_generation_time), delays = delay_opts(delay), rt = rt_opts(prior = rt_prior) ) @@ -129,7 +129,7 @@ To speed up the calculation of the Gaussian Process we could decrease its accura ```{r lower_accuracy} agp <- estimate_infections(reported_cases, - generation_time = generation_time_opts(example_generation_time), + generation_time = gt_opts(example_generation_time), delays = delay_opts(delay), rt = rt_opts(prior = rt_prior), gp = gp_opts(basis_prop = 0.1) @@ -150,7 +150,7 @@ Note that this only affects the forecasts and is done using a crude adjustment ( ```{r susceptible_depletion} dep <- estimate_infections(reported_cases, - generation_time = generation_time_opts(example_generation_time), + generation_time = gt_opts(example_generation_time), delays = delay_opts(delay), rt = rt_opts( prior = rt_prior, @@ -183,7 +183,7 @@ We can then use this in the `esimtate_infections()` function using the `truncati ```{r truncation} trunc <- estimate_infections(reported_cases, - generation_time = generation_time_opts(example_generation_time), + generation_time = gt_opts(example_generation_time), delays = delay_opts(delay), truncation = trunc_opts(trunc_dist), rt = rt_opts(prior = rt_prior) @@ -203,7 +203,7 @@ This will lead to wider uncertainty, and the researcher should check whether thi ```{r gp_projection} project_rt <- estimate_infections(reported_cases, - generation_time = generation_time_opts(example_generation_time), + generation_time = gt_opts(example_generation_time), delays = delay_opts(delay), rt = rt_opts( prior = rt_prior, future = "project" @@ -223,7 +223,7 @@ We might want to estimate a fixed reproduction number, i.e. assume that it does ```{r fixed} fixed <- estimate_infections(reported_cases, - generation_time = generation_time_opts(example_generation_time), + generation_time = gt_opts(example_generation_time), delays = delay_opts(delay), gp = NULL ) @@ -252,7 +252,7 @@ We then use this instead of `reported_cases` in the `estimate_infections()` func ```{r bp} bkp <- estimate_infections(bp_cases, - generation_time = generation_time_opts(example_generation_time), + generation_time = gt_opts(example_generation_time), delays = delay_opts(delay), rt = rt_opts(prior = rt_prior), gp = NULL @@ -272,7 +272,7 @@ This can be achieved using the `rw` option which defines the length of the time ```{r weekly_rw} rw <- estimate_infections(reported_cases, - generation_time = generation_time_opts(example_generation_time), + generation_time = gt_opts(example_generation_time), delays = delay_opts(delay), rt = rt_opts(prior = rt_prior, rw = 7), gp = NULL @@ -292,7 +292,7 @@ Whilst _EpiNow2_ allows the user to specify delays, it can also run directly on ```{r no_delays} no_delay <- estimate_infections( reported_cases, - generation_time = generation_time_opts(example_generation_time) + generation_time = gt_opts(example_generation_time) ) # summarise results summary(no_delay) @@ -311,7 +311,7 @@ It also means that the model is questionable for forecasting, which is why were ```{r nonparametric} non_parametric <- estimate_infections(reported_cases, - generation_time = generation_time_opts(example_generation_time), + generation_time = gt_opts(example_generation_time), delays = delay_opts(delay), rt = NULL, backcalc = backcalc_opts(), diff --git a/vignettes/estimate_infections_workflow.Rmd b/vignettes/estimate_infections_workflow.Rmd index 862a8a041..5d6d3c2c1 100644 --- a/vignettes/estimate_infections_workflow.Rmd +++ b/vignettes/estimate_infections_workflow.Rmd @@ -130,7 +130,7 @@ For a more comprehensive treatment of delays and their estimation avoiding commo ### Generation intervals The generation interval is a delay distribution that describes the amount of time that passes between an individual becoming infected and infecting someone else. -In _EpiNow2_, the generation time distribution is defined by a call to `generation_time_opts()`, a function that takes a single argument defined as a `dist_spec` object (returned by the function corresponding to the probability distribution, i.e. `LogNormal()`, `Gamma()`, etc.). +In _EpiNow2_, the generation time distribution is defined by a call to `gt_opts()`, a function that takes a single argument defined as a `dist_spec` object (returned by the function corresponding to the probability distribution, i.e. `LogNormal()`, `Gamma()`, etc.). For example, to define the generation time as gamma distributed with uncertain mean centered on 3 and sd centered on 1 with some uncertainty, a maximum value of 10 and weighted by the number of case data points we could use the shape and rate parameters suggested above (though notes that this will only very approximately produce the uncertainty in mean and standard deviation stated there): @@ -138,7 +138,7 @@ For example, to define the generation time as gamma distributed with uncertain m generation_time <- Gamma( shape = Normal(9, 2.5), rate = Normal(3, 1.4), max = 10 ) -generation_time_opts(generation_time) +gt_opts(generation_time) ``` ### Reporting delays @@ -261,7 +261,7 @@ For example, using some of the options described above one could call ```r def <- estimate_infections( example_confirmed, - generation_time = generation_time_opts(generation_time), + generation_time = gt_opts(generation_time), delays = delay_opts(delay), rt = rt_opts(prior = rt_prior) ) diff --git a/vignettes/estimate_infections_workflow.Rmd.orig b/vignettes/estimate_infections_workflow.Rmd.orig index 9257a1a58..1d2da81d7 100644 --- a/vignettes/estimate_infections_workflow.Rmd.orig +++ b/vignettes/estimate_infections_workflow.Rmd.orig @@ -102,14 +102,14 @@ For a more comprehensive treatment of delays and their estimation avoiding commo ### Generation intervals The generation interval is a delay distribution that describes the amount of time that passes between an individual becoming infected and infecting someone else. -In _EpiNow2_, the generation time distribution is defined by a call to `generation_time_opts()`, a function that takes a single argument defined as a `dist_spec` object (returned by the function corresponding to the probability distribution, i.e. `LogNormal()`, `Gamma()`, etc.). +In _EpiNow2_, the generation time distribution is defined by a call to `gt_opts()`, a function that takes a single argument defined as a `dist_spec` object (returned by the function corresponding to the probability distribution, i.e. `LogNormal()`, `Gamma()`, etc.). For example, to define the generation time as gamma distributed with uncertain mean centered on 3 and sd centered on 1 with some uncertainty, a maximum value of 10 and weighted by the number of case data points we could use the shape and rate parameters suggested above (though notes that this will only very approximately produce the uncertainty in mean and standard deviation stated there): ```{r, results = 'hide'} generation_time <- Gamma( shape = Normal(9, 2.5), rate = Normal(3, 1.4), max = 10 ) -generation_time_opts(generation_time) +gt_opts(generation_time) ``` ### Reporting delays @@ -206,7 +206,7 @@ For example, using some of the options described above one could call ```{r} def <- estimate_infections( example_confirmed, - generation_time = generation_time_opts(generation_time), + generation_time = gt_opts(generation_time), delays = delay_opts(delay), rt = rt_opts(prior = rt_prior) )