sarima_reg()
is a way to generate a specification of an ARIMA model
before fitting and allows the model to be created using
different packages. Currently the only package is bayesforecast
.
sarima_reg( mode = "regression", seasonal_period = NULL, non_seasonal_ar = NULL, non_seasonal_differences = NULL, non_seasonal_ma = NULL, seasonal_ar = NULL, seasonal_differences = NULL, seasonal_ma = NULL, markov_chains = NULL, chain_iter = NULL, warmup_iter = NULL, adapt_delta = NULL, tree_depth = NULL, pred_seed = NULL )
mode | A single character string for the type of model. The only possible value for this model is "regression". |
---|---|
seasonal_period | A seasonal frequency. Uses "auto" by default. A character phrase of "auto" or time-based phrase of "2 weeks" can be used if a date or date-time variable is provided. See Fit Details below. |
non_seasonal_ar | The order of the non-seasonal auto-regressive (AR) terms. Often denoted "p" in pdq-notation. |
non_seasonal_differences | The order of integration for non-seasonal differencing. Often denoted "d" in pdq-notation. |
non_seasonal_ma | The order of the non-seasonal moving average (MA) terms. Often denoted "q" in pdq-notation. |
seasonal_ar | The order of the seasonal auto-regressive (SAR) terms. Often denoted "P" in PDQ-notation. |
seasonal_differences | The order of integration for seasonal differencing. Often denoted "D" in PDQ-notation. |
seasonal_ma | The order of the seasonal moving average (SMA) terms. Often denoted "Q" in PDQ-notation. |
markov_chains | An integer of the number of Markov Chains chains to be run, by default 4 chains are run. |
chain_iter | An integer of total iterations per chain including the warm-up, by default the number of iterations are 2000. |
warmup_iter | A positive integer specifying number of warm-up (aka burn-in) iterations. This also specifies the number of iterations used for step-size adaptation, so warm-up samples should not be used for inference. The number of warmup should not be larger than iter and the default is iter/2. |
adapt_delta | An optional real value between 0 and 1, the thin of the jumps in a HMC method. By default is 0.9 |
tree_depth | An integer of the maximum depth of the trees evaluated during each iteration. By default is 10. |
pred_seed | An integer with the seed for using when predicting with the model. |
A model spec
The data given to the function are not saved and are only used
to determine the mode of the model. For sarima_reg()
, the
mode will always be "regression".
The model can be created using the fit()
function using the
following engines:
"stan" (default) - Connects to bayesforecast::stan_sarima()
Main Arguments
The main arguments (tuning parameters) for the model are:
non_seasonal_ar
: The order of the non-seasonal auto-regressive (AR) terms.
non_seasonal_differences
: The order of integration for non-seasonal differencing.
non_seasonal_ma
: The order of the non-seasonal moving average (MA) terms.
seasonal_ar
: The order of the seasonal auto-regressive (SAR) terms.
seasonal_differences
: The order of integration for seasonal differencing.
seasonal_ma
: The order of the seasonal moving average (SMA) terms.
markov_chains
: An integer of the number of Markov Chains chains to be run.
adapt_delta
: The thin of the jumps in a HMC method.
tree_depth
: The maximum depth of the trees evaluated during each iteration
These arguments are converted to their specific names at the time that the model is fit.
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.
The standardized parameter names in bayesmodels
can be mapped to their original
names in the engine:
bayesmodels | bayesforecast::stan_sarima |
non_seasonal_ar, non_seasonal_differences, non_seasonal_ma | order = c(p(1), d(0), q(0)) |
seasonal_ar, seasonal_differences, seasonal_ma | seasonal = c(P(0), D(0), Q(0)) |
markov_chains | chains(4) |
adapt_delta | adapt.delta(0.9) |
tree_depth | tree.depth(10) |
Other options can be set using set_engine()
.
stan (default engine)
The engine uses bayesforecast::stan_sarima()
.
Parameter Notes:
xreg
- This is supplied via the parsnip / bayesmodels fit()
interface
(so don't provide this manually). See Fit Details (below).
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.
Seasonal Period Specification
The period can be non-seasonal (seasonal_period = 1 or "none"
) or
yearly seasonal (e.g. For monthly time stamps, seasonal_period = 12
, seasonal_period = "12 months"
, or seasonal_period = "yearly"
).
There are 3 ways to specify:
seasonal_period = "auto"
: A seasonal period is selected based on the periodicity of the data (e.g. 12 if monthly)
seasonal_period = 12
: A numeric frequency. For example, 12 is common for monthly data
seasonal_period = "1 year"
: A time-based phrase. For example, "1 year" would convert to 12 for monthly data.
Univariate (No xregs, Exogenous Regressors):
For univariate analysis, you must include a date or date-time feature. Simply use:
Formula Interface: fit(y ~ date)
will ignore xreg's.
Multivariate (xregs, Exogenous Regressors)
The xreg
parameter is populated using the fit()
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:
y
(target)
date
(time stamp),
month.lbl
(labeled month as a ordered factor).
The month.lbl
is an exogenous regressor that can be passed to the sarima_reg()
using
fit()
:
fit(y ~ date + month.lbl)
will pass month.lbl
on as an exogenous regressor.
Note that date or date-time class values are excluded from xreg
.
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 <- rsample::initial_time_split(m750, prop = 0.8) # ---- ARIMA ---- # Model Spec model_spec <- sarima_reg() %>% set_engine("stan") # Fit Spec model_fit <- model_spec %>% fit(log(value) ~ date, data = training(splits)) model_fit # Model Spec model_spec <- sarima_reg( seasonal_period = 12, non_seasonal_ar = 3, non_seasonal_differences = 1, non_seasonal_ma = 3, seasonal_ar = 1, seasonal_differences = 0, seasonal_ma = 1 ) %>% set_engine("stan") # Fit Spec model_fit <- model_spec %>% fit(log(value) ~ date, data = training(splits)) model_fit }