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

Deprecating aedseo and tsd, renaming to seasonal_onset and to_time_series #41

Merged
merged 9 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
13 changes: 7 additions & 6 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
# Generated by roxygen2: do not edit by hand

S3method(autoplot,aedseo)
S3method(autoplot,aedseo_tsd)
S3method(plot,aedseo)
S3method(plot,aedseo_tsd)
S3method(predict,aedseo)
S3method(summary,aedseo)
S3method(autoplot,seasonal_onset)
S3method(autoplot,tsd)
S3method(plot,seasonal_onset)
S3method(plot,tsd)
S3method(predict,seasonal_onset)
S3method(summary,seasonal_onset)
export("%>%")
export(aedseo)
export(autoplot)
export(epi_calendar)
export(fit_growth_rate)
export(fit_quantiles)
export(seasonal_burden_levels)
export(seasonal_onset)
export(tsd)
importFrom(ggplot2,autoplot)
importFrom(grDevices,devAskNewPage)
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# aedseo (development version)

## Deprecations

* `aedseo()` is now deprecated. Please use `seasonal_onset()` instead. A warning is shown when using `aedseo()` (#41).

## Features

* Added `seasonal_onset()` as a replacement for the deprecated `aedseo()` function (#41).

* Added the `seasonal_burden_levels()` function, which calculates burden levels based on data from previous seasons with two different methods; "peak_levels" or "intensity_levels" (#37).

* Added the `fit_quantiles()` function, which optimises a user selected distribution and calculates the quantiles based on observations and weights. It is meant to be used within the `seasonal_burden_levels()` function (#35, #37).
Expand Down
31 changes: 15 additions & 16 deletions R/autoplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
#'
#' @description
#'
#' This function generates a complete 'ggplot' object suitable for
#' visualizing time series data in an `aedseo_tsd` object. It creates a line
#' plot connecting the observations and adds points at each data point.
#' This function generates a complete 'ggplot' object suitable for visualizing time series data in an `tsd` object.
#' It creates a line plot connecting the observations and adds points at each data point.
#'
#' @param object An `aedseo_tsd` or `aedseo` object
#' @param object An `tsd` or `seasonal_onset_tsd` object
SofiaOtero marked this conversation as resolved.
Show resolved Hide resolved
#' @param linewidth Numeric, the width of the line for the growth rate
#' @param size Numeric, size of observational points.
#' @param width Numeric, the width of the error bar employed to show the
Expand All @@ -20,8 +19,8 @@
#' @aliases autoplot
#'
#' @examples
#' # Create an example aedseo_tsd object
#' aedseo_tsd_object <- tsd(
#' # Create an example tsd object
#' tsd_object <- tsd(
SofiaOtero marked this conversation as resolved.
Show resolved Hide resolved
#' observation = c(100, 120, 150, 180, 220, 270),
#' time = as.Date(c(
#' "2023-01-01",
Expand All @@ -34,29 +33,29 @@
#' time_interval = "day"
#' )
#'
#' # Create a ggplot visualization for the aedseo_tsd object
#' autoplot(aedseo_tsd_object)
#' # Create a ggplot visualization for the tsd object
#' autoplot(tsd_object)
#'
#' # Create an aedseo object
#' aedseo_object <- aedseo(
#' tsd = aedseo_tsd_object,
#' # Create an tsd object
#' tsd_object <- seasonal_onset(
SofiaOtero marked this conversation as resolved.
Show resolved Hide resolved
#' tsd = tsd_object,
#' k = 3,
#' level = 0.95,
#' family = "quasipoisson"
#' )
#'
#' # Create a ggplot visualization of growth rates with confidence intervals
#' autoplot(aedseo_object, linewidth = 1, alpha = 0.2)
#' autoplot(tsd_object, linewidth = 1, alpha = 0.2)
#' @importFrom ggplot2 autoplot
#' @rdname autoplot
#' @export
autoplot <- function(object, ...) {
UseMethod("autoplot")
}
#' @rdname autoplot
#' @method autoplot aedseo_tsd
#' @method autoplot tsd
#' @export
autoplot.aedseo_tsd <- function(object, ...) {
autoplot.tsd <- function(object, ...) {
object %>%
ggplot2::ggplot(
mapping = ggplot2::aes(
Expand All @@ -69,9 +68,9 @@ autoplot.aedseo_tsd <- function(object, ...) {
}
#' @importFrom grDevices devAskNewPage
#' @rdname autoplot
#' @method autoplot aedseo
#' @method autoplot seasonal_onset
#' @export
autoplot.aedseo <- function(
autoplot.seasonal_onset <- function(
object,
linewidth = 0.7,
size = 2,
Expand Down
10 changes: 4 additions & 6 deletions R/epi_calendar.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
#'
#' @description
#'
#' This function identifies the epidemiological season, (must span new year)
#' to which a given date belongs.
#' The epidemiological season is defined by a start and end week, where weeks
#' are numbered according to the ISO week date system.
#' This function identifies the epidemiological season, (must span new year) to which a given date belongs.
#' The epidemiological season is defined by a start and end week, where weeks are numbered according to the
#' ISO week date system.
#'
#' @param date A date object representing the date to check.
#' @param start An integer specifying the start week of the epidemiological
#' season.
#' @param start An integer specifying the start week of the epidemiological season.
#' @param end An integer specifying the end week of the epidemiological season.
#'
#' @return A character vector indicating the season:
Expand Down
19 changes: 6 additions & 13 deletions R/fit_growth_rate.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
#'
#' @description
#'
#' This function fits a growth rate model to time series observations and
#' provides parameter estimates along with confidence intervals.
#' This function fits a growth rate model to time series observations and provides parameter estimates along with
#' confidence intervals.
#'
#' @param observations A numeric vector containing the time series
#' observations.
#' @param level The confidence level for parameter estimates, a numeric
#' value between 0 and 1.
#' @param family A character string specifying the family for modeling.
#' Choose between "poisson," or "quasipoisson".
#' @param observations A numeric vector containing the time series observations.
#' @param level The confidence level for parameter estimates, a numeric value between 0 and 1.
#' @param family A character string specifying the family for modeling. Choose between "poisson," or "quasipoisson".
#'
#' @return A list containing:
#' - 'fit': The fitted growth rate model.
Expand All @@ -24,15 +21,11 @@
#' # Fit a growth rate model to a time series of counts
#' # (e.g., population growth)
#' data <- c(100, 120, 150, 180, 220, 270)
#' growth_rate_model <- fit_growth_rate(
#' fit_growth_rate(
#' observations = data,
#' level = 0.95,
#' family = "poisson"
#' )
#'
#' # Print the estimated growth rate and confidence interval
#' print(growth_rate_model$estimate)
#'
fit_growth_rate <- function(
observations,
level = 0.95,
Expand Down
31 changes: 15 additions & 16 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
#'
#' @description
#'
#' This function generates a complete 'ggplot' object suitable for
#' visualizing time series data in an `aedseo_tsd` object. It creates a line
#' plot connecting the observations and adds points at each data point.
#' This function generates a complete 'ggplot' object suitable for visualizing time series data in an `tsd` object.
#' It creates a line plot connecting the observations and adds points at each data point.
#'
#' @param x An `aedseo_tsd` or `aedseo` object
#' @param x An `tsd` or `seasonal_onset` object
#' @param ... Additional arguments passed to specific methods.
#'
#' @return A 'ggplot' object for visualizing the time series data.
Expand All @@ -16,8 +15,8 @@
#' @seealso [autoplot()]
#'
#' @examples
#' # Create an example aedseo_tsd object
#' aedseo_tsd_object <- tsd(
#' # Create an example tsd object
#' tsd_object <- tsd(
SofiaOtero marked this conversation as resolved.
Show resolved Hide resolved
#' observation = c(100, 120, 150, 180, 220, 270),
#' time = as.Date(c(
#' "2023-01-01",
Expand All @@ -30,29 +29,29 @@
#' time_interval = "day"
#' )
#'
#' # Create a ggplot visualization for the aedseo_tsd object
#' plot(aedseo_tsd_object)
#' # Create a ggplot visualization for the tsd object
#' plot(tsd_object)
#'
#' # Create an aedseo object
#' aedseo_object <- aedseo(
#' tsd = aedseo_tsd_object,
#' # Create an seasonal_onset object
#' object <- seasonal_onset(
#' tsd = tsd_object,
#' k = 3,
#' level = 0.95,
#' family = "quasipoisson"
#' )
#'
#' # Create a ggplot visualization of growth rates with confidence intervals
#' plot(aedseo_object, linewidth = 1, alpha = 0.2)
#' plot(object, linewidth = 1, alpha = 0.2)
#' @importFrom graphics plot
#' @rdname plot
#' @method plot aedseo_tsd
#' @method plot tsd
#' @export
plot.aedseo_tsd <- function(x, ...) {
plot.tsd <- function(x, ...) {
print(autoplot(x, ...))
}
#' @rdname plot
#' @method plot aedseo
#' @method plot seasonal_onset
#' @export
plot.aedseo <- function(x, ...) {
plot.seasonal_onset <- function(x, ...) {
print(autoplot(object = x, ...))
}
31 changes: 12 additions & 19 deletions R/predict.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@
#'
#' @description
#'
#' This function is used to predict future growth rates based on a model object
#' created using the 'aedseo' package. It takes the model object and the number
#' of future time steps (`n_step`) for which you want to make predictions and
#' This function is used to predict future growth rates based on a model object created using the 'aedseo' package.
#' It takes the model object and the number of future time steps (`n_step`) for which you want to make predictions and
#' returns a prediction tibble.
#'
#' @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. Default is 3.
#' @param object A model object created using the `seasonal_onset()` function.
#' @param n_step An integer specifying the number of future time steps for which you want to predict growth rates.
#' @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.
#' @return A tibble S3 object called `seasonal_onset` containing the predicted growth rates, including time,
SofiaOtero marked this conversation as resolved.
Show resolved Hide resolved
#' estimated growth rate, lower confidence interval, and upper confidence interval for the specified number of
#' future time steps.
#'
#' @export
#'
Expand All @@ -36,20 +33,16 @@
#' time_interval = "day"
#' )
#'
#' aedseo_results <- aedseo(
#' tsd_results <- seasonal_onset(
#' tsd = tsd_data,
#' k = 3,
#' level = 0.95,
#' family = "poisson"
#' )
#'
#' # Predict growth rates for the next 5 time steps
#' prediction <- predict(object = aedseo_results, n_step = 5)
#'
#' # Print the prediction
#' print(prediction)
#'
predict.aedseo <- function(object, n_step = 3, ...) {
#' predict(object = tsd_results, n_step = 5)
predict.seasonal_onset <- function(object, n_step = 3, ...) {
# Calculate the prediction
res <- dplyr::last(object) %>%
dplyr::reframe(
Expand All @@ -68,10 +61,10 @@ predict.aedseo <- function(object, n_step = 3, ...) {
level <- attributes_object$level
family <- attributes_object$family

# Turn the results into an `aedseo` class
# Turn the results into a class
ans <- tibble::new_tibble(
x = res,
class = "aedseo_predict",
class = "tsd_predict",
k = k,
level = level,
family = family
Expand Down
2 changes: 1 addition & 1 deletion R/seasonal_burden_levels.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ seasonal_burden_levels <- function(
method <- rlang::arg_match(method)
coll <- checkmate::makeAssertCollection()
checkmate::assert_data_frame(tsd, add = coll)
checkmate::assert_class(tsd, "aedseo_tsd", add = coll)
checkmate::assert_class(tsd, "tsd", add = coll)
checkmate::assert_names(colnames(tsd), identical.to = c("time", "observation"), add = coll)
checkmate::assert_integerish(season_weeks, len = 2, lower = 1, upper = 53,
null.ok = FALSE, add = coll)
Expand Down
Loading
Loading