diff --git a/R/R/allocator.R b/R/R/allocator.R index 254061a5d..7066f6daf 100644 --- a/R/R/allocator.R +++ b/R/R/allocator.R @@ -49,7 +49,7 @@ #' @param constr_mode Character. Options are \code{"eq"} or \code{"ineq"}, #' indicating constraints with equality or inequality. #' @param date_min,date_max Character. Date range to calculate mean (of non-zero spends) and -#' total spends. Default will consider all dates within window. +#' total spends. Default will consider all dates within window. Length must be 1. #' @return A list object containing allocator result. #' @examples #' \dontrun{ @@ -186,6 +186,7 @@ robyn_allocator <- function(robyn_object = NULL, # Spend values based on date range set dt_optimCost <- dt_mod %>% slice(startRW:endRW) + check_daterange(date_min, date_max, dt_optimCost$ds) if (is.null(date_min)) date_min <- min(dt_optimCost$ds) if (is.null(date_max)) date_max <- max(dt_optimCost$ds) if (date_min < min(dt_optimCost$ds)) date_min <- min(dt_optimCost$ds) diff --git a/R/R/checks.R b/R/R/checks.R index 1054ea85d..9a85041e7 100644 --- a/R/R/checks.R +++ b/R/R/checks.R @@ -684,3 +684,16 @@ check_run_inputs <- function(cores, iterations, trials, intercept_sign, nevergra stop(sprintf("Input 'intercept_sign' must be any of: %s", paste(opts, collapse = ", "))) } } + +check_daterange <- function(date_min, date_max, dates) { + if (!is.null(date_min)) { + if (length(date_min) > 1) stop("Set a single date for 'date_min' parameter") + if (date_min < min(dates)) warning(sprintf( + "Parameter 'date_min' not in your data's date range. Changed to '%s'", min(dates))) + } + if (!is.null(date_max)) { + if (length(date_max) > 1) stop("Set a single date for 'date_max' parameter") + if (date_max > max(dates)) warning(sprintf( + "Parameter 'date_max' not in your data's date range. Changed to '%s'", max(dates))) + } +} diff --git a/R/man/robyn_allocator.Rd b/R/man/robyn_allocator.Rd index b8627cac0..9de1ea3b2 100644 --- a/R/man/robyn_allocator.Rd +++ b/R/man/robyn_allocator.Rd @@ -82,7 +82,7 @@ Defaults to 100000.} indicating constraints with equality or inequality.} \item{date_min, date_max}{Character. Date range to calculate mean (of non-zero spends) and -total spends. Default will consider all dates within window.} +total spends. Default will consider all dates within window. Length must be 1.} \item{export}{Boolean. Export outcomes into local files?} diff --git a/R/man/robyn_converge.Rd b/R/man/robyn_converge.Rd index ffb64b2ed..202d16d32 100644 --- a/R/man/robyn_converge.Rd +++ b/R/man/robyn_converge.Rd @@ -4,7 +4,7 @@ \alias{robyn_converge} \title{Check Models Convergence} \usage{ -robyn_converge(OutputModels, n_cuts = 20, sd_qtref = 3, med_lowb = 3, ...) +robyn_converge(OutputModels, n_cuts = 20, sd_qtref = 3, med_lowb = 2, ...) } \arguments{ \item{OutputModels}{List. Output from \code{robyn_run()}.} @@ -23,12 +23,13 @@ for median. (Criteria #2). Default to 3.} \code{robyn_converge()} consumes \code{robyn_run()} outputs and calculate convergence status and builds convergence plots. Convergence is calculated by default using the following criteria -(having kept the default parameters: sd_qtref = 3 and med_lowb = 3): +(having kept the default parameters: sd_qtref = 3 and med_lowb = 2): \describe{ \item{Criteria #1:}{Last quantile's standard deviation < first 3 quantiles' mean standard deviation} - \item{Criteria #2:}{Last quantile's absolute median < first quantile's - absolute median - 3 * first 3 quantiles' mean standard deviation.} + \item{Criteria #2:}{Last quantile's absolute median < absolute first + quantile's absolute median - 2 * first 3 quantiles' mean standard + deviation} } Both mentioned criteria have to be satisfied to consider MOO convergence. }