Learn R Programming

exdqlm (version 0.4.0)

exdqlmForecast: k-step-ahead quantile forecasts

Description

Computes filtered and k-step-ahead forecast quantiles from a fitted dynamic quantile model and optionally adds them to an existing plot.

Usage

exdqlmForecast(
  start.t,
  k,
  m1,
  fFF = NULL,
  fGG = NULL,
  plot = TRUE,
  add = FALSE,
  cols = c("purple", "magenta"),
  cr.percent = 0.95,
  return.draws = FALSE,
  n.samp = NULL,
  seed = NULL
)

Value

An object of class "exdqlmForecast" containing the following:

  • start.t Integer index at which forecasts start (within the span of the fitted model in m1).

  • k Integer number of steps ahead forecasted.

  • m1 The fitted exDQLM model object used to initialize the forecast.

  • cr.percent The probability mass for the credible intervals (e.g., 0.95).

  • fa Forecast state mean vectors (\(q \times k\) matrix).

  • fR Forecast state covariance matrices (\(q \times q \times k\) array).

  • ff Forecast quantile means (length-k numeric).

  • fQ Forecast quantile variances (length-k numeric).

  • samp.fore Optional posterior predictive forecast draws (k x n.samp) returned when return.draws = TRUE.

Arguments

start.t

Integer index at which forecasts start (must be within the span of the fitted model in m1).

k

Integer number of steps ahead to forecast.

m1

A fitted exDQLM model object, returned by exdqlmLDVB(), exdqlmMCMC(), or legacy exdqlmISVB().

fFF

Optional state vector(s) for the forecast steps. A numeric matrix with \(q\) rows and either 1 column (non–time-varying) or k columns (time-varying). Its dimension must match the fitted model in m1.

fGG

Optional evolution matrix/matrices for the forecast steps. Either a numeric \(q \times q\) matrix (non–time-varying) or a \(q \times q \times k\) array (time-varying). Its dimensions must match the fitted model in m1.

plot

Logical value indicating whether to plot filtered and forecast quantiles with equal–tailed credible intervals. Default is TRUE.

add

Logical value indicating whether to add the forecasted quantiles to the current plot. Default is FALSE.

cols

Character vector of length 2 giving the colors for filtered and forecasted quantiles respectively. Default c("purple","magenta").

cr.percent

Numeric in (0, 1) indicating the probability mass for the credible intervals (e.g., 0.95). Default 0.95.

return.draws

Logical; if TRUE, the function also returns a matrix of posterior predictive forecast draws in samp.fore. Default is FALSE.

n.samp

Optional positive integer specifying how many forecast draws to return when return.draws = TRUE. If omitted, all available posterior \((\sigma,\gamma)\) draws from m1 are used.

seed

Optional integer random seed used only for forecast-draw generation when return.draws = TRUE. If provided, the previous R RNG state is restored on exit.

Examples

Run this code
# \donttest{
 # Toy example
 data("scIVTmag", package = "exdqlm")
 old = options(exdqlm.max_iter = 20L)
 y = scIVTmag[1:100]
 model = polytrendMod(1, stats::quantile(y, 0.85), 10)
 M0 = exdqlmLDVB(y, p0 = 0.85, model, df = c(0.98), dim.df = c(1),
                  gam.init = -3.5, sig.init = 15, n.samp = 30,
                  verbose = FALSE)
 exdqlmForecast(start.t = 90, k = 10, m1 = M0)
 M0.forecast = exdqlmForecast(start.t = 90, k = 10, m1 = M0,
                              return.draws = TRUE, n.samp = 50, seed = 123)
 dim(M0.forecast$samp.fore)
 options(old)
# }

Run the code above in your browser using DataLab