View source: R/58_fcast_plot.R
plot.bvar_fcast | R Documentation |
Plotting method for forecasts obtained from predict.bvar
.
Forecasts of all or a subset of the available variables can be plotted.
## S3 method for class 'bvar_fcast'
plot(
x,
vars = NULL,
col = "#737373",
t_back = 1,
area = FALSE,
fill = "#808080",
variables = NULL,
orientation = c("vertical", "horizontal"),
mar = c(2, 2, 2, 0.5),
...
)
x |
A |
vars |
Optional numeric or character vector. Used to subset the plot to
certain variables by position or name (must be available). Defaults to
|
col |
Character vector. Colour(s) of the lines delineating credible
intervals. Single values will be recycled if necessary. Recycled HEX color
codes are varied in transparency if not provided (e.g. "#737373FF"). Lines
can be bypassed by setting this to |
t_back |
Integer scalar. Number of observed datapoints to plot ahead of the forecast. |
area |
Logical scalar. Whether to fill the credible intervals using
|
fill |
Character vector. Colour(s) to fill the credible intervals with. See col for more information. |
variables |
Optional character vector. Names of all variables in the
object. Used to subset and title. Taken from |
orientation |
String indicating the orientation of the plots. Defaults
to |
mar |
Numeric vector. Margins for |
... |
Other graphical parameters for |
Returns x invisibly.
bvar
; predict.bvar
# 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)
# Store predictions ex-post
predict(x) <- predict(x)
# Plot forecasts for all available variables
plot(predict(x))
# Subset to variables in positions 1 and 3 via their name
plot(predict(x), vars = c("CPI", "FED"))
# Subset via position, increase the plotted forecast horizon and past data
plot(predict(x, horizon = 20), vars = c(1, 3), t_back = 10)
# Adjust confidence bands and the plot's orientation
plot(predict(x, conf_bands = 0.25), orientation = "h")
# Draw areas inbetween the confidence bands and skip drawing lines
plot(predict(x), col = "transparent", area = TRUE)
# Plot a conditional forecast (with a constrained second variable).
plot(predict(x, cond_path = c(1, 1, 1, 1, 1, 1), cond_var = 2))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.