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

Deprecate init_cumulative_fit() #572

Merged
merged 16 commits into from
Feb 26, 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 NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Updated `estimate_infections()` so that rather than imputing missing data, it now skips these data points in the likelihood. This is a breaking change as it alters the behaviour of the model when dates are missing from a time series but are known to be zero. We recommend that users check their results when updating to this version but expect this to in most cases improve performance. By @seabbs in #528 and reviewed by @sbfnk.
* `simulate_infections` has been renamed to `forecast_infections` in line with `simulate_secondary` and `forecast_secondary`. The terminology is: a forecast is done from a fit to existing data, a simulation from first principles. By @sbfnk in #544 and reviewed by @seabbs.
* A new `simulate_infections` function has been added that can be used to simulate from the model from given initial conditions and parameters. By @sbfnk in #557 and reviewed by @jamesmbaazam.
* The function `init_cumulative_fit()` has been deprecated. By @jamesmbaazam in #541 and reviewed by @sbfnk.

## Documentation

Expand Down
10 changes: 9 additions & 1 deletion R/estimate_infections.R
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,10 @@ estimate_infections <- function(reported_cases,

#' Generate initial conditions by fitting to cumulative cases
#'
#' @description `r lifecycle::badge("experimental")`
#' @description `r lifecycle::badge("deprecated")`
#'
#' This function has been deprecated and will be removed in version 2.0.0.
#'
#' Fits a model to cumulative cases. This may be a useful approach to
#' initialising a full model fit for certain data sets where the sampler gets
#' stuck or cannot easily be initialised as fitting to cumulative cases changes
Expand Down Expand Up @@ -315,6 +318,11 @@ estimate_infections <- function(reported_cases,
init_cumulative_fit <- function(args, samples = 50, warmup = 50,
id = "init", verbose = FALSE,
backend = "rstan") {
deprecate_warn(
when = "1.5.0",
what = "init_cumulative_fit()",
details = "The function will be removed completely in version 2.0.0."
)
futile.logger::flog.debug(
"%s: Fitting to cumulative data to initialise chains", id,
name = "EpiNow2.epinow.estimate_infections.fit"
Expand Down
11 changes: 10 additions & 1 deletion R/opts.R
Original file line number Diff line number Diff line change
Expand Up @@ -853,13 +853,16 @@ rstan_opts <- function(object = NULL,
#' national level fit to parametrise regional level fits. Optionally a
#' character string can be passed with the currently supported option being
#' "cumulative". This fits the model to cumulative cases and may be useful for
#' certain data sets where the sampler gets stuck or struggles to initialise.
#' certain data sets where the sampler gets stuck or struggles to initialise.
#' See [init_cumulative_fit()] for details.
#'
#' This implementation is based on the approach taken in
#' [epidemia](https://github.com/ImperialCollegeLondon/epidemia/) authored by
#' James Scott.
#'
#' This argument is deprecated and the default (NULL) will be used from
#' version 2.0.0.
#'
#' @param return_fit Logical, defaults to TRUE. Should the fit stan model be
#' returned.
#'
Expand Down Expand Up @@ -915,6 +918,12 @@ stan_opts <- function(object = NULL,
opts <- c(opts, stan_vb_opts(samples = samples, ...))
}
if (!is.null(init_fit)) {
deprecate_warn(
when = "1.5.0",
what = "stan_opts(init_fit)",
details = paste("This argument is deprecated and the default (NULL)",
"will be used from version 2.0.0.")
)
if (is.character(init_fit)) {
init_fit <- arg_match(init_fit, values = "cumulative")
}
Expand Down
5 changes: 4 additions & 1 deletion man/init_cumulative_fit.Rd

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

5 changes: 4 additions & 1 deletion man/stan_opts.Rd

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

3 changes: 3 additions & 0 deletions tests/testthat/test-opts.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test_that("deprecated arguments are caught", {
expect_deprecated(stan_opts(init_fit = "cumulative"))
})
Loading