model {fabletools} | R Documentation |
Estimate models
Description
Trains specified model definition(s) to a dataset. This function will
estimate the a set of model definitions (passed via ...
) to each series
within .data
(as identified by the key structure). The result will be a
mable (a model table), which neatly stores the estimated models in a tabular
structure. Rows of the data identify different series within the data, and
each model column contains all models from that model definition. Each cell
in the mable identifies a single model.
Usage
model(.data, ...)
## S3 method for class 'tbl_ts'
model(.data, ..., .safely = TRUE)
Arguments
.data |
A data structure suitable for the models (such as a |
... |
Definitions for the models to be used. All models must share the same response variable. |
.safely |
If a model encounters an error, rather than aborting the process a NULL model will be returned instead. This allows for an error to occur when computing many models, without losing the results of the successful models. |
Parallel
It is possible to estimate models in parallel using the
future package. By specifying a
future::plan()
before estimating the models, they will be computed
according to that plan.
Progress
Progress on model estimation can be obtained by wrapping the code with
progressr::with_progress()
. Further customisation on how progress is
reported can be controlled using the progressr
package.
Examples
library(fable)
library(tsibbledata)
# Training an ETS(M,Ad,A) model to Australian beer production
aus_production %>%
model(ets = ETS(log(Beer) ~ error("M") + trend("Ad") + season("A")))
# Training a seasonal naive and ETS(A,A,A) model to the monthly
# "Food retailing" turnover for selected Australian states.
library(dplyr)
progressr::with_progress(
aus_retail %>%
filter(
Industry == "Food retailing",
State %in% c("Victoria", "New South Wales", "Queensland")
) %>%
model(
snaive = SNAIVE(Turnover),
ets = ETS(log(Turnover) ~ error("A") + trend("A") + season("A")),
)
)