Skip to contents

Plot koma forecasts

Usage

# S3 method for class 'koma_forecast'
plot(x, y = NULL, ...)

Arguments

x

A koma_forecast object (forecast).

y

Ignored. Included for compatibility with the generic function.

...

Additional parameters:

variables

A vector of variable names to plot.

fig

Optional. A Plotly figure object. Default is NULL.

theme

Optional. A theme for the plot. Default is NULL.

fan

Optional. Logical. If TRUE, add a fan chart from quantiles.

fan_quantiles

Optional. Numeric probabilities in (0, 1] (or percentages in [0, 100]) to define fan-chart bands. Default uses the available quantiles.

central_tendency

Optional. A string specifying the type of forecast to print. Can be "mean", "median", or a quantile name like "q_5", "q_50", "q_95". Default is "mean" if available, otherwise "median", or a specified quantile.

Value

A Plotly figure object displaying the data.

Examples

if (requireNamespace("plotly", quietly = TRUE)) {
  data("simulated_sem")

  dates <- list(
    current = c(2024, 4),
    estimation = simulated_sem$dates$estimation,
    forecast = list(start = c(2025, 1), end = c(2025, 4))
  )

  ts_data <- simulated_sem$ts_data
  ts_data[simulated_sem$sys_eq$endogenous_variables] <- lapply(
    simulated_sem$sys_eq$endogenous_variables,
    function(x) {
      stats::window(ts_data[[x]], end = dates$current)
    }
  )

  set.seed(11)
  fit <- estimate(
    ts_data = ts_data,
    sys_eq = simulated_sem$sys_eq,
    dates = dates,
    options = list(gibbs = list(ndraws = 10))
  )
  fc <- forecast(fit, dates = dates)
  plot(fc, variables = "consumption")
}
#> 
#> ── Gibbs Sampler Settings ──────────────────────────────────────────────────────
#> 
#> ── System Wide Settings ──
#>   • Number of draws (`ndraws`): 10
#>   • Burn-in ratio (`burnin_ratio`): 0.5
#>   • Burn-in (`burnin`): 5
#>   • Store frequency (`nstore`): 1
#>   • Number of saved draws (`nsave`): 5
#>   • Tau (`tau`): 1.1
#> 
#> 
#> ── Estimation ──────────────────────────────────────────────────────────────────
#> 
#> ── Forecast ────────────────────────────────────────────────────────────────────