diff --git a/NAMESPACE b/NAMESPACE index 9638bad..701d1cc 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,7 @@ # Generated by roxygen2: do not edit by hand S3method(predict,aedseo) +S3method(summary,aedseo) export("%>%") export(aedseo) export(fit_growth_rate) diff --git a/R/predict.R b/R/predict.R index 3239eb2..5ae4d6e 100644 --- a/R/predict.R +++ b/R/predict.R @@ -11,12 +11,13 @@ #' @param object A model object created using the `aedseo` package, typically #' the result of the `aedseo()` function. #' @param n_step An integer specifying the number of future time steps for -#' which you want to predict growth rates. -#' @param ... Additional arguement affecting the predictions produced. +#' which you want to predict growth rates. Default is 3. +#' @param ... Additional arguments (not used). #' #' @return A tibble S3 object called `aedseo` containing the predicted growth #' rates, including time, estimated growth rate, lower confidence interval, #' and upper confidence interval for the specified number of future time steps. +#' #' @export #' #' @importFrom rlang .data @@ -49,7 +50,7 @@ #' # Print the prediction #' print(prediction) #' -predict.aedseo <- function(object, n_step, ...) { +predict.aedseo <- function(object, n_step = 3, ...) { # Calculate the prediction ans <- dplyr::last(object) %>% dplyr::reframe( diff --git a/R/summary.R b/R/summary.R index 7046ef9..5ee1b00 100644 --- a/R/summary.R +++ b/R/summary.R @@ -13,6 +13,8 @@ #' @return This function is used for its side effect, which is printing a #' summary message to the console. #' +#' @export +#' #' @examples #' # Create a tsibble object from sample data #' tsd_data <- tsd( diff --git a/man/predict.aedseo.Rd b/man/predict.aedseo.Rd index b2cc425..8da8673 100644 --- a/man/predict.aedseo.Rd +++ b/man/predict.aedseo.Rd @@ -4,21 +4,21 @@ \alias{predict.aedseo} \title{Predict Growth Rates for Future Time Steps} \usage{ -\method{predict}{aedseo}(object, n_step, ...) +\method{predict}{aedseo}(object, n_step = 3, ...) } \arguments{ \item{object}{A model object created using the \code{aedseo} package, typically the result of the \code{aedseo()} function.} \item{n_step}{An integer specifying the number of future time steps for -which you want to predict growth rates.} +which you want to predict growth rates. Default is 3.} -\item{...}{Additional arguement affecting the predictions produced.} +\item{...}{Additional arguments (not used).} } \value{ -A tibble containing the predicted growth rates, including time, -estimated growth rate, lower confidence interval, and upper confidence -interval for the specified number of future time steps. +A tibble S3 object called \code{aedseo} containing the predicted growth +rates, including time, estimated growth rate, lower confidence interval, +and upper confidence interval for the specified number of future time steps. } \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} diff --git a/man/summary.aedseo.Rd b/man/summary.aedseo.Rd index 1c899a3..c93c1ff 100644 --- a/man/summary.aedseo.Rd +++ b/man/summary.aedseo.Rd @@ -7,19 +7,20 @@ \method{summary}{aedseo}(object, ...) } \arguments{ -\item{object}{An object of class 'aedseo' containing the results of an aedseo analysis.} +\item{object}{An object of class 'aedseo' containing the results of an aedseo +analysis.} \item{...}{Additional arguments (not used).} } \value{ -This function is used for its side effect, which is printing a summary message -to the console. +This function is used for its side effect, which is printing a +summary message to the console. } \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} -Summarize the results of an aedseo analysis, including the latest growth rate estimate, -the confidence interval, and information about growth warnings. +Summarize the results of an aedseo analysis, including the latest growth rate +estimate, the confidence interval, and information about growth warnings. } \examples{ # Create a tsibble object from sample data diff --git a/tests/testthat/test-summary.R b/tests/testthat/test-summary.R index aa43e54..15d3131 100644 --- a/tests/testthat/test-summary.R +++ b/tests/testthat/test-summary.R @@ -24,7 +24,7 @@ test_that("Summary prints without errors", { ) # Capture the output of the summary function - tmp <- capture_output(summary.aedseo(aedseo_poisson)) + tmp <- capture_output(summary(aedseo_poisson)) # Verify that the summary printed without errors expect_true(grepl(pattern = "Summary of aedseo Object", x = tmp)) diff --git a/vignettes/aedseo_introduction.Rmd b/vignettes/aedseo_introduction.Rmd index 7c2238c..f5944c2 100644 --- a/vignettes/aedseo_introduction.Rmd +++ b/vignettes/aedseo_introduction.Rmd @@ -24,8 +24,6 @@ library(ggplot2) ## Introduction -This vignette ... - The methodology used to detect the onset of seasonal respiratory epidemics can be divided into two essential criteria: - The local estimate of the exponential growth rate, $r$, is significantly greater than zero. @@ -211,5 +209,36 @@ full_data %>% facet_wrap(facets = vars(name), ncol = 1, scale = "free_y") ``` +## The aedseo package implements S3 methods + +In this section, we will explore how to use the `predict` and `summary` S3 methods provided by the `aedseo` package. These methods enhance the functionality of your `aedseo` objects, allowing you to make predictions and obtain concise summaries of your analysis results. + +### Predicting Growth Rates + +The `predict` method for `aedseo` objects allows you to make predictions for future time steps based on the estimated growth rates. Here's how to use it: + +```{r} + +# Example: Predict growth rates for the next 5 time steps +(prediction <- predict(aedseo_results, n_step = 5)) + +``` + +In the example above, we use the predict method to predict growth rates for the next 5 time steps. The n_step argument specifies the number of steps into the future you want to forecast. The resulting prediction object will contain estimates, lower bounds, and upper bounds for each time step. + +### Summarizing AEDSEO results + +The summary method for aedseo objects provides a concise summary of your automated early detection of seasonal epidemic onset (AEDSEO) analysis. You can use it to retrieve important information about your analysis, including the latest growth warning and the total number of growth warnings: + + +```{r summary} + +summary(aedseo_results) + +``` + +The summary method generates a summary message that includes details such as the reference time point, growth rate estimates, and the number of growth warnings in the series. It helps you quickly assess the key findings of your analysis. + +