a few fixes
[talweg.git] / pkg / R / computeError.R
index 3aa028f..c3bc4f3 100644 (file)
 #'   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 = pred$getSize()
-       mape_day = rep(0, horizon)
-       abs_day = rep(0, horizon)
+       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)
 
@@ -25,8 +25,8 @@ computeError = function(data, pred, horizon=data$getStdHorizon())
        for (i in seq_len(L))
        {
                index = pred$getIndexInData(i)
-               serie = data$getSerie(index+1)[1:horizon]
-               forecast = pred$getForecast(i)[1:horizon]
+               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