Fable
Fable
Fable
1
2 R topics documented:
R topics documented:
ARIMA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
common_xregs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
components.ETS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
ETS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
fitted.ARIMA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
fitted.ETS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
fitted.model_mean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
fitted.NNETAR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
fitted.RW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
fitted.TSLM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
fitted.VAR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
forecast.ARIMA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
forecast.ETS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
forecast.model_mean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
forecast.NNETAR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
forecast.RW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
forecast.TSLM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
forecast.VAR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
generate.ETS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
generate.model_mean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
generate.NNETAR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
generate.RW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
generate.TSLM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
glance.ARIMA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
glance.ETS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
glance.model_mean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
glance.NNETAR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
glance.RW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
glance.TSLM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
glance.VAR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
interpolate.ARIMA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
interpolate.TSLM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
MEAN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
NNETAR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
refit.ARIMA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
refit.ETS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
refit.TSLM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
residuals.ARIMA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
residuals.ETS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
residuals.model_mean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
residuals.NNETAR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
residuals.RW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
residuals.TSLM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
residuals.VAR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
RW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
tidy.ARIMA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
ARIMA 3
tidy.ETS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
tidy.model_mean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
tidy.NNETAR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
tidy.RW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
tidy.TSLM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
tidy.VAR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
TSLM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
unitroot_options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
VAR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Index 49
Description
Searches through the model space specified in the specials to identify the best ARIMA model which
has lowest AIC, AICc or BIC value. It is implemented using stats::arima() and allows ARIMA
models to be used in the fable framework.
Usage
ARIMA(formula, ic = c("aicc", "aic", "bic"), stepwise = TRUE,
greedy = TRUE, approximation = NULL, order_constraint = p + q + P +
Q <= 6, unitroot_spec = unitroot_options(), ...)
Arguments
formula Model specification (see "Specials" section).
ic The information criterion used in selecting the model.
stepwise Should stepwise be used?
greedy Should the stepwise search move to the next best option immediately?
approximation Should CSS (conditional sum of squares) be used during model selection? The
default (NULL) will use the approximation if there are more than 150 observations
or if the seasonal period is greater than 12.
order_constraint
A logical predicate on the orders of p, d, q, P, D and Q to consider in the search.
unitroot_spec A specification of unit root tests to use in the selection of d and D. See unitroot_options()
for more details.
... Further arguments for stats::arima()
Value
A model specification.
4 ARIMA
Specials
pdq: The pdq special is used to specify non-seasonal components of the model.
pdq(p = 0:5, d = 0:2, q = 0:5,
p_init = 2, q_init = 2)
p The order of the non-seasonal auto-regressive (AR) terms. If multiple values are provided, the one which minimises
d The order of integration for non-seasonal differencing. If multiple values are provided, one of the values will be sele
q The order of the non-seasonal moving average (MA) terms. If multiple values are provided, the one which minimise
p_init If stepwise = TRUE, p_init provides the initial value for p for the stepwise search procedure.
q_init If stepwise = TRUE, q_init provides the initial value for q for the stepwise search procedure.
PDQ: The PDQ special is used to specify seasonal components of the model.
PDQ(P = 0:2, D = 0:1, Q = 0:2, period = NULL,
P_init = 1, Q_init = 1)
P The order of the seasonal auto-regressive (SAR) terms. If multiple values are provided, the one which minimises ic
D The order of integration for seasonal differencing. If multiple values are provided, one of the values will be selected
Q The order of the seasonal moving average (SMA) terms. If multiple values are provided, the one which minimises i
period The periodic nature of the seasonality. This can be either a number indicating the number of observations in each sea
P_init If stepwise = TRUE, P_init provides the initial value for P for the stepwise search procedure.
Q_init If stepwise = TRUE, Q_init provides the initial value for Q for the stepwise search procedure.
xreg: Exogenous regressors can be included in an ARIMA model without explicitly using the
xreg() special. Common exogenous regressor specials as specified in common_xregs can also be
used. These regressors are handled using stats::model.frame(), and so interactions and other
functionality behaves similarly to stats::lm().
The inclusion of a constant in the model follows the similar rules to stats::lm(), where includ-
ing 1 will add a constant and 0 or -1 will remove the constant. If left out, the inclusion of a
constant will be determined by minimising ic.
xreg(...)
See Also
Forecasting: Principles and Practices, ARIMA models (chapter 9) Forecasting: Principles and Prac-
tices, Dynamic regression models (chapter 10)
Examples
# Manual ARIMA specification
USAccDeaths %>%
as_tsibble %>%
model(arima = ARIMA(log(value) ~ pdq(0,1,1) + PDQ(0,1,1)))
library(tsibble)
library(dplyr)
tsibbledata::global_economy %>%
filter(Country == "Australia") %>%
model(ARIMA(log(GDP) ~ Population))
Description
These special functions provide interfaces to more complicated functions within the model formulae
interface.
Usage
common_xregs
Specials
trend: The trend special includes common linear trend regressors in the model. It also supports
piecewise linear trend via the knots argument.
trend(knots = NULL, origin = NULL)
knots A vector of times (same class as the data’s time index) identifying the position of knots for a piecewise linear trend.
origin An optional time value to act as the starting time for the trend.
season: The season special includes seasonal dummy variables in the model.
season(period = NULL)
period The periodic nature of the seasonality. This can be either a number indicating the number of observations in each sea
fourier: The fourier special includes seasonal fourier terms in the model. The maximum order
of the fourier terms must be specified using K.
fourier(period = NULL, K, origin = NULL)
period The periodic nature of the seasonality. This can be either a number indicating the number of observations in each sea
K The maximum order of the fourier terms.
origin An optional time value to act as the starting time for the fourier series.
Description
Extract estimated states from an ETS model.
Usage
## S3 method for class 'ETS'
components(object, ...)
Arguments
object An estimated model.
... Unused.
Value
A fabletools::dable() containing estimated states.
Examples
as_tsibble(USAccDeaths) %>%
model(ets = ETS(log(value) ~ season("A"))) %>%
components()
Description
Returns ETS model specified by the formula.
Usage
ETS(formula, opt_crit = c("lik", "amse", "mse", "sigma", "mae"),
nmse = 3, bounds = c("both", "usual", "admissible"), ic = c("aicc",
"aic", "bic"), restrict = TRUE, ...)
Arguments
formula Model specification (see "Specials" section).
opt_crit The optimization criterion. Defaults to the log-likelihood "lik", but can also
be set to "mse" (Mean Square Error), "amse" (Average MSE over first nmse
forecast horizons), "sigma" (Standard deviation of residuals), or "mae" (Mean
Absolute Error).
nmse If opt_crit == "amse", nmse provides the number of steps for average multi-
step MSE (1<=nmse<=30).
ETS 7
bounds Type of parameter space to impose: "usual" indicates all parameters must lie
between specified lower and upper bounds; "admissible" indicates parameters
must lie in the admissible space; "both" (default) takes the intersection of these
regions.
ic The information criterion used in selecting the model.
restrict If TRUE (default), the models with infinite variance will not be allowed.
... Other arguments
Details
Based on the classification of methods as described in Hyndman et al (2008).
The methodology is fully automatic. The model is chosen automatically if not specified. This
methodology performed extremely well on the M3-competition data. (See Hyndman, et al, 2002,
below.)
Value
A model specification.
Specials
error: The error special is used to specify the form of the error term.
error(method = c("A", "M"))
method The form of the error term: either additive ("A") or multiplicative ("M").
trend: The trend special is used to specify the form of the trend term and associated parameters.
trend(method = c("N", "A", "Ad"),
alpha = NULL, alpha_range = c(1e-04, 0.9999),
beta = NULL, beta_range = c(1e-04, 0.9999),
phi = NULL, phi_range = c(0.8, 0.98))
method The form of the trend term: either none ("N"), additive ("A"), multiplicative ("M") or damped variants ("Ad",
alpha The value of the smoothing parameter for the level. If alpha = 0, the level will not change over time. Convers
alpha_range If alpha=NULL, alpha_range provides bounds for the optimised value of alpha.
beta The value of the smoothing parameter for the slope. If beta = 0, the slope will not change over time. Convers
beta_range If beta=NULL, beta_range provides bounds for the optimised value of beta.
phi The value of the dampening parameter for the slope. If phi = 0, the slope will be dampened immediately (no s
phi_range If phi=NULL, phi_range provides bounds for the optimised value of phi.
season: The season special is used to specify the form of the seasonal term and associated
parameters.
season(method = c("N", "A", "M"), period = NULL,
gamma = NULL, gamma_range = c(1e-04, 0.9999))
method The form of the seasonal term: either none ("N"), additive ("A") or multiplicative ("M").
8 fitted.ARIMA
period The periodic nature of the seasonality. This can be either a number indicating the number of observations in e
gamma The value of the smoothing parameter for the seasonal pattern. If gamma = 0, the seasonal pattern will not chan
gamma_range If gamma=NULL, gamma_range provides bounds for the optimised value of gamma.
References
Hyndman, R.J., Koehler, A.B., Snyder, R.D., and Grose, S. (2002) "A state space framework for
automatic forecasting using exponential smoothing methods", International J. Forecasting, 18(3),
439–454.
Hyndman, R.J., Akram, Md., and Archibald, B. (2008) "The admissible parameter space for expo-
nential smoothing models". Annals of Statistical Mathematics, 60(2), 407–426.
Hyndman, R.J., Koehler, A.B., Ord, J.K., and Snyder, R.D. (2008) Forecasting with exponential
smoothing: the state space approach, Springer-Verlag. http://www.exponentialsmoothing.
net.
See Also
Forecasting: Principles and Practices, Exponential smoothing (chapter 8)
Examples
as_tsibble(USAccDeaths) %>%
model(ETS(log(value) ~ season("A")))
Description
Extracts the fitted values.
Usage
## S3 method for class 'ARIMA'
fitted(object, ...)
Arguments
object The time series model used to produce the forecasts
... Additional arguments for forecast model methods.
Value
A vector of fitted values.
fitted.ETS 9
Examples
USAccDeaths %>%
as_tsibble %>%
model(arima = ARIMA(log(value) ~ pdq(0,1,1) + PDQ(0,1,1))) %>%
fitted()
Description
Extracts the fitted values.
Usage
## S3 method for class 'ETS'
fitted(object, ...)
Arguments
object The time series model used to produce the forecasts
... Additional arguments for forecast model methods.
Value
A vector of fitted values.
Examples
as_tsibble(USAccDeaths) %>%
model(ets = ETS(log(value) ~ season("A"))) %>%
fitted()
Description
Extracts the fitted values.
Usage
## S3 method for class 'model_mean'
fitted(object, ...)
10 fitted.NNETAR
Arguments
object The time series model used to produce the forecasts
... Additional arguments for forecast model methods.
Value
A vector of fitted values.
Examples
library(tsibbledata)
vic_elec %>%
model(avg = MEAN(Demand)) %>%
fitted()
Description
Extracts the fitted values.
Usage
## S3 method for class 'NNETAR'
fitted(object, ...)
Arguments
object The time series model used to produce the forecasts
... Additional arguments for forecast model methods.
Value
A vector of fitted values.
Examples
as_tsibble(airmiles) %>%
model(nn = NNETAR(box_cox(value, 0.15))) %>%
fitted()
fitted.RW 11
Description
Extracts the fitted values.
Usage
## S3 method for class 'RW'
fitted(object, ...)
Arguments
object The time series model used to produce the forecasts
... Additional arguments for forecast model methods.
Value
A vector of fitted values.
Examples
as_tsibble(Nile) %>%
model(NAIVE(value)) %>%
fitted()
library(tsibbledata)
aus_production %>%
model(snaive = SNAIVE(Beer ~ lag("year"))) %>%
fitted()
Description
Extracts the fitted values.
Usage
## S3 method for class 'TSLM'
fitted(object, ...)
12 fitted.VAR
Arguments
object The time series model used to produce the forecasts
... Additional arguments for forecast model methods.
Value
A vector of fitted values.
Examples
as_tsibble(USAccDeaths) %>%
model(lm = TSLM(log(value) ~ trend() + season())) %>%
fitted()
Description
Extracts the fitted values.
Usage
## S3 method for class 'VAR'
fitted(object, ...)
Arguments
object The time series model used to produce the forecasts
... Additional arguments for forecast model methods.
Value
A vector of fitted values.
Examples
lung_deaths <- cbind(mdeaths, fdeaths) %>%
as_tsibble(pivot_longer = FALSE)
lung_deaths %>%
model(VAR(vars(log(mdeaths), fdeaths) ~ AR(3))) %>%
fitted()
forecast.ARIMA 13
Description
Usage
Arguments
Value
A list of forecasts.
Examples
USAccDeaths %>%
as_tsibble %>%
model(arima = ARIMA(log(value) ~ pdq(0,1,1) + PDQ(0,1,1))) %>%
forecast()
14 forecast.ETS
Description
Usage
Arguments
Value
A list of forecasts.
Examples
as_tsibble(USAccDeaths) %>%
model(ets = ETS(log(value) ~ season("A"))) %>%
forecast()
forecast.model_mean 15
Description
Usage
Arguments
Value
A list of forecasts.
Examples
library(tsibbledata)
vic_elec %>%
model(avg = MEAN(Demand)) %>%
forecast()
16 forecast.NNETAR
Description
Usage
Arguments
Value
A list of forecasts.
Examples
as_tsibble(airmiles) %>%
model(nn = NNETAR(box_cox(value, 0.15))) %>%
forecast(times = 10)
forecast.RW 17
Description
Usage
Arguments
Value
A list of forecasts.
Examples
as_tsibble(Nile) %>%
model(NAIVE(value)) %>%
forecast()
library(tsibbledata)
aus_production %>%
model(snaive = SNAIVE(Beer ~ lag("year"))) %>%
forecast()
18 forecast.VAR
Description
Produces forecasts from a trained model.
Usage
## S3 method for class 'TSLM'
forecast(object, new_data, specials = NULL,
bootstrap = FALSE, times = 5000, ...)
Arguments
object The time series model used to produce the forecasts
new_data A tsibble containing future information used to forecast.
specials (passed by fabletools::forecast.mdl_df()).
bootstrap If TRUE, then forecast distributions are computed using simulation with resam-
pled errors.
times The number of sample paths to use in estimating the forecast distribution when
boostrap = TRUE.
... Additional arguments for forecast model methods.
Value
A list of forecasts.
Examples
as_tsibble(USAccDeaths) %>%
model(lm = TSLM(log(value) ~ trend() + season())) %>%
forecast()
Description
Produces forecasts from a trained model.
generate.ETS 19
Usage
## S3 method for class 'VAR'
forecast(object, new_data = NULL, specials = NULL,
bootstrap = FALSE, times = 5000, ...)
Arguments
object The time series model used to produce the forecasts
new_data A tsibble containing future information used to forecast.
specials (passed by fabletools::forecast.mdl_df()).
bootstrap If TRUE, then forecast distributions are computed using simulation with resam-
pled errors.
times The number of sample paths to use in estimating the forecast distribution when
boostrap = TRUE.
... Additional arguments for forecast model methods.
Value
A list of forecasts.
Examples
lung_deaths <- cbind(mdeaths, fdeaths) %>%
as_tsibble(pivot_longer = FALSE)
lung_deaths %>%
model(VAR(vars(log(mdeaths), fdeaths) ~ AR(3))) %>%
forecast()
Description
Simulates future paths from a dataset using a fitted model. Innovations are sampled by the model’s
assumed error distribution. If bootstrap is TRUE, innovations will be sampled from the model’s
residuals. If new_data contains the .innov column, those values will be treated as innovations.
Usage
## S3 method for class 'ETS'
generate(x, new_data, specials, bootstrap = FALSE, ...)
20 generate.model_mean
Arguments
x A fitted model.
new_data A tsibble containing future information used to forecast.
specials (passed by fabletools::forecast.mdl_df()).
bootstrap If TRUE, then forecast distributions are computed using simulation with resam-
pled errors.
... Additional arguments for forecast model methods.
See Also
fabletools::generate.mdl_df
Examples
as_tsibble(USAccDeaths) %>%
model(ETS(log(value) ~ season("A"))) %>%
generate(times = 100)
Description
Simulates future paths from a dataset using a fitted model. Innovations are sampled by the model’s
assumed error distribution. If bootstrap is TRUE, innovations will be sampled from the model’s
residuals. If new_data contains the .innov column, those values will be treated as innovations.
Usage
## S3 method for class 'model_mean'
generate(x, new_data, bootstrap = FALSE, ...)
Arguments
x A fitted model.
new_data A tsibble containing future information used to forecast.
bootstrap If TRUE, then forecast distributions are computed using simulation with resam-
pled errors.
... Additional arguments for forecast model methods.
See Also
fabletools::generate.mdl_df
generate.NNETAR 21
Examples
library(tsibbledata)
vic_elec %>%
model(avg = MEAN(Demand)) %>%
generate()
Description
Simulates future paths from a dataset using a fitted model. Innovations are sampled by the model’s
assumed error distribution. If bootstrap is TRUE, innovations will be sampled from the model’s
residuals. If new_data contains the .innov column, those values will be treated as innovations.
Usage
## S3 method for class 'NNETAR'
generate(x, new_data, specials = NULL,
bootstrap = FALSE, ...)
Arguments
x A fitted model.
new_data A tsibble containing future information used to forecast.
specials (passed by fabletools::forecast.mdl_df()).
bootstrap If TRUE, then forecast distributions are computed using simulation with resam-
pled errors.
... Additional arguments for forecast model methods.
See Also
fabletools::generate.mdl_df
Examples
as_tsibble(airmiles) %>%
model(nn = NNETAR(box_cox(value, 0.15))) %>%
generate()
22 generate.RW
Description
Simulates future paths from a dataset using a fitted model. Innovations are sampled by the model’s
assumed error distribution. If bootstrap is TRUE, innovations will be sampled from the model’s
residuals. If new_data contains the .innov column, those values will be treated as innovations.
Usage
Arguments
x A fitted model.
new_data A tsibble containing future information used to forecast.
bootstrap If TRUE, then forecast distributions are computed using simulation with resam-
pled errors.
... Additional arguments for forecast model methods.
See Also
fabletools::generate.mdl_df
Examples
as_tsibble(Nile) %>%
model(NAIVE(value)) %>%
generate()
library(tsibbledata)
aus_production %>%
model(snaive = SNAIVE(Beer ~ lag("year"))) %>%
generate()
generate.TSLM 23
Description
Simulates future paths from a dataset using a fitted model. Innovations are sampled by the model’s
assumed error distribution. If bootstrap is TRUE, innovations will be sampled from the model’s
residuals. If new_data contains the .innov column, those values will be treated as innovations.
Usage
## S3 method for class 'TSLM'
generate(x, new_data, specials, bootstrap = FALSE, ...)
Arguments
x A fitted model.
new_data A tsibble containing future information used to forecast.
specials (passed by fabletools::forecast.mdl_df()).
bootstrap If TRUE, then forecast distributions are computed using simulation with resam-
pled errors.
... Additional arguments for forecast model methods.
See Also
fabletools::generate.mdl_df
Examples
as_tsibble(USAccDeaths) %>%
model(lm = TSLM(log(value) ~ trend() + season())) %>%
generate()
Description
Construct a single row summary of the ARIMA model.
Usage
## S3 method for class 'ARIMA'
glance(x, ...)
24 glance.ETS
Arguments
x model or other R object to convert to single-row data frame
... other arguments passed to methods
Details
Contains the variance of residuals (sigma2), the log-likelihood (log_lik), information criterion
(AIC, AICc, BIC) and the characteristic roots (ar_roots and ma_roots).
Value
A one row tibble summarising the model’s fit.
Examples
USAccDeaths %>%
as_tsibble %>%
model(arima = ARIMA(log(value) ~ pdq(0,1,1) + PDQ(0,1,1))) %>%
glance()
Description
Construct a single row summary of the ETS model.
Usage
## S3 method for class 'ETS'
glance(x, ...)
Arguments
x model or other R object to convert to single-row data frame
... other arguments passed to methods
Details
Contains the variance of residuals (sigma2), the log-likelihood (log_lik), and information criterion
(AIC, AICc, BIC).
Value
A one row tibble summarising the model’s fit.
glance.model_mean 25
Examples
as_tsibble(USAccDeaths) %>%
model(ets = ETS(log(value) ~ season("A"))) %>%
glance()
Description
Usage
Arguments
Details
Value
Examples
library(tsibbledata)
vic_elec %>%
model(avg = MEAN(Demand)) %>%
glance()
26 glance.RW
Description
Construct a single row summary of the NNETAR model. Contains the variance of residuals (sigma2).
Usage
## S3 method for class 'NNETAR'
glance(x, ...)
Arguments
x model or other R object to convert to single-row data frame
... other arguments passed to methods
Value
A one row tibble summarising the model’s fit.
Examples
as_tsibble(airmiles) %>%
model(nn = NNETAR(box_cox(value, 0.15))) %>%
glance()
Description
Construct a single row summary of the lag walk model. Contains the variance of residuals (sigma2).
Usage
## S3 method for class 'RW'
glance(x, ...)
Arguments
x model or other R object to convert to single-row data frame
... other arguments passed to methods
glance.TSLM 27
Value
A one row tibble summarising the model’s fit.
Examples
as_tsibble(Nile) %>%
model(NAIVE(value)) %>%
glance()
library(tsibbledata)
aus_production %>%
model(snaive = SNAIVE(Beer ~ lag("year"))) %>%
glance()
Description
Construct a single row summary of the TSLM model.
Usage
## S3 method for class 'TSLM'
glance(x, ...)
Arguments
x model or other R object to convert to single-row data frame
... other arguments passed to methods
Details
Contains the R squared (r_squared), variance of residuals (sigma2), the log-likelihood (log_lik),
and information criterion (AIC, AICc, BIC).
Value
A one row tibble summarising the model’s fit.
Examples
as_tsibble(USAccDeaths) %>%
model(lm = TSLM(log(value) ~ trend() + season())) %>%
glance()
28 interpolate.ARIMA
Description
Construct a single row summary of the VAR model.
Usage
## S3 method for class 'VAR'
glance(x, ...)
Arguments
x model or other R object to convert to single-row data frame
... other arguments passed to methods
Details
Contains the variance of residuals (sigma2), the log-likelihood (log_lik), and information criterion
(AIC, AICc, BIC).
Value
A one row tibble summarising the model’s fit.
Examples
lung_deaths <- cbind(mdeaths, fdeaths) %>%
as_tsibble(pivot_longer = FALSE)
lung_deaths %>%
model(VAR(vars(log(mdeaths), fdeaths) ~ AR(3))) %>%
glance()
Description
Applies a model specific estimation technique to predict the values of missing values in a tsibble,
and replace them.
interpolate.TSLM 29
Usage
## S3 method for class 'ARIMA'
interpolate(object, new_data, specials, ...)
Arguments
object The time series model used to produce the forecasts
new_data A tsibble containing future information used to forecast.
specials (passed by fabletools::forecast.mdl_df()).
... Additional arguments for forecast model methods.
Value
A tibble of the same dimension of new_data with missing values interpolated.
Examples
library(tsibbledata)
olympic_running %>%
model(arima = ARIMA(Time ~ trend())) %>%
interpolate(olympic_running)
Description
Applies a model specific estimation technique to predict the values of missing values in a tsibble,
and replace them.
Usage
## S3 method for class 'TSLM'
interpolate(object, new_data, specials, ...)
Arguments
object The time series model used to produce the forecasts
new_data A tsibble containing future information used to forecast.
specials (passed by fabletools::forecast.mdl_df()).
... Additional arguments for forecast model methods.
Value
A tibble of the same dimension of new_data with missing values interpolated.
30 MEAN
Examples
library(tsibbledata)
olympic_running %>%
model(lm = TSLM(Time ~ trend())) %>%
interpolate(olympic_running)
Description
MEAN() returns an iid model applied to the formula’s response variable.
Usage
MEAN(formula, ...)
Arguments
formula Model specification.
... Not used.
Details
The model does not use any specials, and so everything on the formula’s right-hand-side will be
ignored.
Value
A model specification.
Specials
This model does not support usage of any specials. It only computes the mean!
See Also
Forecasting: Principles and Practices, Some simple forecasting methods (section 3.2)
Examples
library(tsibbledata)
vic_elec %>%
model(avg = MEAN(Demand))
NNETAR 31
Description
Feed-forward neural networks with a single hidden layer and lagged inputs for forecasting univariate
time series.
Usage
Arguments
Details
A feed-forward neural network is fitted with lagged values of the response as inputs and a single
hidden layer with size nodes. The inputs are for lags 1 to p, and lags m to mP where m is the seasonal
period specified.
If exogenous regressors are provided, its columns are also used as inputs. Missing values are cur-
rently not supported by this model. A total of repeats networks are fitted, each with random
starting weights. These are then averaged when computing forecasts. The network is trained for
one-step forecasting. Multi-step forecasts are computed recursively.
For non-seasonal data, the fitted model is denoted as an NNAR(p,k) model, where k is the num-
ber of hidden nodes. This is analogous to an AR(p) model but with non-linear functions. For
seasonal data, the fitted model is called an NNAR(p,P,k)[m] model, which is analogous to an
ARIMA(p,0,0)(P,0,0)[m] model but with non-linear functions.
Value
A model specification.
32 refit.ARIMA
Specials
AR: The AR special is used to specify auto-regressive components in each of the nodes of the
neural network.
AR(p = NULL, P = 1, period = NULL)
p The order of the non-seasonal auto-regressive (AR) terms. If p = NULL, an optimal number of lags will be selected fo
P The order of the seasonal auto-regressive (SAR) terms.
period The periodic nature of the seasonality. This can be either a number indicating the number of observations in each sea
xreg: Exogenous regressors can be included in an NNETAR model without explicitly using the
xreg() special. Common exogenous regressor specials as specified in common_xregs can also be
used. These regressors are handled using stats::model.frame(), and so interactions and other
functionality behaves similarly to stats::lm().
xreg(...)
See Also
Forecasting: Principles and Practices, Neural network models (section 11.3)
Examples
as_tsibble(airmiles) %>%
model(nn = NNETAR(box_cox(value, 0.15)))
Description
Applies a fitted ARIMA model to a new dataset.
Usage
## S3 method for class 'ARIMA'
refit(object, new_data, specials = NULL,
reestimate = FALSE, ...)
Arguments
object The time series model used to produce the forecasts
new_data A tsibble containing future information used to forecast.
specials (passed by fabletools::forecast.mdl_df()).
refit.ETS 33
reestimate If TRUE, the coefficients for the fitted model will be re-estimated to suit the new
data.
... Additional arguments for forecast model methods.
Value
A refitted model.
Examples
lung_deaths_male <- as_tsibble(mdeaths)
lung_deaths_female <- as_tsibble(fdeaths)
report(fit)
fit %>%
refit(lung_deaths_female) %>%
report()
Description
Applies a fitted ETS model to a new dataset.
Usage
## S3 method for class 'ETS'
refit(object, new_data, specials = NULL,
reestimate = FALSE, reinitialise = TRUE, ...)
Arguments
object The time series model used to produce the forecasts
new_data A tsibble containing future information used to forecast.
specials (passed by fabletools::forecast.mdl_df()).
reestimate If TRUE, the coefficients for the fitted model will be re-estimated to suit the new
data.
reinitialise If TRUE, the initial parameters will be re-estimated to suit the new data.
... Additional arguments for forecast model methods.
34 refit.TSLM
Examples
lung_deaths_male <- as_tsibble(mdeaths)
lung_deaths_female <- as_tsibble(fdeaths)
report(fit)
fit %>%
refit(lung_deaths_female, reinitialise = TRUE) %>%
report()
Description
Applies a fitted TSLM to a new dataset.
Usage
## S3 method for class 'TSLM'
refit(object, new_data, specials = NULL,
reestimate = FALSE, ...)
Arguments
object The time series model used to produce the forecasts
new_data A tsibble containing future information used to forecast.
specials (passed by fabletools::forecast.mdl_df()).
reestimate If TRUE, the coefficients for the fitted model will be re-estimated to suit the new
data.
... Additional arguments for forecast model methods.
Examples
lung_deaths_male <- as_tsibble(mdeaths)
lung_deaths_female <- as_tsibble(fdeaths)
report(fit)
fit %>%
residuals.ARIMA 35
refit(lung_deaths_female) %>%
report()
Description
Extracts the residuals.
Usage
## S3 method for class 'ARIMA'
residuals(object, type = c("innovation", "regression"),
...)
Arguments
object The time series model used to produce the forecasts
type The type of the residuals to extract.
... Additional arguments for forecast model methods.
Value
A vector of fitted residuals.
Examples
USAccDeaths %>%
as_tsibble %>%
model(arima = ARIMA(log(value) ~ pdq(0,1,1) + PDQ(0,1,1))) %>%
residuals()
Description
Extracts the residuals.
Usage
## S3 method for class 'ETS'
residuals(object, ...)
36 residuals.model_mean
Arguments
object The time series model used to produce the forecasts
... Additional arguments for forecast model methods.
Value
A vector of fitted residuals.
Examples
as_tsibble(USAccDeaths) %>%
model(ets = ETS(log(value) ~ season("A"))) %>%
residuals()
Description
Extracts the residuals.
Usage
## S3 method for class 'model_mean'
residuals(object, ...)
Arguments
object The time series model used to produce the forecasts
... Additional arguments for forecast model methods.
Value
A vector of fitted residuals.
Examples
library(tsibbledata)
vic_elec %>%
model(avg = MEAN(Demand)) %>%
residuals()
residuals.NNETAR 37
Description
Extracts the residuals.
Usage
## S3 method for class 'NNETAR'
residuals(object, ...)
Arguments
object The time series model used to produce the forecasts
... Additional arguments for forecast model methods.
Value
A vector of fitted residuals.
Examples
as_tsibble(airmiles) %>%
model(nn = NNETAR(box_cox(value, 0.15))) %>%
residuals()
Description
Extracts the residuals.
Usage
## S3 method for class 'RW'
residuals(object, ...)
Arguments
object The time series model used to produce the forecasts
... Additional arguments for forecast model methods.
38 residuals.TSLM
Value
Examples
as_tsibble(Nile) %>%
model(NAIVE(value)) %>%
residuals()
library(tsibbledata)
aus_production %>%
model(snaive = SNAIVE(Beer ~ lag("year"))) %>%
residuals()
Description
Usage
Arguments
Value
Examples
as_tsibble(USAccDeaths) %>%
model(lm = TSLM(log(value) ~ trend() + season())) %>%
residuals()
residuals.VAR 39
Description
Extracts the residuals.
Usage
## S3 method for class 'VAR'
residuals(object, ...)
Arguments
object The time series model used to produce the forecasts
... Additional arguments for forecast model methods.
Value
A vector of fitted residuals.
Examples
lung_deaths <- cbind(mdeaths, fdeaths) %>%
as_tsibble(pivot_longer = FALSE)
lung_deaths %>%
model(VAR(vars(log(mdeaths), fdeaths) ~ AR(3))) %>%
residuals()
Description
RW() returns a random walk model, which is equivalent to an ARIMA(0,1,0) model with an optional
drift coefficient included using drift(). naive() is simply a wrapper to rwf() for simplicity.
snaive() returns forecasts and prediction intervals from an ARIMA(0,0,0)(0,1,0)m model where
m is the seasonal period.
Usage
RW(formula, ...)
NAIVE(formula, ...)
SNAIVE(formula, ...)
40 RW
Arguments
formula Model specification (see "Specials" section).
... Not used.
Details
The random walk with drift model is
Yt = c + Yt−1 + Zt
Yn (h) = ch + Yn
. If there is no drift (as in naive), the drift parameter c=0. Forecast standard errors allow for
uncertainty in estimating the drift parameter (unlike the corresponding forecasts obtained by fitting
an ARIMA model directly).
The seasonal naive model is
Yt = Yt−m + Zt
where Zt is a normal iid error.
Value
A model specification.
Specials
lag: The lag special is used to specify the lag order for the random walk process. If left out, this
special will automatically be included.
lag(lag = NULL)
lag The lag order for the random walk process. If lag = m, forecasts will return the observation from m time periods ago. Thi
drift: The drift special can be used to include a drift/trend component into the model. By
default, drift is not included unless drift() is included in the formula.
drift(drift = TRUE)
See Also
Forecasting: Principles and Practices, Some simple forecasting methods (section 3.2)
Examples
library(tsibbledata)
tidy.ARIMA 41
aus_production %>%
model(rw = RW(Beer ~ drift()))
as_tsibble(Nile) %>%
model(NAIVE(value))
library(tsibbledata)
aus_production %>%
model(snaive = SNAIVE(Beer ~ lag("year")))
Description
Usage
Arguments
Value
Examples
USAccDeaths %>%
as_tsibble %>%
model(arima = ARIMA(log(value) ~ pdq(0,1,1) + PDQ(0,1,1))) %>%
tidy()
42 tidy.model_mean
Description
Returns the coefficients from the model in a tibble format.
Usage
## S3 method for class 'ETS'
tidy(x, ...)
Arguments
x An object to be converted into a tidy tibble::tibble().
... Additional arguments to tidying method.
Value
The model’s coefficients in a tibble.
Examples
as_tsibble(USAccDeaths) %>%
model(ets = ETS(log(value) ~ season("A"))) %>%
tidy()
Description
Returns the coefficients from the model in a tibble format.
Usage
## S3 method for class 'model_mean'
tidy(x, ...)
Arguments
x An object to be converted into a tidy tibble::tibble().
... Additional arguments to tidying method.
tidy.NNETAR 43
Value
Examples
library(tsibbledata)
vic_elec %>%
model(avg = MEAN(Demand)) %>%
tidy()
Description
Usage
Arguments
Value
Examples
as_tsibble(airmiles) %>%
model(nn = NNETAR(box_cox(value, 0.15))) %>%
tidy()
44 tidy.TSLM
Description
Returns the coefficients from the model in a tibble format.
Usage
## S3 method for class 'RW'
tidy(x, ...)
Arguments
x An object to be converted into a tidy tibble::tibble().
... Additional arguments to tidying method.
Value
The model’s coefficients in a tibble.
Examples
as_tsibble(Nile) %>%
model(NAIVE(value)) %>%
tidy()
library(tsibbledata)
aus_production %>%
model(snaive = SNAIVE(Beer ~ lag("year"))) %>%
tidy()
Description
Returns the coefficients from the model in a tibble format.
Usage
## S3 method for class 'TSLM'
tidy(x, ...)
tidy.VAR 45
Arguments
x An object to be converted into a tidy tibble::tibble().
... Additional arguments to tidying method.
Value
The model’s coefficients in a tibble.
Examples
as_tsibble(USAccDeaths) %>%
model(lm = TSLM(log(value) ~ trend() + season())) %>%
tidy()
Description
Returns the coefficients from the model in a tibble format.
Usage
## S3 method for class 'VAR'
tidy(x)
Arguments
x An object to be converted into a tidy tibble::tibble().
Value
The model’s coefficients in a tibble.
Examples
lung_deaths <- cbind(mdeaths, fdeaths) %>%
as_tsibble(pivot_longer = FALSE)
lung_deaths %>%
model(VAR(vars(log(mdeaths), fdeaths) ~ AR(3))) %>%
tidy()
46 TSLM
Description
The model formula will be handled using stats::model.matrix(), and so the the same ap-
proach to include interactions in stats::lm() applies when specifying the formula. In addition
to stats::lm(), it is possible to include common_xregs in the model formula, such as trend(),
season(), and fourier().
Usage
TSLM(formula)
Arguments
formula Model specification.
Value
A model specification.
Specials
xreg: Exogenous regressors can be included in an ARIMA model without explicitly using the
xreg() special. Common exogenous regressor specials as specified in common_xregs can also be
used. These regressors are handled using stats::model.frame(), and so interactions and other
functionality behaves similarly to stats::lm().
xreg(...)
See Also
stats::lm(), stats::model.matrix() Forecasting: Principles and Practices, Time series regres-
sion models (chapter 6)
Examples
as_tsibble(USAccDeaths) %>%
model(lm = TSLM(log(value) ~ trend() + season()))
library(tsibbledata)
olympic_running %>%
model(TSLM(Time ~ trend())) %>%
interpolate(olympic_running)
unitroot_options 47
unitroot_options Options for the unit root tests for order of integration
Description
Options for the unit root tests for order of integration
Usage
unitroot_options(ndiffs_alpha = 0.05, nsdiffs_alpha = 0.05,
ndiffs_pvalue = ~feasts::unitroot_kpss(.)["kpss_pvalue"],
nsdiffs_pvalue = ~feasts::feat_stl(., .period)[2] < 0.64)
Arguments
ndiffs_alpha, nsdiffs_alpha
The level for the test specified in the pval functions As long as pval < alpha,
differences will be added.
ndiffs_pvalue, nsdiffs_pvalue
A function (or lambda expression) which returns the probability of the . As long
as pval < alpha, differences will be added.
For the function for the seasonal p-value, the seasonal period will be provided
as the .period argument to this function. A vector of data to test is available as
. or .x.
Value
A list of parameters
Description
Searches through the vector of lag orders to find the best VAR model which has lowest AIC, AICc
or BIC value. It is implemented using OLS per equation.
Usage
VAR(formula, ic = c("aicc", "aic", "bic"), ...)
Arguments
formula Model specification (see "Specials" section).
ic The information criterion used in selecting the model.
... Further arguments for arima
48 VAR
Details
Exogenous regressors and common_xregs can be specified in the model formula.
Value
A model specification.
Specials
pdq: The AR special is used to specify the lag order for the auto-regression.
AR(p = 0:5)
p The order of the auto-regressive (AR) terms. If multiple values are provided, the one which minimises ic will be chosen.
xreg: Exogenous regressors can be included in an ARIMA model without explicitly using the
xreg() special. Common exogenous regressor specials as specified in common_xregs can also be
used. These regressors are handled using stats::model.frame(), and so interactions and other
functionality behaves similarly to stats::lm().
The inclusion of a constant in the model follows the similar rules to stats::lm(), where includ-
ing 1 will add a constant and 0 or -1 will remove the constant. If left out, the inclusion of a
constant will be determined by minimising ic.
xreg(...)
See Also
Forecasting: Principles and Practices, Vector autoregressions (section 11.2)
Examples
report(fit)
fit %>%
forecast() %>%
autoplot(lung_deaths)
Index
ARIMA, 3 MEAN, 30
49
50 INDEX
tidy.VAR, 45
TSLM, 46
unitroot_options, 47
unitroot_options(), 3
VAR, 47