diff --git a/R/fit_peak.R b/R/fit_peak.R index db0f805..5bff451 100644 --- a/R/fit_peak.R +++ b/R/fit_peak.R @@ -11,7 +11,7 @@ #' uses the peak observations from each previous season it can only #' explain the current intensity in relation to the peak of the season. #' -#' @param weighted_observations A tibble containing three columns of size n; +#' @param weighted_observations A tibble containing two columns of size n; #' `observation`, which represents the data points, and `weight`, which is the #' importance assigned to an observation. Higher weights indicate that an #' observation has more influence on the model outcome, while lower weights @@ -62,8 +62,7 @@ #' # Add into a tibble with weight decreasing going one season step back #' peak_input <- tibble::tibble( #' observation = observations, -#' weight = 0.8^rep(season_num_rev, each = obs), -#' season = season[rep(seq(from = 1, to = length(season)), each = obs)] +#' weight = 0.8^rep(season_num_rev, each = obs) #' ) #' #' # Use the peak model @@ -86,6 +85,14 @@ fit_peak <- function( lower_optim = -Inf, upper_optim = Inf ) { + # Check input arguments + coll <- checkmate::makeAssertCollection() + checkmate::assert_tibble(weighted_observations, add = coll) + checkmate::assert_names(colnames(weighted_observations), + identical.to = c("observation", "weight"), add = coll) + checkmate::assert_numeric(lower_optim, add = coll) + checkmate::assert_numeric(upper_optim, add = coll) + checkmate::reportAssertions(coll) # Match the arguements. family <- rlang::arg_match(family) optim_method <- rlang::arg_match(optim_method) diff --git a/man/fit_peak.Rd b/man/fit_peak.Rd index adf79d2..606af9c 100644 --- a/man/fit_peak.Rd +++ b/man/fit_peak.Rd @@ -14,7 +14,7 @@ fit_peak( ) } \arguments{ -\item{weighted_observations}{A tibble containing three columns of size n; +\item{weighted_observations}{A tibble containing two columns of size n; \code{observation}, which represents the data points, and \code{weight}, which is the importance assigned to an observation. Higher weights indicate that an observation has more influence on the model outcome, while lower weights @@ -88,8 +88,7 @@ observations = rep(stats::rnorm(10,obs), length(season)) # Add into a tibble with weight decreasing going one season step back peak_input <- tibble::tibble( observation = observations, - weight = 0.8^rep(season_num_rev, each = obs), - season = season[rep(seq(from = 1, to = length(season)), each = obs)] + weight = 0.8^rep(season_num_rev, each = obs) ) # Use the peak model diff --git a/tests/testthat/test-fit_peak.R b/tests/testthat/test-fit_peak.R index 7549755..fc50164 100644 --- a/tests/testthat/test-fit_peak.R +++ b/tests/testthat/test-fit_peak.R @@ -8,8 +8,7 @@ test_that("Can run the fit_peak fun without error", { peak_input <- tibble::tibble( observation = observations, - weight = 0.8^rep(season_num_rev, each = obs), - season = season[rep(seq(from = 1, to = length(season)), each = obs)] + weight = 0.8^rep(season_num_rev, each = obs) ) expect_no_error(fit_peak(weighted_observations = peak_input))