% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/conditional_forecast.R
\name{conditional_forecast}
\alias{conditional_forecast}
\title{Conditional forecasts from a fitted steady-state BVAR model}
\usage{
conditional_forecast(
  bvar_obj,
  conditions,
  pi = 0.95,
  fcst_type = c("mean", "median"),
  growth_rate_idx = NULL,
  plot_idx = NULL
)
}
\arguments{
\item{bvar_obj}{A steady-state \code{bvar} object that has been passed through
\code{\link{fit}}.}

\item{conditions}{A data frame with three columns: \code{var} (integer index
of the conditioned variable), \code{horizon} (integer forecast horizon at
which the condition is imposed), and \code{value} (numeric, the imposed
condition). Note that \code{var} and \code{horizon} must be integers, as
they are used for indexing.}

\item{pi}{Numeric. The prediction interval width. Default \code{0.95}, i.e. 95\% prediction interval.}

\item{fcst_type}{Character. Whether to use \code{"mean"} or \code{"median"}
as the point forecast. Default \code{"mean"}.}

\item{growth_rate_idx}{Integer vector. Indices of variables of which to convert forecasts to
annual growth rates \eqn{\ln x_{t} - \ln x_{t-f}}, where \eqn{f} is
the frequency of the data (4 for quarterly, 12 for monthly).
Only suitable for variables specified as \eqn{\ln x_{t} - \ln x_{t-1}}, i.e.
\code{diff(log(x))} or \code{100*diff(log(x))}.
Computed by summing up to \eqn{f} log first differences. Default is \code{NULL}.}

\item{plot_idx}{Integer vector. Indices of variables to plot. If \code{NULL}
(default), all variables are plotted. Forecasts are always computed and
returned for all variables, regardless of \code{plot_idx}.}
}
\value{
Invisibly returns a list with three matrices: \code{forecast}, \code{lower}, and
\code{upper}, each of dimension \code{H x k}.
}
\description{
Computes and plots conditional forecasts from a fitted steady-state \code{bvar} object.
Conditions are imposed on specific variables at specific horizons using Algorithm 3.3.1
from Dieppe, Legrand, and van Roye (2016). Both conditional and unconditional
forecasts are plotted for comparison. Please note that for the moment, conditional forecasting
is only enabled for the homoscedastic steady-state BVAR, i.e. when \code{SV=FALSE} in \code{priors()}.
}
\details{
See Section 5.3 of Dieppe, Legrand, and van Roye (2016) for more details.
Please note the limitations of this method, see the detailed discussion in Section 5.4 of Dieppe, Legrand, and van Roye (2016).
}
\examples{
\donttest{
#homoscedastic with Jeffreys prior
yt <- matrix(rnorm(50), 25, 2)

bvar_obj <- bvar(data = yt)

bvar_obj <- setup(bvar_obj, p=1, deterministic = "constant")

bvar_obj <- priors(bvar_obj,
                   lambda_1 = 0.2,
                   lambda_2 = 0.5,
                   lambda_3 = 1,
                   first_own_lag_prior_mean = rep(1,2),
                   theta_Psi = rep(0, 2),
                   Omega_Psi = diag(0.1, 2, 2),
                   Jeffreys = TRUE,
                   SV = FALSE,
                   SV_type = NULL,
                   SV_priors = NULL)
                   
bvar_obj <- fit(bvar_obj,
                H = 8,
                d_pred = matrix(rep(1,8)),
                iter = 200,
                warmup = 50,
                chains = 1,
                cores = 1)
                
conditions <- data.frame(var = rep(2,8),
                         horizon = rep(1:8),
                         value   = rep(1,8))
                         
(cond_fcst <- conditional_forecast(bvar_obj,
                                  conditions,
                                  pi=0.68,
                                  fcst_type = "mean"))
}
}
\references{
Dieppe, A., Legrand, R., and van Roye, B. (2016).
The BEAR toolbox. Working Paper Series, No. 1934. European Central Bank.
}
