Description Usage Arguments Details Engine Details Fit Details See Also Examples
View source: R/parsnipseasonal_reg.R
seasonal_reg()
is a way to generate a specification of an
Seasonal Decomposition model
before fitting and allows the model to be created using
different packages. Currently the only package is forecast
.
1 2 3 4 5 6  seasonal_reg(
mode = "regression",
seasonal_period_1 = NULL,
seasonal_period_2 = NULL,
seasonal_period_3 = NULL
)

mode 
A single character string for the type of model. The only possible value for this model is "regression". 
seasonal_period_1 
(required) The primary seasonal frequency.
Uses 
seasonal_period_2 
(optional) A second seasonal frequency.
Is 
seasonal_period_3 
(optional) A third seasonal frequency.
Is 
The data given to the function are not saved and are only used
to determine the mode of the model. For seasonal_reg()
, the
mode will always be "regression".
The model can be created using the fit()
function using the
following engines:
"tbats"  Connects to forecast::tbats()
"stlm_ets"  Connects to forecast::stlm()
, method = "ets"
"stlm_arima"  Connects to forecast::stlm()
, method = "arima"
The standardized parameter names in modeltime
can be mapped to their original
names in each engine:
modeltime  forecast::stlm  forecast::tbats 
seasonal_period_1, seasonal_period_2, seasonal_period_3  msts(seasonal.periods)  msts(seasonal.periods) 
Other options can be set using set_engine()
.
The engines use forecast::stlm()
.
Function Parameters:
1 2 3 4  ## function (y, s.window = 7 + 4 * seq(6), robust = FALSE, method = c("ets",
## "arima"), modelfunction = NULL, model = NULL, etsmodel = "ZZN", lambda = NULL,
## biasadj = FALSE, xreg = NULL, allow.multiplicative.trend = FALSE, x = y,
## ...)

tbats
Method: Uses method = "tbats"
, which by default is autoTBATS.
Xregs: Univariate. Cannot accept Exogenous Regressors (xregs). Xregs are ignored.
stlm_ets
Method: Uses method = "stlm_ets"
, which by default is autoETS.
Xregs: Univariate. Cannot accept Exogenous Regressors (xregs). Xregs are ignored.
stlm_arima
Method: Uses method = "stlm_arima"
, which by default is autoARIMA.
Xregs: Multivariate. Can accept Exogenous Regressors (xregs).
Date and DateTime Variable
It's a requirement to have a date or datetime variable as a predictor.
The fit()
interface accepts date and datetime features and handles them internally.
fit(y ~ date)
Seasonal Period Specification
The period can be nonseasonal (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 timebased 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 datetime feature. Simply use:
Formula Interface (recommended): fit(y ~ date)
will ignore xreg's.
XY Interface: fit_xy(x = data[,"date"], y = data$y)
will ignore xreg's.
Multivariate (xregs, Exogenous Regressors)
The tbats
engine cannot accept Xregs.
The stlm_ets
engine cannot accept Xregs.
The stlm_arima
engine can accept Xregs
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 Datetime 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 seasonal_reg()
using
fit()
:
fit(y ~ date + month.lbl)
will pass month.lbl
on as an exogenous regressor.
fit_xy(data[,c("date", "month.lbl")], y = data$y)
will pass x, where x is a data frame containing month.lbl
and the date
feature. Only month.lbl
will be used as an exogenous regressor.
Note that date or datetime class values are excluded from xreg
.
fit.model_spec()
, set_engine()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34  library(dplyr)
library(parsnip)
library(rsample)
library(timetk)
library(modeltime)
# Data
taylor_30_min
# Split Data 80/20
splits < initial_time_split(taylor_30_min, prop = 0.8)
#  STLM ETS 
# Model Spec
model_spec < seasonal_reg() %>%
set_engine("stlm_ets")
# Fit Spec
model_fit < model_spec %>%
fit(log(value) ~ date, data = training(splits))
model_fit
#  STLM ARIMA 
# Model Spec
model_spec < seasonal_reg() %>%
set_engine("stlm_arima")
# Fit Spec
model_fit < model_spec %>%
fit(log(value) ~ date, data = training(splits))
model_fit

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.