R/best_mdl.R

#' Selects model with minimal mean absolute forecating error.
#'
#' @param ... Arguments passed to \code{crossv_ts_multi}.
#' @return Name of model function which produced smallest error.
#' @export

best_mdl <- function(...) {

  err_ts_lst <- crossv_ts_multi(...)

  mean_errs <- purrr::map_dbl(err_ts_lst, ~ mean(abs(.), na.rm = TRUE))

  mdl <- names(mean_errs[mean_errs == min(mean_errs)])

  if (length(mdl) != 1L)
    warning(
      paste0("Result of model selection is not length one: ",
             paste0(mdl, collapse = ", ")))

  mdl

}
malexan/forecastbox documentation built on May 29, 2019, 3:44 a.m.