R: Plot predictions from Bayesian structural time series

plot.bsts.prediction {bsts} | R Documentation

## Plot predictions from Bayesian structural time series

### Description

Plot the posterior predictive distribution from a `bsts` prediction object.

### Usage

      ## S3 method for class 'bsts.prediction'
    plot(x,
         y = NULL,
         burn = 0,
         plot.original = TRUE,
         median.color = "blue",
         median.type = 1,
         median.width = 3,
         interval.quantiles = c(.025, .975),
         interval.color = "green",
         interval.type = 2,
         interval.width = 2,
         style = c("dynamic", "boxplot"),
         ylim = NULL,
         ...)

### Arguments

`x` | An object of class `bsts.prediction` created by calling `predict` on a `bsts` object.
`y` | A dummy argument necessary to match the signature of the `plot` generic function. This argument is unused.
`plot.original` | Logical or numeric. If `TRUE` then the prediction is plotted after a time series plot of the original series. If `FALSE`, the prediction fills the entire plot. If numeric, then it specifies the number of trailing observations of the original time series to plot in addition to the predictions.
`burn` | The number of observations you wish to discard as burn-in from the posterior predictive distribution. This is in addition to the burn-in discarded using `predict.bsts`.
`median.color` | The color to use for the posterior median of the prediction.
`median.type` | The type of line (lty) to use for the posterior median of the prediction.
`median.width` | The width of line (lwd) to use for the posterior median of the prediction.
`interval.quantiles` | The lower and upper limits of the credible interval to be plotted.
`interval.color` | The color to use for the upper and lower limits of the 95% credible interval for the prediction.
`interval.type` | The type of line (lty) to use for the upper and lower limits of the 95% credible inerval for of the prediction.
`interval.width` | The width of line (lwd) to use for the upper and lower limits of the 95% credible inerval for of the prediction.
`style` | Either "dynamic", for dynamic distribution plots, or "boxplot", for box plots. Partial matching is allowed, so "dyn" or "box" would work, for example.
`ylim` | Limits on the vertical axis.
`...` | Extra arguments to be passed to `PlotDynamicDistribution` and `lines`.

### Details

Plots the posterior predictive distribution described by `x` using a dynamic distribution plot generated by `PlotDynamicDistribution`. Overlays the posterior median and 95% prediction limits for the predictive distribution.

### Value

Returns NULL.

### See Also

`bsts` `PlotDynamicDistribution` `plot.lm.spike`

### Examples

      data(AirPassengers)
      y <- log(AirPassengers)
      ss <- AddLocalLinearTrend(list(), y)
      ss <- AddSeasonal(ss, y, nseasons = 12)
      model <- bsts(y, state.specification = ss, niter = 500)
      pred <- predict(model, horizon = 12, burn = 100)
      plot(pred)

[Package bsts version 0.9.6 Index]