Skip to content

Commit

Permalink
Explicitly use innovation residuals for bootstrap paths
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchelloharawild committed Nov 8, 2024
1 parent d8a0fbc commit 2b6cd38
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion R/generate.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ generate.mdl_df <- function(x, new_data = NULL, h = NULL, times = 1, seed = NULL
unnest_tsbl(x, ".sim", parent_key = kv)
}

#' @export
generate.lst_mdl <- function(x, new_data = NULL, h = NULL, times = 1, seed = NULL, ...) {
map2(x,
new_data %||% rep(list(NULL), length.out = NROW(x)),
generate, h = h, times = times, seed = seed, ...)
}

#' @rdname generate.mdl_df
#'
#' @param bootstrap If TRUE, then forecast distributions are computed using simulation with resampled errors.
Expand Down Expand Up @@ -77,7 +84,7 @@ generate.mdl_ts <- function(x, new_data = NULL, h = NULL, times = 1, seed = NULL
}

if(bootstrap) {
res <- residuals(x$fit)
res <- residuals(x$fit, type = "innovation")
f_mean <- if(length(x$response) == 1) mean else colMeans
res <- stats::na.omit(res) - f_mean(res, na.rm = TRUE)
i <- if(bootstrap_block_size == 1) {
Expand Down

0 comments on commit 2b6cd38

Please sign in to comment.