predict.bvar {BVAR} | R Documentation |
Predict method for Bayesian VARs
Description
Retrieves / calculates forecasts for Bayesian VARs generated via
bvar
. If a forecast is already present and no settings are
supplied it is simply retrieved, otherwise it will be calculated.
To store the results you may want to assign the output using the setter
function (predict(x) <- predict(x)
). May also be used to update
confidence bands.
Usage
## S3 method for class 'bvar'
predict(object, ..., conf_bands, n_thin = 1L, newdata)
predict(object) <- value
## S3 method for class 'bvar_fcast'
summary(object, vars = NULL, ...)
Arguments
object |
A |
... |
A |
conf_bands |
Numeric vector of confidence bands to apply.
E.g. for bands at 5%, 10%, 90% and 95% set this to |
n_thin |
Integer scalar. Every n_thin'th draw in object is used to predict, others are dropped. |
newdata |
Optional numeric matrix or dataframe. Used to base the prediction on. |
value |
A |
vars |
Optional numeric or character vector. Used to subset the summary
to certain variables by position or name (must be available). Defaults to
|
Value
Returns a list of class bvar_fcast
including forecasts
at desired confidence bands.
The summary method returns a numeric array of forecast paths at the
specified confidence bands.
See Also
Examples
# Access a subset of the fred_qd dataset
data <- fred_qd[, c("CPIAUCSL", "UNRATE", "FEDFUNDS")]
# Transform it to be stationary
data <- fred_transform(data, codes = c(5, 5, 1), lag = 4)
# Estimate a BVAR using one lag, default settings and very few draws
x <- bvar(data, lags = 1, n_draw = 1000L, n_burn = 200L, verbose = FALSE)
# Calculate a forecast with an increased horizon
y <- predict(x, horizon = 20)
# Add some confidence bands and store the forecast
predict(x) <- predict(x, conf_bands = c(0.05, 0.16))
# Recalculate with different settings and increased thinning
predict(x, bv_fcast(24L), n_thin = 10L)
# Simulate some new data to predict on
predict(x, newdata = matrix(rnorm(300), ncol = 3))
# Calculate a conditional forecast (with a constrained second variable).
predict(x, cond_path = c(1, 1, 1, 1, 1, 1), cond_var = 2)
# Get a summary of the stored forecast
summary(x)
# Only get the summary for variable #2
summary(x, vars = 2L)