diff --git a/R/acp.R b/R/acp.R index f5ee02b..f6f0189 100644 --- a/R/acp.R +++ b/R/acp.R @@ -124,7 +124,7 @@ acp <- function(object, alpha = 1 - 0.01 * object$level, gamma = 0.005, ) for (h in seq(horizon)) { - indx <- seq(ncal+h-1, nrow(errors), by = 1L) + indx <- seq(ncal+h-1, nrow(errors)-!object$forward, by = 1L) alphat_h <- alphat_lower_h <- alphat_upper_h <- errt_h <- errt_lower_h <- errt_upper_h <- diff --git a/R/cvforecast.R b/R/cvforecast.R index 42cf4e9..eb00009 100644 --- a/R/cvforecast.R +++ b/R/cvforecast.R @@ -59,6 +59,7 @@ #' series with the same dimensional characteristics as \code{MEAN}.} #' \item{level}{The confidence values associated with the prediction intervals.} #' \item{call}{The matched call.} +#' \item{forward}{Whether \code{forward} is applied.} #' If \code{forward} is \code{TRUE}, the components \code{mean}, \code{lower}, #' \code{upper}, and \code{model} will also be returned, showing the information #' about the final fitted model and forecasts using all available observations, see @@ -224,6 +225,7 @@ cvforecast <- function(y, forecastfun, h = 1, level = c(80, 95), out$level <- level } out$call <- match.call() + out$forward <- forward # The final forecasting model output if forward is TRUE if (forward) { out$mean <- fc$mean diff --git a/R/mcp.R b/R/mcp.R index a71d6e6..7556881 100644 --- a/R/mcp.R +++ b/R/mcp.R @@ -149,7 +149,7 @@ mcp <- function(object, alpha = 1 - 0.01 * object$level, ) for (h in seq(horizon)) { - indx <- seq(h, nrow(errors), by = 1L) + indx <- seq(h, nrow(errors)-!object$forward, by = 1L) errt_lower_h <- errt_upper_h <- integ_lower_h <- integ_upper_h <- @@ -157,6 +157,7 @@ mcp <- function(object, alpha = 1 - 0.01 * object$level, matrix(NA_real_, nrow = n, ncol = length(alpha)) qts_lower_h <- qts_upper_h <- qs_lower_h <- qs_upper_h <- matrix(0, nrow = n, ncol = length(alpha)) + for (t in indx) { t_burnin <- max(t - ncal + 1L, h) errors_subset <- subset( diff --git a/R/pid.R b/R/pid.R index bb16998..103aefc 100644 --- a/R/pid.R +++ b/R/pid.R @@ -165,7 +165,7 @@ pid <- function(object, alpha = 1 - 0.01 * object$level, ) for (h in seq(horizon)) { - indx <- seq(h, nrow(errors), by = 1L) + indx <- seq(h, nrow(errors)-!object$forward, by = 1L) errt_h <- errt_lower_h <- errt_upper_h <- integ_h <- integ_lower_h <- integ_upper_h <- diff --git a/R/scp.R b/R/scp.R index 9e74511..40143be 100644 --- a/R/scp.R +++ b/R/scp.R @@ -157,7 +157,7 @@ scp <- function(object, alpha = 1 - 0.01 * object$level, ) for (h in seq(horizon)) { - indx <- seq(ncal+h-1, nrow(errors), by = 1L) + indx <- seq(ncal+h-1, nrow(errors)-!object$forward, by = 1L) for (t in indx) { errors_subset <- subset( @@ -191,6 +191,7 @@ scp <- function(object, alpha = 1 - 0.01 * object$level, type = quantiletype, na.rm = na.rm) } + for (i in seq(length(alpha))) { lower[[i]][t+h, h] <- pf[t+h, h] - q_lo[i] upper[[i]][t+h, h] <- pf[t+h, h] + q_up[i] diff --git a/man/cvforecast.Rd b/man/cvforecast.Rd index f923235..d6b924e 100644 --- a/man/cvforecast.Rd +++ b/man/cvforecast.Rd @@ -68,6 +68,7 @@ each \code{level}. Each element within the list will be a multivariate time series with the same dimensional characteristics as \code{MEAN}.} \item{level}{The confidence values associated with the prediction intervals.} \item{call}{The matched call.} +\item{forward}{Whether \code{forward} is applied.} If \code{forward} is \code{TRUE}, the components \code{mean}, \code{lower}, \code{upper}, and \code{model} will also be returned, showing the information about the final fitted model and forecasts using all available observations, see