Skip to content

Commit

Permalink
Explicitly use marginal quantiles for plotting forecasts
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchelloharawild committed Sep 15, 2024
1 parent 643646d commit 5b74b04
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
9 changes: 8 additions & 1 deletion R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,15 @@ build_fbl_layer <- function(object, data = NULL, level = c(80, 95),
intvl_mapping$fill_ramp <- intvl_mapping$colour_ramp <- sym(".width")
intvl_mapping$fill <- intvl_mapping$colour <- col

qi_marginal <- function(x, .width = 0.95, na.rm = FALSE) {
if (!na.rm && anyNA(x)) {
return(matrix(c(NA_real_, NA_real_), ncol = 2))
}
do.call(rbind, lapply(quantile(x, (1 + c(-1, 1) * .width)/2, type = "marginal", na.rm = na.rm), t))
}

dist_qi_frame <- function(data, level) {
data <- ggdist::median_qi(as_tibble(data), !!sym(distribution_var(data)), .width = level/100)
data <- ggdist::point_interval(as_tibble(data), !!sym(distribution_var(data)), .interval = qi_marginal, .width = level/100)
names(data)[match(".index", names(data))] <- ".response"
data
}
Expand Down
5 changes: 3 additions & 2 deletions man/IRF.Rd

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

2 changes: 1 addition & 1 deletion man/generate.mdl_df.Rd

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

0 comments on commit 5b74b04

Please sign in to comment.