Skip to content
This repository has been archived by the owner on Nov 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #5 from EpiForeSITE/EpiEstim
Browse files Browse the repository at this point in the history
Adds EpiEstim method
  • Loading branch information
gvegayon authored Sep 25, 2024
2 parents e460c5a + e808b55 commit 933959d
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ Imports:
cli,
tibble
Suggests:
rtestim, tinytest, EpiNow2
rtestim, tinytest, EpiNow2, EpiEstim
Remotes: dajmcdon/rtestim
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
S3method(summarize_rtestimate,cv_poisson_rt)
S3method(summarize_rtestimate,default)
S3method(summarize_rtestimate,epinow)
S3method(summarize_rtestimate,estimate_R)
S3method(summarize_rtestimate,poisson_rt)
export(new_summarize)
export(summarize_rtestimate)
importFrom(cli,cli_abort)
importFrom(stats,median)
Expand Down
71 changes: 69 additions & 2 deletions R/summarize_rtestimate.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,52 @@

#' Create a new summary object
#'
#' Creates a new summary object for the `summrt` package while validating the input.
#'
#' @param date Integer vector. vector of index dates.
#' @param median Double vector. vector of median values.
#' @param lb Double vector. vector of lower bounds.
#' @param ub Double vector. vector of upper bounds.
#' @param package String. Name of the package.
#' @export
#' @return A list of class `summrt_summary`. with the following components:
#' - `date`: Integer vector. vector of index dates.
#' - `median`: Double vector. vector of median values.
#' - `lb`: Double vector. vector of lower bounds.
#' - `ub`: Double vector. vector of upper bounds.
#' - `package`: String. Name of the package.
new_summarize <- function(
date, median, lb, ub, package
) {

# Asserting the types
checkmate::assert_integer(date)
checkmate::assert_double(median)
checkmate::assert_double(lb)
checkmate::assert_double(up)
checkmate::assert_string(package)

# Checking the length
len_date <- length(date)
len_median <- length(median)
len_lb <- length(lb)
len_up <- length(up)
if (len_date != len_median || len_date != len_lb || len_date != len_up) {
stop("The length of the date, median, lb, and ub should be the same.")
}

structure(
list(
date = date,
median = median,
lb = lb,
ub = ub,
package = package
),
class = "summrt_summary"
)
}

#' Extract Rt estimation from a model fit
#' @param x Object to extract Rt from.
#' @param ... Additional arguments passed to methods.
Expand Down Expand Up @@ -63,10 +112,28 @@ summarize_rtestimate.poisson_rt <- function(x, level = 0.95, lambda = NULL, ...)
#' @export
summarize_rtestimate.epinow <- function(x, level = 0.95, ...) {

if (!requireNamespace("epinow2", quietly = TRUE)) {
cli::cli_abort("You must install the {.pkg epinow2} package for this functionality.")
if (!requireNamespace("EpiNow2", quietly = TRUE)) {
cli::cli_abort("You must install the {.pkg EpiNow2} package for this functionality.")
}
checkmate::assert_number(level, lower = 0, upper = 1)

# res <- x$estimates$summarized |> dplyr::select()
}

#' @export
#' @details The `estimate_R` method is for the `EpiEstim` package.
#' @rdname summarize_rtestimate
summarize_rtestimate.estimate_R <- function(x, ...) {
if (!requireNamespace("EpiEstim", quietly = TRUE)) {
cli::cli_abort("You must install the {.pkg EpiEstim} package for this functionality.")
}
checkmate::assert_number(level, lower = 0, upper = 1)

new_summarize(
date = x$R$t_end,
median = x$R$`Median(R)`,
lb = x$R$`Quantile.0.025(R)`,
ub = x$R$`Quantile.0.975(R)`,
package = "EpiEstim"
)
}
32 changes: 32 additions & 0 deletions man/new_summarize.Rd

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

6 changes: 6 additions & 0 deletions man/summarize_rtestimate.Rd

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

0 comments on commit 933959d

Please sign in to comment.