prepare package for yearly report
[talweg.git] / pkg / R / J_Persistence.R
CommitLineData
102bcfda
BA
1#' getPersistenceJumpPredict
2#'
3#' Analog of the PersistenceForecaster: predict the jump after last observed value either
4#' by re-applying the last jump between similar day and its follower (if argument
5#' "same_day" is TRUE), or by re-using the very last observed jump (when "same_day" =
6#' FALSE).
3d69ff21 7#'
99f83c9a 8#' @inheritParams computeForecast
e030a6e3 9#' @inheritParams getZeroJumpPredict
546b0cb6 10#'
3ddf1c12 11#' @aliases J_Persistence
102bcfda 12#'
d2ab47a7
BA
13getPersistenceJumpPredict = function(data, today, memory, predict_from,
14 horizon, params, ...)
3d69ff21 15{
09cf9c19
BA
16 #return gap between end of similar day curve and first day of tomorrow (in the past)
17 first_day = max(1, today-memory)
e5aa669a 18 same_day = ifelse(hasArg("same_day"), list(...)$same_day, TRUE)
d2ab47a7 19 index <- today
09cf9c19
BA
20 repeat
21 {
d2ab47a7
BA
22 # If 'same_day', get the last known future of similar day
23 index = index - ifelse(same_day,7,1)
09cf9c19
BA
24 if (index < first_day)
25 return (NA)
d2ab47a7
BA
26 gap <-
27 if (predict_from >= 2)
28 data$getSerie(index)[predict_from] - data$getSerie(index)[predict_from-1]
29 else
30 head(data$getSerie(index),1) - tail(data$getSerie(index-1),1)
31 if (!is.na(gap))
32 return (gap)
09cf9c19 33 }
3d69ff21 34}