Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shorten generation_time_opts() to gt_opts() as alias #698

Merged
merged 6 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions R/epinow.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
#' )
Expand All @@ -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(),
Expand Down
10 changes: 5 additions & 5 deletions R/estimate_infections.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand All @@ -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(),
Expand Down
9 changes: 7 additions & 2 deletions R/opts.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#'
Expand Down Expand Up @@ -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(...)
Expand Down Expand Up @@ -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")`
Expand Down
4 changes: 2 additions & 2 deletions R/regional_epinow.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions data-raw/estimate-infections.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion inst/dev/benchmark-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
12 changes: 6 additions & 6 deletions inst/dev/recover-synthetic/rt.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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),
Expand All @@ -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"
Expand All @@ -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
),
Expand Down
10 changes: 5 additions & 5 deletions man/epinow.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions man/estimate_infections.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions man/generation_time_opts.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/get_seeding_time.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions man/regional_epinow.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/run_region.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/simulate_infections.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions tests/testthat/test-delays.R
Original file line number Diff line number Diff line change
@@ -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()) {
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Loading
Loading