X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=pkg%2FR%2FcomputeError.R;h=c3bc4f381da34112eca28f339db3093582ed9d67;hb=cf3bb00128ac8cb930996455faf7c99a3fc102fb;hp=7da103288805fa64d84feecdad8689b60e55de66;hpb=2057c793ad9929ed5bef8663ea28b896c84df0fc;p=talweg.git diff --git a/pkg/R/computeError.R b/pkg/R/computeError.R index 7da1032..c3bc4f3 100644 --- a/pkg/R/computeError.R +++ b/pkg/R/computeError.R @@ -1,29 +1,32 @@ #' Compute error #' -#' Obtain the errors between forecast and data +#' Compute the errors between forecasted and measured series. #' -#' @param data Dataset, object of class \code{Data} output of \code{getData} -#' @param pred Forecast object, class \code{Forecast} output of \code{computeForecast} +#' @param data Object of class \code{Data} output of \code{getData} +#' @param pred Object of class \code{Forecast} output of \code{computeForecast} #' @param horizon Horizon where to compute the error #' (<= horizon used in \code{computeForecast}) #' -#' @return A list (abs,MAPE) of lists (day,indices) +#' @return A list (abs,MAPE) of lists (day,indices). The "indices" slots contain series +#' of size L where L is the number of predicted days; i-th value is the averaged error +#' (absolute or MAPE) on day i. The "day" slots contain curves of errors, for each time +#' step, averaged on the L forecasting days. #' #' @export -computeError = function(data, pred, horizon=data$getStdHorizon()) +computeError = function(data, pred, predict_from, horizon=length(data$getSerie(1))) { - L = forecast$getSize() - mape_day = rep(0, horizon) - abs_day = rep(0, horizon) + L = pred$getSize() + mape_day = rep(0, horizon-predict_from+1) + abs_day = rep(0, horizon-predict_from+1) 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] - forecast = pred$getForecast(i)[1:horizon] + index = pred$getIndexInData(i) + serie = data$getSerie(index)[predict_from:horizon] + forecast = pred$getForecast(i)[predict_from:horizon] if (!any(is.na(serie)) && !any(is.na(forecast))) { nb_no_NA_data = nb_no_NA_data + 1