Learn R Programming

BVAR (version 0.2.2)

predict.bvar: 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 ex-post. To store a prediction you may want to assign the output of predict.bvar to object$fcast. May also be used to update confidence bands.

Usage

# S3 method for bvar
predict(object, ..., conf_bands, n_thin = 1L, newdata)

# S3 method for bvar_fcast print(x, vars = NULL, ...)

# S3 method for bvar_fcast summary(object, vars = NULL, digits = 2L, ...)

# S3 method for bvar_fcast_summary print(x, digits = 2L, ...)

Arguments

object, x

A bvar object, obtained from bvar. Summary and print methods take in a bvar_fcast object.

...

A bv_fcast object or parameters to be fed into bv_fcast. Contains settings for the forecast.

conf_bands

Numeric vector of desired confidence bands to apply. E.g. for bands at 5%, 10%, 90% and 95% set this to c(0.05, 0.1). Note that the median, i.e. 0.5 is always included.

n_thin

Integer scalar. Every n_thin'th draw in object is used for forecasting, others are dropped.

newdata

Optional numeric matrix or dataframe. Used to base the prediction on. Fitted values are used by default.

vars

Optional numeric or character vector. Used to subset the summary to certain variables by position or name (must be available). Defaults to NULL, i.e. all variables.

digits

Integer scalar. Fed to round and applied to numeric outputs (i.e. the quantiles).

Value

Returns a list of class bvar_fcast including forecasts at desired confidence bands. See bvar. The summary method returns a numeric array of forecast paths at the specified confidence bands.

See Also

bvar; plot.bvar_fcast; bv_fcast

Examples

Run this code
# NOT RUN {
data <- matrix(rnorm(200), ncol = 2)
x <- bvar(data, lags = 2)

# Access forecast and update confidence bands
predict(x, conf_bands = 0.01)

# Adjust, compute and store a longer forecast
x$fcast <- predict(x, horizon = 24L)

# Lower draws, use `bv_fcast()` to set options and add confidence bands
predict(x, bv_fcast(24L), n_thin = 10L, conf_bands = c(0.05, 0.16))

# Use new data to calculate a prediction
predict(x, newdata = matrix(rnorm(200), ncol = 2))

# Get a summary of the last saved forecast
summary(x)

# Limit the summary to variable #2
summary(x, vars = 2L)
# }

Run the code above in your browser using DataLab