Skip to content

Commit

Permalink
changes enforced by CRAN
Browse files Browse the repository at this point in the history
  • Loading branch information
seabbs committed Oct 20, 2022
1 parent 34b4e0c commit 8e95120
Show file tree
Hide file tree
Showing 26 changed files with 164 additions and 169 deletions.
6 changes: 3 additions & 3 deletions R/epinow-internal.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ update_horizon <- function(horizon, target_date, reported_cases) {
#' Saves observed data to a target location if given.
#' @inheritParams setup_target_folder
#' @inheritParams epinow
#' @return NULL
#' @return No return value, called for side effects
#' @export
save_input <- function(reported_cases, target_folder) {
if (!is.null(target_folder)) {
Expand All @@ -45,7 +45,7 @@ save_input <- function(reported_cases, target_folder) {
#' @seealso estimate_infections
#' @inheritParams setup_target_folder
#' @inheritParams estimate_infections
#' @return NULL
#' @return No return value, called for side effects
#' @export
save_estimate_infections <- function(estimates, target_folder = NULL,
samples = TRUE, return_fit = TRUE) {
Expand Down Expand Up @@ -105,7 +105,7 @@ estimates_by_report_date <- function(estimates, CrIs = c(0.2, 0.5, 0.9),
#' @param latest_folder Character string containing the path to the latest target folder.
#' As produced by `setup_target_folder`.
#' @inheritParams setup_target_folder
#' @return NULL
#' @return No return value, called for side effects
#' @export
copy_results_to_latest <- function(target_folder = NULL, latest_folder = NULL) {
if (!is.null(target_folder)) {
Expand Down
55 changes: 34 additions & 21 deletions R/estimate_infections.R
Original file line number Diff line number Diff line change
@@ -1,27 +1,40 @@
#' Estimate Infections, the Time-Varying Reproduction Number and the Rate of Growth
#' Estimate Infections, the Time-Varying Reproduction Number and the Rate of
#' Growth
#'
#' @description `r lifecycle::badge("maturing")`
#' Uses a non-parametric approach to reconstruct cases by date of infection from reported
#' cases. It uses either a generative Rt model or non-parametric back calculation to estimate underlying
#' latent infections and then maps these infections to observed cases via uncertain reporting delays and a flexible
#' observation model. See the examples and function arguments for the details of all options. The default settings
#' may not be sufficient for your use case so the number of warmup samples (`stan_args = list(warmup)`) may need to
#' be increased as may the overall number of samples. Follow the links provided by any warnings messages to diagnose
#' issues with the MCMC fit. It is recommended to explore several of the Rt estimation approaches supported as not all
#' of them may be suited to users own use cases. See [here](https://gist.github.com/seabbs/163d0f195892cde685c70473e1f5e867)
#' for an example of using `estimate_infections` within the `epinow` wrapper to estimate Rt for Covid-19 in a country from
#' the ECDC data source.
#' @param reported_cases A data frame of confirmed cases (confirm) by date (date). confirm must be integer and date must be
#' in date format.
#' @param generation_time A list containing the mean, standard deviation of the mean (mean_sd),
#' standard deviation (sd), standard deviation of the standard deviation and the maximum allowed value for the
#' generation time (assuming a gamma distribution).
#' @param delays A call to `delay_opts()` defining delay distributions and options. See the documentation of `delay_opts()`
#' and the examples below for details.
#' @param horizon Numeric, defaults to 7. Number of days into the future to forecast.
#' @param verbose Logical, defaults to `TRUE` when used interactively and otherwise `FALSE`. Should verbose debug progress messages be printed. Corresponds to the "DEBUG" level from
#' `futile.logger`. See `setup_logging` for more detailed logging options.
#' Uses a non-parametric approach to reconstruct cases by date of infection
#' from reported cases. It uses either a generative Rt model or non-parametric
#' back calculation to estimate underlying latent infections and then maps
#' these infections to observed cases via uncertain reporting delays and a
#' flexible observation model. See the examples and function arguments for th
#' details of all options. The default settings may not be sufficient for your
#' use case so the number of warmup samples (`stan_args = list(warmup)`) may
#' need to be increased as may the overall number of samples. Follow the links
#' provided by any warnings messages to diagnose issues with the MCMC fit. It
#' is recommended to explore several of the Rt estimation approaches supported
#' as not all of them may be suited to users own use cases. See
#' [here](https://gist.github.com/seabbs/163d0f195892cde685c70473e1f5e867)
#' for an example of using `estimate_infections` within the `epinow` wrapper to
#' estimate Rt for Covid-19 in a country from the ECDC data source.
#'
#' @param reported_cases A data frame of confirmed cases (confirm) by date
#' (date). confirm must be integer and date must be in date format.
#' @param generation_time A list containing the mean, standard deviation of the
#' mean (mean_sd), standard deviation (sd), standard deviation of the standard
#' deviation and the maximum allowed value for the generation time (assuming a
#' gamma distribution).
#' @param delays A call to `delay_opts()` defining delay distributions and
#' options. See the documentation of `delay_opts()` and the examples below for
#' details.
#' @param horizon Numeric, defaults to 7. Number of days into the future to
#' forecast.
#' @param verbose Logical, defaults to `TRUE` when used interactively and otherwise `FALSE`. Should verbose debug progress messages be printed.
#' Corresponds to the "DEBUG" level from `futile.logger`. See `setup_logging`
#' for more detailed logging options.
#' @export
#' @return A list of output including: posterior samples, summarised posterior
#' samples, data used to fit the model, and the fit object itself.
#'
#' @seealso epinow regional_epinow forecast_infections simulate_infections
#' @inheritParams create_stan_args
#' @inheritParams create_stan_data
Expand Down
16 changes: 0 additions & 16 deletions R/opts.R
Original file line number Diff line number Diff line change
Expand Up @@ -524,22 +524,6 @@ opts_list <- function(opts, reported_cases, ...) {
#' call to an `_opts()` function.
#' @param region A character string indicating a region of interest.
#' @return A list of options
#' @examples
#' # uses example case vector
#' cases <- example_confirmed[1:40]
#' cases <- data.table::rbindlist(list(
#' data.table::copy(cases)[, region := "testland"],
#' cases[, region := "realland"]
#' ))
#'
#' # regional options
#' regional_opts <- opts_list(rt_opts(), cases)
#' EpiNow2:::filter_opts(regional_opts, "realland")
#' # default only
#' EpiNow2:::filter_opts(rt_opts(), "realland")
#' # settings are NULL in one regions
#' regional_opts <- update_list(regional_opts, list(realland = NULL))
#' EpiNow2:::filter_opts(regional_opts, "realland")
filter_opts <- function(opts, region) {
if (region %in% names(opts)) {
out <- opts[[region]]
Expand Down
2 changes: 1 addition & 1 deletion R/setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ setup_logging <- function(threshold = "INFO", file = NULL,
#' @param mirror_epinow Logical, defaults to FALSE. Should internal logging be
#' returned from `epinow` to the console.
#' @inheritParams setup_target_folder
#' @return NULL
#' @return No return value, called for side effects
#' @export
#' @importFrom purrr walk
#' @examples
Expand Down
7 changes: 5 additions & 2 deletions R/simulate_infections.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
#' This function simulates infections using an existing fit to observed cases but with a modified
#' time-varying reproduction number. This can be used to explore forecast models or past counterfactuals.
#' Simulations can be run in parallel using `future::plan`.
#' @param estimates The \code{estimates} element of an \code{epinow} run that has been done with
#' output = "fit", or the result of \code{estimate_infections} with \code{return_fit} set to TRUE.
#' @param estimates The \code{estimates} element of an \code{epinow} run that
#' has been done with output = "fit", or the result of
#' \code{estimate_infections} with \code{return_fit} set to TRUE.
#' @param model A compiled stan model as returned by `rstan::stan_model`.
#' @param R A numeric vector of reproduction numbers; these will overwrite the reproduction numbers
#' contained in \code{estimates}, except elements set to NA. If it is longer than the time series
Expand All @@ -25,6 +26,8 @@
#' @importFrom progressr with_progress progressor
#' @importFrom data.table rbindlist as.data.table
#' @importFrom lubridate days
#' @return A list of output as returned by [estimate_infections()] but based on
#' results from the specified scenario rather than fitting.
#' @export
#' @examples
#' \donttest{
Expand Down
23 changes: 2 additions & 21 deletions R/utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' to the current directory.
#' @importFrom purrr walk
#' @importFrom futile.logger flog.info
#' @return NULL
#' @return No return value, called for side effects
#' @export
clean_nowcasts <- function(date = NULL, nowcast_dir = ".") {
if (is.null(date)) {
Expand Down Expand Up @@ -157,9 +157,6 @@ allocate_delays <- function(delay_var, no_delays) {
#' empty if missing.
#' @param n Numeric, number of samples to assign an empty array
#' @return A list of parameters some allocated to be empty
#' @examples
#' data <- list(x = 1, y = 2, z = 30)
#' EpiNow2:::allocate_empty(data, params = c("x", "t"))
allocate_empty <- function(data, params, n = 0) {
for (param in params) {
if (!exists(param, data)) {
Expand All @@ -181,22 +178,6 @@ allocate_empty <- function(data, params, n = 0) {
#' of futile.logger for details. Supported options are "info" and "debug"
#' @return A logical vector of named output arguments
#' @importFrom futile.logger flog.info flog.debug
#' @examples
#' # select nothing
#' EpiNow2:::match_output_arguments(supported_args = c("fit", "plots", "samples"))
#'
#' # select just plots
#' EpiNow2:::match_output_arguments("plots", supported_args = c("fit", "plots", "samples"))
#'
#' # select plots and samples
#' EpiNow2:::match_output_arguments(c("plots", "samples"),
#' supported_args = c("fit", "plots", "samples")
#' )
#'
#' # lazily select arguments
#' EpiNow2:::match_output_arguments("p",
#' supported_args = c("fit", "plots", "samples")
#' )
match_output_arguments <- function(input_args = c(),
supported_args = c(),
logger = NULL,
Expand Down Expand Up @@ -245,7 +226,7 @@ match_output_arguments <- function(input_args = c(),
#' @param files A character vector indicating the target files
#' @param target_dir A character string indicating the target directory for the file
#' @param ... Additional arguments passed to `rstan::expose_stan_functions`.
#' @return NULL
#' @return No return value, called for side effects
#' @export
#' @importFrom rstan expose_stan_functions stanc
#' @importFrom purrr map_chr
Expand Down
4 changes: 0 additions & 4 deletions man/allocate_empty.Rd

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

3 changes: 3 additions & 0 deletions man/clean_nowcasts.Rd

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

3 changes: 3 additions & 0 deletions man/copy_results_to_latest.Rd

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

7 changes: 4 additions & 3 deletions man/create_clean_reported_cases.Rd

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

7 changes: 4 additions & 3 deletions man/create_shifted_cases.Rd

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

16 changes: 9 additions & 7 deletions man/create_stan_data.Rd

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

24 changes: 14 additions & 10 deletions man/epinow.Rd

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

Loading

0 comments on commit 8e95120

Please sign in to comment.