Learn R Programming

bsts (version 0.6.1)

plot.bsts: Plotting functions for Bayesian structural time series

Description

Functions to plot the results of a model fit using bsts.

Usage

## S3 method for class 'bsts':
plot(x, y = c("state", "components", "residuals",
              "coefficients", "prediction.errors",
              "forecast.distribution",
              "predictors", "size", "dynamic"),
      ...)

PlotBstsCoefficients(bsts.object, burn = SuggestBurn(.1, bsts.object), inclusion.threshold = 0, number.of.variables = NULL, ...) PlotBstsComponents(bsts.object, burn = SuggestBurn(.1, bsts.object), time, same.scale = TRUE, layout = c("square", "horizontal", "vertical"), style = c("dynamic", "boxplot"), ylim = NULL, ...) PlotDynamicRegression(bsts.object, burn = SuggestBurn(.1, bsts.object), time = NULL, style = c("dynamic", "boxplot"), layout = c("square", "horizontal", "vertical"), ...) PlotBstsState(bsts.object, burn = SuggestBurn(.1, bsts.object), time, show.actuals = TRUE, style = c("dynamic", "boxplot"), ...) PlotBstsResiduals(bsts.object, burn = SuggestBurn(.1, bsts.object), time, style = c("dynamic", "boxplot"), ...) PlotBstsPredictionErrors(bsts.object, burn = SuggestBurn(.1, bsts.object), time, style = c("dynamic", "boxplot"), ...) PlotBstsSize(bsts.object, burn = SuggestBurn(.1, bsts.object), style = c("histogram", "ts"), ...)

Arguments

x
An object of class bsts.
bsts.object
An object of class bsts.
y
A character string indicating the aspect of the model that should be plotted.
burn
The number of MCMC iterations to discard as burn-in.
time
An optional vector of values to plot against. If missing, the default is to diagnose the time scale of the original time series.
same.scale
Logical. If TRUE then all the state components will be plotted with the same scale on the vertical axis. If FALSE then each component will get its own scale for the vertical axis.
show.actuals
Logical. If TRUE then actual values from the fitted series will be shown on the plot.
style
The desired plot style. Partial matching is allowed, so "dyn" would match "dynamic", for example.
layout
For controlling the layout of functions that generate mutiple plots.
inclusion.threshold
A inclusion probability that individual coefficients must exceed in order to be displayed when what == "coefficients". See the help file for plot.lm.spike.
number.of.variables
If non-NULL this specifies the number of coefficients to plot, taking precedence over inclusion.threshold. See plot.lm.spike.
ylim
Limits for the vertical axis. If NULL these will be inferred from the state components and the same.scale argument. Otherwise all plots will be created with the same ylim values.
...
Additional arguments to be passed to PlotDynamicDistribution

Value

  • These functions are called for their side effect, which is to produce a plot on the current graphics device.

Details

PlotBstsState, PlotBstsComponents, and PlotBstsResiduals all produce dynamic distribution plots. PlotBstsState plots the aggregate state contribution (including regression effects) to the mean, while PlotBstsComponents plots the contribution of each state component. PlotBstsResiduals plots the posterior distribution of the residuals given complete data (i.e. looking forward and backward in time). PlotBstsPredictionErrors plots filtering errors (i.e. the one-step-ahead prediction errors given data up to the previous time point). PlotBstsForecastDistribution plots the one-step-ahead forecasts instead of the prediction errors.

PlotBstsCoefficients creates a significance plot for the predictors used in the state space regression model. It is obviously not useful for models with no regressors.

PlotBstsSize plots the distribution of the number of predictors included in the model.

See Also

bsts PlotDynamicDistribution plot.lm.spike

Examples

Run this code
data(AirPassengers)
  y <- log(AirPassengers)
  ss <- AddLocalLinearTrend(list(), y)
  ss <- AddSeasonal(ss, y, nseasons = 12)
  model <- bsts(y, state.specification = ss, niter = 500)
  plot(model, burn = 100)
  plot(model, "residuals", burn = 100)
  plot(model, "components", burn = 100)
  plot(model, "forecast.distribution", burn = 100)

Run the code above in your browser using DataLab