bayesian_structural_reg() is a way to generate a specification of a Bayesian Structural Time Series Model before fitting and allows the model to be created using different packages. Currently the only package is bsts.

bayesian_structural_reg(mode = "regression", distribution = NULL)

Arguments

mode

A single character string for the type of model. The only possible value for this model is "regression".

distribution

The model family for the observation equation. Non-Gaussian model families use data augmentation to recover a conditionally Gaussian model.

Value

A model spec

Details

The data given to the function are not saved and are only used to determine the mode of the model. For bayesian_structural_reg(), the mode will always be "regression".

The model can be created using the fit() function using the following engines:

Main Arguments

Other options and argument can be set using set_engine() (See Engine Details below).

If parameters need to be modified, update() can be used in lieu of recreating the object from scratch.

stan (default engine)

The engine uses bsts::bsts().

Parameter Notes:

  • xreg - This is supplied via the parsnip / modeltime fit() interface (so don't provide this manually). See Fit Details (below).

Fit Details

Date and Date-Time Variable

It's a requirement to have a date or date-time variable as a predictor. The fit() interface accepts date and date-time features and handles them internally.

Univariate (No xregs, Exogenous Regressors):

For univariate analysis, you must include a date or date-time feature. Simply use:

  • Formula Interface (recommended): fit(y ~ date) will ignore xreg's.

Multivariate (xregs, Exogenous Regressors)

The xreg parameter is populated using the fit() or fit_xy() function:

  • Only factor, ordered factor, and numeric data will be used as xregs.

  • Date and Date-time variables are not used as xregs

  • character data should be converted to factor.

Xreg Example: Suppose you have 3 features:

  1. y (target)

  2. date (time stamp),

  3. month.lbl (labeled month as a ordered factor).

The month.lbl is an exogenous regressor that can be passed to the arima_reg() using fit():

Note that date or date-time class values are excluded from xreg.

See also

Examples

if (FALSE) { library(dplyr) library(parsnip) library(rsample) library(timetk) library(modeltime) library(bayesmodels) # Data m750 <- m4_monthly %>% filter(id == "M750") m750 # Split Data 80/20 splits <- initial_time_split(m750, prop = 0.8) ss <- AddLocalLinearTrend(list(), training(splits)$value) # Model Spec model_spec <- bayesian_structural_reg() %>% set_engine("stan", state.specification = ss) # Fit Spec model_fit <- model_spec %>% fit(log(value) ~ date, data = training(splits)) model_fit predict(model_fit, testing(splits)) }