X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=R%2FgetError.R;fp=R%2FgetError.R;h=0000000000000000000000000000000000000000;hb=469529710f56c790ae932b45d13fed2e34bcabf2;hp=affe6c307b49ad84954990cd40fd02ddcec55cea;hpb=4c59ec9aefef8ea5464723a293b3aa39ee02dc60;p=talweg.git diff --git a/R/getError.R b/R/getError.R deleted file mode 100644 index affe6c3..0000000 --- a/R/getError.R +++ /dev/null @@ -1,47 +0,0 @@ -#' @title Get error -#' -#' @description Obtain the errors between forecast and data -#' -#' @param data Dataset, object of class \code{Data} output of \code{getData} -#' @param forecast Forecast object, class \code{Forecast} output of \code{getForecast} -#' @param horizon Horizon where to compute the error (<= horizon used in \code{getForecast}) -#' -#' @return A list (abs,MAPE) of lists (day,indices) -#' -#' @export -getError = function(data, forecast, horizon=data$getStdHorizon()) -{ - L = forecast$getSize() - mape_day = rep(0, horizon) - abs_day = rep(0, horizon) - mape_indices = rep(NA, L) - abs_indices = rep(NA, L) - - nb_no_NA_data = 0 - for (i in seq_len(L)) - { - index = forecast$getIndexInData(i) - serie = data$getSerie(index+1)[1:horizon] - pred = forecast$getSerie(i)[1:horizon] - if (!any(is.na(serie)) && !any(is.na(pred))) - { - nb_no_NA_data = nb_no_NA_data + 1 - mape_increment = abs(serie - pred) / serie - mape_increment[is.nan(mape_increment)] = 0. # 0 / 0 - mape_increment[!is.finite(mape_increment)] = 1. # >0 / 0 - mape_day = mape_day + mape_increment - abs_increment = abs(serie - pred) - abs_day = abs_day + abs_increment - mape_indices[i] = mean(mape_increment) - abs_indices[i] = mean(abs_increment) - } - } - - list( - "abs" = list( - "day" = abs_day / nb_no_NA_data, - "indices" = abs_indices), - "MAPE" = list( - "day" = mape_day / nb_no_NA_data, - "indices" = mape_indices) ) -}