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

Telkamp7/issue3 #4

Merged
merged 10 commits into from
Oct 30, 2023
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Generated by roxygen2: do not edit by hand

S3method(predict,aedseo)
export("%>%")
export(aedseo)
export(fit_growth_rate)
export(predict_growth_rate)
export(tsd)
importFrom(lifecycle,deprecated)
importFrom(magrittr,"%>%")
Expand Down
9 changes: 7 additions & 2 deletions R/aedseo.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
#'
#' # Print the AEDSEO results
#' print(aedseo_results)
#'
aedseo <- function(
tsd,
k = 5,
Expand Down Expand Up @@ -106,5 +105,11 @@ aedseo <- function(
)
}

return(res)
# Turn the results into an `aedseo` class
ans <- tibble::new_tibble(
x = res,
class = "aedseo"
)

return(ans)
}
15 changes: 8 additions & 7 deletions R/predict_growth_rate.R → R/predict.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
#' 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.
#'
#' @return 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.
#' @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
Expand Down Expand Up @@ -43,14 +44,14 @@
#' )
#'
#' # Predict growth rates for the next 5 time steps
#' prediction <- predict_growth_rate(object = aedseo_results, n_step = 5)
#' prediction <- predict(object = aedseo_results, n_step = 5)
#'
#' # Print the prediction
#' print(prediction)
#'
predict_growth_rate <- function(object, n_step) {
predict.aedseo <- function(object, n_step, ...) {
# Calculate the prediction
prediction <- dplyr::last(object) %>%
ans <- dplyr::last(object) %>%
dplyr::reframe(
t = 0:n_step,
time = .data$reference_time + t,
Expand All @@ -60,5 +61,5 @@ predict_growth_rate <- function(object, n_step) {
)

# Return
return(prediction)
return(ans)
}
1 change: 0 additions & 1 deletion man/aedseo.Rd

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

12 changes: 7 additions & 5 deletions man/predict_growth_rate.Rd → man/predict.aedseo.Rd

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

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ test_that("Returns the desired length", {
n_step <- 5

# Predict growth rates for the next 5 time steps
prediction <- predict_growth_rate(object = aedseo_results, n_step = n_step)
prediction <- predict(object = aedseo_results, n_step = n_step)

# Return the number of prediction + the initial observation
expect_length(prediction$estimate, n_step + 1)
Expand Down