Learn R Programming

bsts (version 0.6.1)

predict.bsts: Prediction for bayesian structural time series

Description

Generated draws from the posterior predictive distribution of a bsts object.

Usage

## S3 method for class 'bsts':
predict(object,
        newdata,
        horizon = 1,
        burn = SuggestBurn(.1, object),
        na.action = na.exclude,
        olddata,
        quantiles = c(.025, .975),
        ...)

Arguments

object
An object of class bsts created by a call to the function bsts.
newdata
a vector, matrix, or data frame containing the predictor variables to use in making the prediction. This is only required if object contains a regression compoent. If a data frame, it must include variables with the same names a
horizon
An integer specifying the number of periods into the future you wish to predict. If object contains a regression component then the forecast horizon is nrow(X), and this argument is not used.
burn
An integer describing the number of MCMC iterations in object to be discarded as burn-in. If burn <= 0<="" code=""> then no burn-in period will be discarded.
na.action
A function determining what should be done with missing values in newdata.
olddata
This is an optional component allowing predictions to be made conditional on data other than the data used to fit the model. If omitted, then it is assumed that forecasts are to be made relative to the final observation in the training data.
quantiles
A numeric vector of length 2 giving the lower and upper quantiles to use for the forecast interval estimate.
...
This is a dummy argument included to match the signature of the generic predict function. It is not used.

Value

  • Returns an object of class bsts.prediction, which is a list with the following components.
  • meanA vector giving the posterior mean of the prediction.
  • intervalA two (column/row?) matrix giving the upper and lower bounds of the 95 percent credible interval for the prediction.
  • distributionA matrix of draws from the posterior predictive distribution. Each row in the matrix is one MCMC draw. Columns represent time.

Details

Samples from the posterior distribution of a Bayesian structural time series model. This function can be used either with or without contemporaneous predictor variables (in a time series regression).

If predictor variables are present, the regression coefficients are fixed (as opposed to time varying, though time varying coefficients might be added as state component). The predictors and response in the formula are contemporaneous, so if you want lags and differences you need to put them in the predictor matrix yourself.

If no predictor variables are used, then the model is an ordinary state space time series model.

References

Harvey (1990), "Forecasting, structural time series, and the Kalman filter", Cambridge University Press.

Durbin and Koopman (2001), "Time series analysis by state space methods", Oxford University Press.

See Also

bsts. AddLocalLevel. AddLocalLinearTrend. AddGeneralizedLocalLinearTrend.

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)
  pred <- predict(model, horizon = 12, burn = 100)
  plot(pred)

Run the code above in your browser using DataLab