conditional_forecast: Conditional Forecast

View source: R/conditional-forecast.R

conditional_forecastR Documentation

Conditional Forecast

Description

Produces a dynamic forecast of a fitted DSGE model conditional on a user-specified path for one or more observable variables. Useful for policy scenario analysis (e.g. holding the policy rate fixed for k periods, or imposing an inflation path implied by a survey).

Usage

conditional_forecast(object, horizon = 12L, condition, ...)

## S3 method for class 'dsge_fit'
conditional_forecast(object, horizon = 12L, condition, ...)

Arguments

object

A dsge_fit object (returned by estimate).

horizon

Integer. Number of periods to forecast. Default 12.

condition

A named list. Each element corresponds to one observable variable and supplies the conditioning path as a numeric vector of length up to horizon. Use NA to leave a particular period unconditioned (the forecast value at that period is then determined endogenously).

...

Additional arguments (currently unused).

Details

The minimum-norm shock sequence is computed by solving

e^* = R^\prime (R R^\prime)^{-1} (c - b)

where R is the stacked impulse-response matrix from each shock at each period to the conditioned variables, c is the vector of conditioning targets (de-meaned) and b is the unconditional forecast of those variables. A small Tikhonov regularisation is added to R R^\prime for numerical stability when constraints are linearly dependent.

Value

An object of class c("dsge_conditional_forecast", "dsge_forecast") containing the same fields as forecast.dsge_fit plus the implied structural shock sequence (shocks), the conditioning input (condition), and a logical flag conditioned in the forecasts data frame indicating which (period, variable) pairs were constrained.

Because the result inherits from dsge_forecast, the existing plot.dsge_forecast method will display it with history and (point) forecast. Confidence bands are not currently computed for the conditional case.

References

Waggoner, D.F. and Zha, T. (1999). Conditional forecasts in dynamic multivariate models. Review of Economics and Statistics, 81(4), 639-651.

See Also

forecast.dsge_fit for unconditional forecasts.

Examples


nk <- dsge_model(
  obs(p   ~ beta * lead(p) + kappa * x),
  unobs(x ~ lead(x) - (r - lead(p) - g)),
  obs(r   ~ psi * p + u),
  state(u ~ rhou * u),
  state(g ~ rhog * g),
  fixed = list(beta = 0.99),
  start = list(kappa = 0.1, psi = 1.5, rhou = 0.7, rhog = 0.9)
)
sol <- solve_dsge(nk,
  params   = c(kappa = 0.1, psi = 1.5, rhou = 0.7, rhog = 0.9),
  shock_sd = c(e.u = 1.0, e.g = 0.5))
# Simulate data and fit
set.seed(1)
TT <- 100
xst <- matrix(0, TT, nrow(sol$H))
y   <- matrix(0, TT, nrow(sol$G))
for (t in 2:TT) {
  e <- rnorm(ncol(sol$M)) * c(1, 0.5)
  xst[t, ] <- as.numeric(sol$H %*% xst[t-1, ] + sol$M %*% e)
  y[t, ]   <- as.numeric(sol$G %*% xst[t, ])
}
colnames(y) <- rownames(sol$G)
dat <- as.data.frame(y[, nk$variables$observed, drop = FALSE])
fit <- estimate(nk, data = dat)

# Conditional forecast: hold r at 0 for the next 4 periods
cf <- conditional_forecast(fit, horizon = 12,
  condition = list(r = c(0, 0, 0, 0, rep(NA, 8))))
plot(cf)



dsge documentation built on Sept. 25, 2026, 5:08 p.m.