Skip to content

Commit

Permalink
Fix subscript out of bounds error when forward=FALSE
Browse files Browse the repository at this point in the history
  • Loading branch information
xqnwang committed May 20, 2024
1 parent 874477f commit c1803cb
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion R/acp.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 <-
Expand Down
2 changes: 2 additions & 0 deletions R/cvforecast.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion R/mcp.R
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,15 @@ 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 <-
q_lo_h <- q_up_h <-
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(
Expand Down
2 changes: 1 addition & 1 deletion R/pid.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 <-
Expand Down
3 changes: 2 additions & 1 deletion R/scp.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions man/cvforecast.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c1803cb

Please sign in to comment.