Learn R Programming

bayesforecast (version 1.0.1)

predictive_error.varstan: Out-of-sample predictive errors

Description

This is a convenience function for computing \(y - y_{h}\) The method for stanreg objects calls posterior_predict internally, where as the method accepts the data.frame returned by posterior_predict as input and can be used to avoid multiple calls to posterior_predict.

Usage

# S3 method for varstan
predictive_error(
  object,
  newdata = NULL,
  xreg = NULL,
  draws = 1000,
  seed = NULL,
  ...
)

Arguments

object

Either a fitted model object returned by one of the rstanarm modeling functions (a stanreg object) or, for the "ppd" method, a matrix of draws from the posterior predictive distribution returned by posterior_predict.

newdata

An array with the newdata vector.

xreg

Optional, a numerical matrix of external regressors, which must have the same number of rows as ts. It should not be a data frame.

draws, seed

Optional arguments passed to posterior_predict. Please see the Note section below if newdata will be specified.

...

Further arguments passed to predictive_error.

Value

A draws by nrow(newdata) data.frame.

See Also

posterior_predict function from rstanarm package, to draw from the posterior predictive distribution without computing predictive errors.