Computes the one-step-ahead prediction errors for a
bsts.prediction.errors(bsts.object, cutpoints = NULL, burn = SuggestBurn(.1, bsts.object), standardize = FALSE)
An object of class
An increasing sequence of integers between 1 and the
number of time points in the trainig data for
An integer giving the number of MCMC iterations to discard
as burn-in. If
Returns the posterior distribution of the one-step-ahead prediction errors from the bsts.object. The errors are computing using the Kalman filter, and are of two types.
Purely in-sample errors are computed as a by-product of the Kalman
filter as a result of fitting the model. These are stored in the
bsts.object assuming the
save.prediction.errors option is TRUE,
which is the default (See
BstsOptions). The in-sample
errors are 'in-sample' in the sense that the parameter values used to
run the Kalman filter are drawn from their posterior distribution given
complete data. Conditional on the parameters in that MCMC iteration,
each 'error' is the difference between the observed y[t] and its
expectation given data to t-1.
Purely out-of-sample errors can be computed by specifying the 'cutpoints' argument. If cutpoints are supplied then a separate MCMC is run using just data up to the cutpoint. The Kalman filter is then run on the remaining data, again finding the difference between y[t] and its expectation given data to t-1, but conditional on parameters estimated using data up to the cutpoint.
A matrix of draws of the one-step-ahead prediction errors. Rows of the matrix correspond to MCMC draws. Columns correspond to time.
Steven L. Scott email@example.com
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.
data(AirPassengers) y <- log(AirPassengers) ss <- AddLocalLinearTrend(list(), y) ss <- AddSeasonal(ss, y, nseasons = 12) ## Not run: model <- bsts(y, state.specification = ss, niter = 500) ## End(Not run) errors <- bsts.prediction.errors(model, burn = 100) PlotDynamicDistribution(errors$in.sample) ## Compute out of sample prediction errors beyond times 80 and 120. errors <- bsts.prediction.errors(model, cutpoints = c(80, 120)) standardized.errors <- bsts.prediction.errors( model, cutpoints = c(80, 120), standardize = TRUE) plot(model, "prediction.errors", cutpoints = c(80, 120)) str(errors) ## three matrices, with 400 ( = 500 - 100) rows ## and length(y) columns
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.