plot_density_forecast: Plot Density Forecast

View source: R/plots.R

plot_density_forecastR Documentation

Plot Density Forecast

Description

Generates a kernel density plot of a predictive distribution, highlighting the point forecast and a symmetric credible interval at a specified level. The predictive distribution can be constructed by treating the cross-sectional spread of model forecasts at a given period as a proxy for forecast uncertainty (see compute_crps for the centring convention).

Usage

plot_density_forecast(
  full_distribution,
  point_forecast,
  title = "Density Forecast",
  ci_level = 0.9
)

Arguments

full_distribution

Numeric vector of forecast samples drawn from the predictive distribution (e.g., forecasts from all models at one time period, optionally centred and shifted as in compute_crps).

point_forecast

Single numeric value: the point forecast to highlight (e.g., the mean or median of full_distribution, or one model's forecast).

title

Character string for the plot title. Default is "Density Forecast".

ci_level

Numeric confidence interval level strictly between 0 and 1. Default is 0.90, producing lower and upper quantiles at (1 - ci_level) / 2 and 1 - (1 - ci_level) / 2.

Details

To build a pseudo-predictive distribution from the metals dataset, centre the cross-sectional model forecasts at period t around their mean, following the same convention used in compute_crps: dist_t <- forecasts[t, ] - forecasts[t, k] + mean(forecasts[t, ]). This preserves cross-sectional spread while recentring on the cross-sectional mean rather than on model k's own point forecast.

Value

A ggplot object. The plot shows a kernel density curve (blue fill), a red dashed vertical line at point_forecast, and orange dotted vertical lines at the lower and upper quantiles of the credible interval. The subtitle reports the numeric bounds of the interval.

See Also

compute_crps, run_comprehensive_erc_analysis'

Examples

data(metals)
t       <- 100
K       <- ncol(metals) - 1
dist_t  <- as.numeric(metals[t, 1:K]) - metals[t, 7] +
            mean(as.numeric(metals[t, 1:K]))
pt_fcst <- mean(as.numeric(metals[t, 1:K]))
plot_density_forecast(dist_t, pt_fcst,
                      title    = "Predictive Density at t = 100",
                      ci_level = 0.90)

RCtest documentation built on June 2, 2026, 9:07 a.m.