Skip to content

Commit

Permalink
Rename again
Browse files Browse the repository at this point in the history
  • Loading branch information
SofiaOtero committed Nov 5, 2024
1 parent 0f9e405 commit 0bbe362
Show file tree
Hide file tree
Showing 24 changed files with 200 additions and 159 deletions.
9 changes: 5 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Generated by roxygen2: do not edit by hand

S3method(autoplot,seasonal_onset)
S3method(autoplot,tsd)
S3method(plot,seasonal_onset)
S3method(autoplot,tsd_onset)
S3method(plot,tsd)
S3method(predict,seasonal_onset)
S3method(summary,seasonal_onset)
S3method(plot,tsd_onset)
S3method(predict,tsd_onset)
S3method(summary,tsd_onset)
export("%>%")
export(aedseo)
export(autoplot)
Expand All @@ -14,6 +14,7 @@ export(fit_growth_rate)
export(fit_quantiles)
export(seasonal_burden_levels)
export(seasonal_onset)
export(to_time_series)
export(tsd)
importFrom(ggplot2,autoplot)
importFrom(grDevices,devAskNewPage)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@

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

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

## Features

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

* Added `to_time_series()` as a replacement for the deprecated `tsd()` 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
24 changes: 12 additions & 12 deletions R/autoplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
#'
#' @description
#'
#' This function generates a complete 'ggplot' object suitable for visualizing time series data in an `tsd` object.
#' 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 `tsd` or `seasonal_onset_tsd` object
#' @param object An `tsd` or `tsd_onset` object
#' @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 @@ -19,8 +19,8 @@
#' @aliases autoplot
#'
#' @examples
#' # Create an example tsd object
#' tsd_object <- tsd(
#' # Create an example `tsd` object
#' time_series <- tsd(
#' observation = c(100, 120, 150, 180, 220, 270),
#' time = as.Date(c(
#' "2023-01-01",
Expand All @@ -33,19 +33,19 @@
#' time_interval = "day"
#' )
#'
#' # Create a ggplot visualization for the tsd object
#' autoplot(tsd_object)
#' # Create a ggplot visualization for the `tsd` object
#' autoplot(time_series)
#'
#' # Create an tsd object
#' tsd_object <- seasonal_onset(
#' tsd = tsd_object,
#' # Create an `tsd_onset` object
#' time_series_with_onset <- seasonal_onset(
#' tsd = time_series,
#' k = 3,
#' level = 0.95,
#' family = "quasipoisson"
#' )
#'
#' # Create a ggplot visualization of growth rates with confidence intervals
#' autoplot(tsd_object, linewidth = 1, alpha = 0.2)
#' autoplot(time_series_with_onset, linewidth = 1, alpha = 0.2)
#' @importFrom ggplot2 autoplot
#' @rdname autoplot
#' @export
Expand All @@ -68,9 +68,9 @@ autoplot.tsd <- function(object, ...) {
}
#' @importFrom grDevices devAskNewPage
#' @rdname autoplot
#' @method autoplot seasonal_onset
#' @method autoplot tsd_onset
#' @export
autoplot.seasonal_onset <- function(
autoplot.tsd_onset <- function(
object,
linewidth = 0.7,
size = 2,
Expand Down
18 changes: 9 additions & 9 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' 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 `tsd` or `seasonal_onset` object
#' @param x An `tsd` or `tsd_onset` object
#' @param ... Additional arguments passed to specific methods.
#'
#' @return A 'ggplot' object for visualizing the time series data.
Expand All @@ -15,8 +15,8 @@
#' @seealso [autoplot()]
#'
#' @examples
#' # Create an example tsd object
#' tsd_object <- tsd(
#' # Create an example `tsd` object
#' time_series <- to_time_series(
#' observation = c(100, 120, 150, 180, 220, 270),
#' time = as.Date(c(
#' "2023-01-01",
Expand All @@ -29,12 +29,12 @@
#' time_interval = "day"
#' )
#'
#' # Create a ggplot visualization for the tsd object
#' plot(tsd_object)
#' # Create a ggplot visualization for the `tsd` object
#' plot(time_series)
#'
#' # Create an seasonal_onset object
#' # Create an `tsd_onset` object
#' object <- seasonal_onset(
#' tsd = tsd_object,
#' tsd = time_series,
#' k = 3,
#' level = 0.95,
#' family = "quasipoisson"
Expand All @@ -50,8 +50,8 @@ plot.tsd <- function(x, ...) {
print(autoplot(x, ...))
}
#' @rdname plot
#' @method plot seasonal_onset
#' @method plot tsd_onset
#' @export
plot.seasonal_onset <- function(x, ...) {
plot.tsd_onset <- function(x, ...) {
print(autoplot(object = x, ...))
}
14 changes: 7 additions & 7 deletions R/predict.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
#' 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 `seasonal_onset()` function.
#' @param object A `tsd_onset` 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 `seasonal_onset` containing the predicted growth rates, including time,
#' @return A tibble-like object called `tsd_onset` 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.
#'
Expand All @@ -20,7 +20,7 @@
#'
#' @examples
#' # Analyze the data using the aedseo package
#' tsd_data <- tsd(
#' time_series <- to_time_series(
#' observation = c(100, 120, 150, 180, 220, 270),
#' time = as.Date(c(
#' "2023-01-01",
Expand All @@ -33,16 +33,16 @@
#' time_interval = "day"
#' )
#'
#' tsd_results <- seasonal_onset(
#' tsd = tsd_data,
#' time_series_with_onset <- seasonal_onset(
#' tsd = time_series,
#' k = 3,
#' level = 0.95,
#' family = "poisson"
#' )
#'
#' # Predict growth rates for the next 5 time steps
#' predict(object = tsd_results, n_step = 5)
predict.seasonal_onset <- function(object, n_step = 3, ...) {
#' predict(object = time_series_with_onset, n_step = 5)
predict.tsd_onset <- function(object, n_step = 3, ...) {
# Calculate the prediction
res <- dplyr::last(object) %>%
dplyr::reframe(
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 @@ -5,7 +5,7 @@
#' This function calculates the burden levels of time series of observations that are stratified by season.
#' It uses the previous seasons to calculate the levels of the newest season.
#'
#' @param tsd A `aedseo_tsd` object containing time series data with 'time' and 'observation'.
#' @param tsd A `tsd` object containing time series data with 'time' and 'observation'.
#' @param season_weeks A numeric vector of length 2, `c(start, end)`, with the start and end weeks of the seasons to
#' stratify the observations by. Must span the new year; e.g.: `season_weeks = c(21, 20)`.
#' NOTE: The data must include data for a complete previous season to make predictions for the newest season.
Expand Down
7 changes: 5 additions & 2 deletions R/seasonal_onset.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ seasonal_onset <- function(
# Turn the results into an `seasonal_onset` class
ans <- tibble::new_tibble(
x = res,
class = "seasonal_onset",
class = "tsd_onset",
k = k,
level = level,
disease_threshold = disease_threshold,
Expand All @@ -177,9 +177,12 @@ seasonal_onset <- function(
#' Deprecated aedseo function
#' @description
#' `r lifecycle::badge("deprecated")`
#' This function has been renamed to better reflect its purpose.
#' Please use `seasonal_onset()` instead.
#' @param ... Arguments passed to `seasonal_onset()`
#' @keywords internal
#' @export
aedseo <- function(...) {
warning("`aedseo()` is deprecated. Please use `seasonal_onset()` instead.")
lifecycle::deprecate_warn("0.1.2", "aedseo()", "seasonal_onset()")
seasonal_onset(...)
}
12 changes: 6 additions & 6 deletions R/summary.R
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#' Summary method for seasonal_onset objects
#' Summary method for `tsd_onset` objects
#'
#' @description
#'
#' Summarize the results of an seasonal onset analysis, including the latest growth rate estimate,
#' the confidence interval, and information about growth warnings.
#'
#' @param object An object of class 'seasonal_onset' containing the results of a seasonal_onset analysis.
#' @param object An object of class 'tsd_onset' containing the results of a seasonal_onset analysis.
#' @param ... Additional arguments (not used).
#'
#' @return This function is used for its side effect, which is printing a summary message to the console.
#'
#' @export
#'
#' @examples
#' # Create a tibble object from sample data
#' tsd_data <- tsd(
#' # Create a `tsd_onset` object from sample data
#' tsd_data <- to_time_series(
#' observation = c(100, 120, 150, 180, 220, 270),
#' time = as.Date(c(
#' "2023-01-01",
Expand All @@ -27,14 +27,14 @@
#' time_interval = "day"
#' )
#'
#' # Calculate seasonal_onset with a 3-day window and a Poisson family model
#' # Calculate seasonal_onset results with a 3-day window and a Poisson family model
#' seasonal_onset(
#' tsd = tsd_data,
#' k = 3,
#' level = 0.95,
#' family = "poisson"
#' )
summary.seasonal_onset <- function(object, ...) {
summary.tsd_onset <- function(object, ...) {
# Extract the last observation
last_observation <- dplyr::last(object)

Expand Down
25 changes: 19 additions & 6 deletions R/tsd.R → R/to_time_series.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Create a S3 `tsd` (time-series data) object from observed data and corresponding dates.
#' Create a tibble-like `tsd` (time-series data) object from observed data and corresponding dates.
#'
#' @description
#'
Expand All @@ -18,7 +18,7 @@
#'
#' @examples
#' # Create a `tsd` object from daily data
#' daily_tsd <- tsd(
#' daily_tsd <- to_time_series(
#' observation = c(10, 15, 20, 18),
#' time = as.Date(
#' c("2023-01-01", "2023-01-02", "2023-01-03", "2023-01-04")
Expand All @@ -27,24 +27,24 @@
#' )
#'
#' # Create a `tsd` object from weekly data
#' weekly_tsd <- tsd(
#' weekly_tsd <- to_time_series(
#' observation = c(100, 120, 130),
#' time = as.Date(
#' c("2023-01-01", "2023-01-08", "2023-01-15")
#' ),
#' time_interval = "week"
#' )
#'
#' # Create a `aedseo` object from monthly data
#' monthly_tsd <- tsd(
#' # Create a `tsd` object from monthly data
#' monthly_tsd <- to_time_series(
#' observation = c(500, 520, 540),
#' time = as.Date(
#' c("2023-01-01", "2023-02-01", "2023-03-01")
#' ),
#' time_interval = "month"
#' )
#'
tsd <- function(observation, time, time_interval = c("day", "week", "month")) {
to_time_series <- function(observation, time, time_interval = c("day", "week", "month")) {
# Check input arguments
coll <- checkmate::makeAssertCollection()
checkmate::assert_date(time, add = coll)
Expand All @@ -69,3 +69,16 @@ tsd <- function(observation, time, time_interval = c("day", "week", "month")) {

return(tsd)
}

#' Deprecated tsd function
#' @description
#' `r lifecycle::badge("deprecated")`
#' This function has been renamed to better reflect its purpose.
#' Please use `to_time_series()` instead.
#' @param ... Arguments passed to `to_time_series()`
#' @keywords internal
#' @export
tsd <- function(...) {
lifecycle::deprecate_warn("0.1.2", "tsd()", "to_time_series()")
to_time_series(...)
}
3 changes: 3 additions & 0 deletions man/aedseo.Rd

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

22 changes: 11 additions & 11 deletions man/autoplot.Rd

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

Loading

0 comments on commit 0bbe362

Please sign in to comment.