| Title: | Forecasting Models for Tidy Time Series |
| Version: | 0.4.1 |
| Description: | Provides a collection of commonly used univariate and multivariate time series forecasting models including automatically selected exponential smoothing (ETS) and autoregressive integrated moving average (ARIMA) models. These models work within the 'fable' framework provided by the 'fabletools' package, which provides the tools to evaluate, visualise, and combine models in a workflow consistent with the tidyverse. |
| License: | GPL-3 |
| URL: | https://fable.tidyverts.org,https://github.com/tidyverts/fable |
| BugReports: | https://github.com/tidyverts/fable/issues |
| Depends: | R (≥ 3.4.0), fabletools (≥ 0.3.0) |
| Imports: | Rcpp (≥ 0.11.0), rlang (≥ 0.4.6), stats, dplyr (≥ 1.0.0),tsibble (≥ 0.9.0), tibble, tidyr, utils, distributional |
| Suggests: | covr, feasts, forecast, knitr, MTS, nnet, rmarkdown,spelling, testthat, tsibbledata (≥ 0.2.0) |
| LinkingTo: | Rcpp (≥ 0.11.0) |
| VignetteBuilder: | knitr |
| ByteCompile: | true |
| Encoding: | UTF-8 |
| Language: | en-GB |
| RoxygenNote: | 7.3.2 |
| NeedsCompilation: | yes |
| Packaged: | 2024-11-05 00:24:01 UTC; mitchell |
| Author: | Mitchell O'Hara-Wild [aut, cre], Rob Hyndman [aut], Earo Wang [aut], Gabriel Caceres [ctb] (NNETAR implementation), Christoph Bergmeir |
| Maintainer: | Mitchell O'Hara-Wild <mail@mitchelloharawild.com> |
| Repository: | CRAN |
| Date/Publication: | 2024-11-05 03:20:07 UTC |
fable: Forecasting Models for Tidy Time Series
Description

Provides a collection of commonly used univariate and multivariate time series forecasting models including automatically selected exponential smoothing (ETS) and autoregressive integrated moving average (ARIMA) models. These models work within the 'fable' framework provided by the 'fabletools' package, which provides the tools to evaluate, visualise, and combine models in a workflow consistent with the tidyverse.
Author(s)
Maintainer: Mitchell O'Hara-Wildmail@mitchelloharawild.com
Authors:
Rob Hyndman
Earo Wang
Other contributors:
Gabriel Caceres (NNETAR implementation) [contributor]
Christoph Bergmeir (ORCID) [contributor]
Tim-Gunnar Hensel [contributor]
Timothy Hyndman [contributor]
See Also
Useful links:
Report bugs athttps://github.com/tidyverts/fable/issues
Estimate a AR model
Description
Searches through the vector of lag orders to find the best AR model whichhas lowest AIC, AICc or BIC value. It is implemented using OLS, and behavescomparably tostats::ar.ols().
Usage
AR(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 |
Details
Exogenous regressors andcommon_xregs can be specified in the modelformula.
Value
A model specification.
Specials
pdq
Theorder special is used to specify the lag order for the auto-regression.
order(p = 0:15, fixed = list())
p | The order of the auto-regressive (AR) terms. If multiple values are provided, the one which minimisesic will be chosen. |
fixed | A named list of fixed parameters for coefficients. The names identify the coefficient, beginning withar, and then followed by the lag order. For example,fixed = list(ar1 = 0.3, ar3 = 0). |
xreg
Exogenous regressors can be included in an AR model without explicitly using thexreg() special. Common exogenous regressor specials as specified incommon_xregs can also be used. These regressors are handled usingstats::model.frame(), and so interactions and other functionality behaves similarly tostats::lm().
The inclusion of a constant in the model follows the similar rules tostats::lm(), where including1 will add a constant and0 or-1 will remove the constant. If left out, the inclusion of a constant will be determined by minimisingic.
xreg(..., fixed = list())
... | Bare expressions for the exogenous regressors (such aslog(x)) |
fixed | A named list of fixed parameters for coefficients. The names identify the coefficient, and should match the name of the regressor. For example,fixed = list(constant = 20). |
See Also
Forecasting: Principles and Practices, Vector autoregressions (section 11.2)
Examples
luteinizing_hormones <- as_tsibble(lh)fit <- luteinizing_hormones %>% model(AR(value ~ order(3)))report(fit)fit %>% forecast() %>% autoplot(luteinizing_hormones)Estimate an ARIMA model
Description
Searches through the model space specified in the specials to identify thebest ARIMA model, with the lowest AIC, AICc or BIC value. It is implementedusingstats::arima() and allows ARIMA models to be used in the fableframework.
Usage
ARIMA( formula, ic = c("aicc", "aic", "bic"), selection_metric = function(x) x[[ic]], stepwise = TRUE, greedy = TRUE, approximation = NULL, order_constraint = p + q + P + Q <= 6 & (constant + d + D <= 2), unitroot_spec = unitroot_options(), trace = FALSE, ...)Arguments
formula | Model specification (see "Specials" section). |
ic | The information criterion used in selecting the model. |
selection_metric | A function used to compute a metric from an |
stepwise | Should stepwise be used? (Stepwise can be much faster) |
greedy | Should the stepwise search move to the next best option immediately? |
approximation | Should CSS (conditional sum of squares) be used during modelselection? The default ( |
order_constraint | A logical predicate on the orders of |
unitroot_spec | A specification of unit root tests to use in theselection of |
trace | If |
... | Further arguments for |
Value
A model specification.
Parameterisation
The fableARIMA() function uses an alternative parameterisation ofconstants tostats::arima() andforecast::Arima(). While theparameterisations are equivalent, the coefficients for the constant/meanwill differ.
Infable, if there are no exogenous regressors, the parameterisation usedis:
(1-\phi_1B - \cdots - \phi_p B^p)(1-B)^d y_t = c + (1 + \theta_1 B + \cdots + \theta_q B^q)\varepsilon_t
In stats and forecast, an ARIMA model is parameterised as:
(1-\phi_1B - \cdots - \phi_p B^p)(y_t' - \mu) = (1 + \theta_1 B + \cdots + \theta_q B^q)\varepsilon_t
where\mu is the mean of(1-B)^d y_t andc = \mu(1-\phi_1 - \cdots - \phi_p ).
If there are exogenous regressors,fable uses the same parameterisation asused in stats and forecast. That is, it fits a regression with ARIMA(p,d,q)errors:
y_t = c + \beta' x_t + z_t
where\beta is a vector of regression coefficients,x_t isa vector of exogenous regressors at timet, andz_t is anARIMA(p,d,q) error process:
(1-\phi_1B - \cdots - \phi_p B^p)(1-B)^d z_t = (1 + \theta_1 B + \cdots + \theta_q B^q)\varepsilon_t
For details of the estimation algorithm, see thearima function in the stats package.
Specials
Thespecials define the space over whichARIMA will search for the model that best fits the data. If the RHS offormula is left blank, the default search space is given bypdq() + PDQ(): that is, a model with candidate seasonal and nonseasonal terms, but no exogenous regressors. Note that a seasonal model requires at least 2 full seasons of data; if this is not available,ARIMA will revert to a nonseasonal model with a warning.
To specify a model fully (avoid automatic selection), the intercept andpdq()/PDQ() values must be specified. For example,formula = response ~ 1 + pdq(1, 1, 1) + PDQ(1, 0, 0).
pdq
Thepdq 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, fixed = list())
p | The order of the non-seasonal auto-regressive (AR) terms. If multiple values are provided, the one which minimisesic will be chosen. |
d | The order of integration for non-seasonal differencing. If multiple values are provided, one of the values will be selected via repeated KPSS tests. |
q | The order of the non-seasonal moving average (MA) terms. If multiple values are provided, the one which minimisesic will be chosen. |
p_init | Ifstepwise = TRUE,p_init provides the initial value forp for the stepwise search procedure. |
q_init | Ifstepwise = TRUE,q_init provides the initial value forq for the stepwise search procedure. |
fixed | A named list of fixed parameters for coefficients. The names identify the coefficient, beginning with eitherar orma, followed by the lag order. For example,fixed = list(ar1 = 0.3, ma2 = 0). |
PDQ
ThePDQ special is used to specify seasonal components of the model. To force a non-seasonal fit, specifyPDQ(0, 0, 0) in the RHS of the model formula. Note that simply omittingPDQ from the formula willnot result in a non-seasonal fit.
PDQ(P = 0:2, D = 0:1, Q = 0:2, period = NULL, P_init = 1, Q_init = 1, fixed = list())
P | The order of the seasonal auto-regressive (SAR) terms. If multiple values are provided, the one which minimisesic will be chosen. |
D | The order of integration for seasonal differencing. If multiple values are provided, one of the values will be selected via repeated heuristic tests (based on strength of seasonality from an STL decomposition). |
Q | The order of the seasonal moving average (SMA) terms. If multiple values are provided, the one which minimisesic will be chosen. |
period | The periodic nature of the seasonality. This can be either a number indicating the number of observations in each seasonal period, or text to indicate the duration of the seasonal window (for example, annual seasonality would be "1 year"). |
P_init | Ifstepwise = TRUE,P_init provides the initial value forP for the stepwise search procedure. |
Q_init | Ifstepwise = TRUE,Q_init provides the initial value forQ for the stepwise search procedure. |
fixed | A named list of fixed parameters for coefficients. The names identify the coefficient, beginning with eithersar orsma, followed by the lag order. For example,fixed = list(sar1 = 0.1). |
xreg
Exogenous regressors can be included in an ARIMA model without explicitly using thexreg() special. Common exogenous regressor specials as specified incommon_xregs can also be used. These regressors are handled usingstats::model.frame(), and so interactions and other functionality behaves similarly tostats::lm().
The inclusion of a constant in the model follows the similar rules tostats::lm(), where including1 will add a constant and0 or-1 will remove the constant. If left out, the inclusion of a constant will be determined by minimisingic.
xreg(..., fixed = list())
... | Bare expressions for the exogenous regressors (such aslog(x)) |
fixed | A named list of fixed parameters for coefficients. The names identify the coefficient, and should match the name of the regressor. For example,fixed = list(constant = 20). |
See Also
Forecasting: Principles and Practices, ARIMA models (chapter 9)Forecasting: Principles and Practices, Dynamic regression models (chapter 10)
Examples
# Manual ARIMA specificationUSAccDeaths %>% as_tsibble() %>% model(arima = ARIMA(log(value) ~ 0 + pdq(0, 1, 1) + PDQ(0, 1, 1))) %>% report()# Automatic ARIMA specificationlibrary(tsibble)library(dplyr)tsibbledata::global_economy %>% filter(Country == "Australia") %>% model(ARIMA(log(GDP) ~ Population))Croston's method
Description
Based on Croston's (1972) method for intermittent demand forecasting, also described in Shenstone and Hyndman (2005). Croston's method involves using simple exponential smoothing (SES) on the non-zero elements of the time series and a separate application of SES to the times between non-zero elements of the time series.
Usage
CROSTON( formula, opt_crit = c("mse", "mae"), type = c("croston", "sba", "sbj"), ...)Arguments
formula | Model specification (see "Specials" section). |
opt_crit | The optimisation criterion used to optimise the parameters. |
type | Which variant of Croston's method to use. Defaults to |
... | Not used. |
Details
Note that forecast distributions are not computed as Croston's method has nounderlying stochastic model. In a later update, we plan to support distributions viathe equivalent stochastic models that underly Croston's method (Shenstone andHyndman, 2005)
There are two variant methods available which apply multiplicative correction factorsto the forecasts that result from the original Croston's method. For theSyntetos-Boylan approximation (type = "sba"), this factor is1 - \alpha / 2,and for the Shale-Boylan-Johnston method (type = "sbj"), this factor is1 - \alpha / (2 - \alpha), where\alpha is the smoothing parameter forthe interval SES application.
Value
A model specification.
Specials
demand
Thedemand special specifies parameters for the demand SES application.
demand(initial = NULL, param = NULL, param_range = c(0, 1))
initial | The initial value for the demand application of SES. |
param | The smoothing parameter for the demand application of SES. |
param_range | Ifparam = NULL, the range of values over which to search for the smoothing parameter. |
interval
Theinterval special specifies parameters for the interval SES application.
interval(initial = NULL, param = NULL, param_range = c(0, 1))
initial | The initial value for the interval application of SES. |
param | The smoothing parameter for the interval application of SES. |
param_range | Ifparam = NULL, the range of values over which to search for the smoothing parameter. |
References
Croston, J. (1972) "Forecasting and stock control forintermittent demands",Operational Research Quarterly,23(3),289-303.
Shenstone, L., and Hyndman, R.J. (2005) "Stochastic models underlyingCroston's method for intermittent demand forecasting".Journal ofForecasting,24, 389-402.
Kourentzes, N. (2014) "On intermittent demand model optimisation andselection".International Journal of Production Economics,156,180-190.doi:10.1016/j.ijpe.2014.06.007.
Examples
library(tsibble)sim_poisson <- tsibble( time = yearmonth("2012 Dec") + seq_len(24), count = rpois(24, lambda = 0.3), index = time)sim_poisson %>% autoplot(count)sim_poisson %>% model(CROSTON(count)) %>% forecast(h = "2 years") %>% autoplot(sim_poisson)Exponential smoothing state space model
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 |
nmse | If |
bounds | Type of parameter space to impose: |
ic | The information criterion used in selecting the model. |
restrict | If TRUE (default), the models with infinite variance will notbe allowed. These restricted model components are AMM, AAM, AMA, and MMA. |
... | 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 notspecified. This methodology performed extremely well on the M3-competitiondata. (See Hyndman, et al, 2002, below.)
Value
A model specification.
Specials
Thespecials define the methods and parameters for the components (error, trend, and seasonality) of an ETS model. If more than one method is specified,ETS will consider all combinations of the specified models and select the model which best fits the data (minimisingic). The method argument for each specials have reasonable defaults, so if a component is not specified an appropriate method will be chosen automatically.
There are a couple of limitations to note about ETS models:
It does not support exogenous regressors.
It does not support missing values. You can complete missing values in the data with imputed values (e.g. with
tidyr::fill(), or by fitting a different model type and then callingfabletools::interpolate()) before fitting the model.
error
Theerror 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"). If the error is multiplicative, the data must be non-negative. All specified methods are tested on the data, and the one that gives the best fit (lowestic) will be kept. |
trend
Thetrend 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", "Md"). All specified methods are tested on the data, and the one that gives the best fit (lowestic) will be kept. |
alpha | The value of the smoothing parameter for the level. Ifalpha = 0, the level will not change over time. Conversely, ifalpha = 1 the level will update similarly to a random walk process. |
alpha_range | Ifalpha=NULL,alpha_range provides bounds for the optimised value ofalpha. |
beta | The value of the smoothing parameter for the slope. Ifbeta = 0, the slope will not change over time. Conversely, ifbeta = 1 the slope will have no memory of past slopes. |
beta_range | Ifbeta=NULL,beta_range provides bounds for the optimised value ofbeta. |
phi | The value of the dampening parameter for the slope. Ifphi = 0, the slope will be dampened immediately (no slope). Conversely, ifphi = 1 the slope will not be dampened. |
phi_range | Ifphi=NULL,phi_range provides bounds for the optimised value ofphi. |
season
Theseason special is used to specify the form of the seasonal term and associated parameters. To specify a nonseasonal model you would includeseason(method = "N").
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"). All specified methods are tested on the data, and the one that gives the best fit (lowestic) will be kept. |
period | The periodic nature of the seasonality. This can be either a number indicating the number of observations in each seasonal period, or text to indicate the duration of the seasonal window (for example, annual seasonality would be "1 year"). |
gamma | The value of the smoothing parameter for the seasonal pattern. Ifgamma = 0, the seasonal pattern will not change over time. Conversely, ifgamma = 1 the seasonality will have no memory of past seasonal periods. |
gamma_range | Ifgamma=NULL,gamma_range provides bounds for the optimised value ofgamma. |
References
Hyndman, R.J., Koehler, A.B., Snyder, R.D., and Grose, S. (2002)"A state space framework for automatic forecasting using exponentialsmoothing methods",International J. Forecasting,18(3),439–454.
Hyndman, R.J., Akram, Md., and Archibald, B. (2008) "The admissibleparameter space for exponential smoothing models".Annals ofStatistical 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")))Calculate impulse responses from a fable model
Description
Calculate impulse responses from a fable model
Usage
## S3 method for class 'ARIMA'IRF(x, new_data, specials, ...)Arguments
x | A fitted model. |
new_data | A tsibble containing the time points and exogenous regressors to produce forecasts for. |
specials | (passed by |
... | Other arguments passed to methods |
Calculate impulse responses from a fable model
Description
Simulates future paths from a dataset using a fitted model. Innovations aresampled by the model's assumed error distribution. Ifbootstrap isTRUE,innovations will be sampled from the model's residuals. Ifnew_datacontains the.innov column, those values will be treated as innovations.
Usage
## S3 method for class 'VAR'IRF(x, new_data, specials, impulse = NULL, orthogonal = FALSE, ...)Arguments
x | A fitted model. |
new_data | A tsibble containing the time points and exogenous regressors to produce forecasts for. |
specials | (passed by |
impulse | A character string specifying the name of the variable that is shocked (the impulse variable). |
orthogonal | If TRUE, orthogonalised impulse responses will be computed. |
... | Other arguments passed to methods |
Calculate impulse responses from a fable model
Description
Simulates future paths from a dataset using a fitted model. Innovations aresampled by the model's assumed error distribution. Ifbootstrap isTRUE,innovations will be sampled from the model's residuals. Ifnew_datacontains the.innov column, those values will be treated as innovations.
Usage
## S3 method for class 'VECM'IRF(x, new_data, specials, impulse = NULL, orthogonal = FALSE, ...)Arguments
x | A fitted model. |
new_data | A tsibble containing the time points and exogenous regressors to produce forecasts for. |
specials | (passed by |
impulse | A character string specifying the name of the variable that is shocked (the impulse variable). |
orthogonal | If TRUE, orthogonalised impulse responses will be computed. |
... | Other arguments passed to methods |
Mean models
Description
MEAN() returns an iid model applied to the formula's response variable.
Usage
MEAN(formula, ...)Arguments
formula | Model specification. |
... | Not used. |
Value
A model specification.
Specials
window
Thewindow special is used to specify a rolling window for the mean.
window(size = NULL)
size | The size (number of observations) for the rolling window. If NULL (default), a rolling window will not be used. |
See Also
Forecasting: Principles and Practices, Some simple forecasting methods (section 3.2)
Examples
library(tsibbledata)vic_elec %>% model(avg = MEAN(Demand))Neural Network Time Series Forecasts
Description
Feed-forward neural networks with a single hidden layer and lagged inputsfor forecasting univariate time series.
Usage
NNETAR(formula, n_nodes = NULL, n_networks = 20, scale_inputs = TRUE, ...)Arguments
formula | Model specification (see "Specials" section). |
n_nodes | Number of nodes in the hidden layer. Default is half of thenumber of input nodes (including external regressors, if given) plus 1. |
n_networks | Number of networks to fit with different random startingweights. These are then averaged when producing forecasts. |
scale_inputs | If TRUE, inputs are scaled by subtracting the columnmeans and dividing by their respective standard deviations. Scaling isapplied after transformations. |
... | Other arguments passed to |
Details
A feed-forward neural network is fitted with lagged values of the response asinputs and a single hidden layer withsize nodes. The inputs are forlags 1 top, and lagsm tomP wherem is the seasonal period specified.
If exogenous regressors are provided, its columns are also used as inputs.Missing values are currently not supported by this model.A total ofrepeats networks arefitted, each with random starting weights. These are then averaged whencomputing 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 number of hidden nodes. This is analogous to an AR(p) modelbut with non-linear functions. For seasonal data, the fitted model is calledan 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.
Specials
AR
TheAR special is used to specify auto-regressive components in each of thenodes of the neural network.
AR(p = NULL, P = 1, period = NULL)
p | The order of the non-seasonal auto-regressive (AR) terms. Ifp = NULL, an optimal number of lags will be selected for a linear AR(p) model via AIC. For seasonal time series, this will be computed on the seasonally adjusted data (via STL decomposition). |
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 seasonal period, or text to indicate the duration of the seasonal window (for example, annual seasonality would be "1 year"). |
xreg
Exogenous regressors can be included in an NNETAR model without explicitly using thexreg() special. Common exogenous regressor specials as specified incommon_xregs can also be used. These regressors are handled usingstats::model.frame(), and so interactions and other functionality behaves similarly tostats::lm().
xreg(...)
... | Bare expressions for the exogenous regressors (such aslog(x)) |
See Also
Forecasting: Principles and Practices, Neural network models (section 11.3)
Examples
as_tsibble(airmiles) %>% model(nn = NNETAR(box_cox(value, 0.15)))Random walk models
Description
RW() returns a random walk model, which is equivalent to an ARIMA(0,1,0)model with an optional drift coefficient included usingdrift().naive() is simply a wrappertorwf() for simplicity.snaive() returns forecasts andprediction intervals from an ARIMA(0,0,0)(0,1,0)m model where m is theseasonal period.
Usage
RW(formula, ...)NAIVE(formula, ...)SNAIVE(formula, ...)Arguments
formula | Model specification (see "Specials" section). |
... | Not used. |
Details
The random walk with drift model is
Y_t=c + Y_{t-1} + Z_t
whereZ_t is a normal iid error. Forecasts aregiven by
Y_n(h)=ch+Y_n
. If there is no drift (as innaive), the drift parameter c=0. Forecast standard errors allow foruncertainty in estimating the drift parameter (unlike the correspondingforecasts obtained by fitting an ARIMA model directly).
The seasonal naive model is
Y_t= Y_{t-m} + Z_t
whereZ_t is a normal iid error.
Value
A model specification.
Specials
lag
Thelag 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. Iflag = m, forecasts will return the observation fromm time periods ago. This can also be provided as text indicating the duration of the lag window (for example, annual seasonal lags would be "1 year"). |
drift
Thedrift special can be used to include a drift/trend component into the model. By default, drift is not included unlessdrift() is included in the formula.
drift(drift = TRUE)
drift | Ifdrift = TRUE, a drift term will be included in the model. |
See Also
Forecasting: Principles and Practices, Some simple forecasting methods (section 3.2)
Examples
library(tsibbledata)aus_production %>% model(rw = RW(Beer ~ drift()))as_tsibble(Nile) %>% model(NAIVE(value))library(tsibbledata)aus_production %>% model(snaive = SNAIVE(Beer ~ lag("year")))Theta method
Description
The theta method of Assimakopoulos and Nikolopoulos (2000) is equivalent tosimple exponential smoothing with drift. This is demonstrated in Hyndman andBillah (2003).
Usage
THETA(formula, ...)Arguments
formula | Model specification. |
... | Not used. |
Details
The series is tested for seasonality using the test outlined in A&N. Ifdeemed seasonal, the series is seasonally adjusted using a classicalmultiplicative decomposition before applying the theta method. The resultingforecasts are then reseasonalized.
More general theta methods are available in the forecTheta package.
Value
A model specification.
Specials
season
Theseason special is used to specify the parameters of the seasonal adjustment via classical decomposition.
season(period = NULL, method = c("multiplicative", "additive"))period | The periodic nature of the seasonality. This can be either a number indicating the number of observations in each seasonal period, or text to indicate the duration of the seasonal window (for example, annual seasonality would be "1 year"). |
method | The type of classical decomposition to apply. The original Theta method always used multiplicative seasonal decomposition, and so this is the default. |
Author(s)
Rob J Hyndman, Mitchell O'Hara-Wild
References
Assimakopoulos, V. and Nikolopoulos, K. (2000). The theta model:a decomposition approach to forecasting.International Journal ofForecasting16, 521-530.
Hyndman, R.J., and Billah, B. (2003) Unmasking the Theta method.International J. Forecasting,19, 287-290.
Examples
# Theta method with transformdeaths <- as_tsibble(USAccDeaths)deaths %>% model(theta = THETA(log(value))) %>% forecast(h = "4 years") %>% autoplot(deaths)# Compare seasonal specificationslibrary(tsibbledata)library(dplyr)aus_retail %>% filter(Industry == "Clothing retailing") %>% model(theta_multiplicative = THETA(Turnover ~ season(method = "multiplicative")), theta_additive = THETA(Turnover ~ season(method = "additive"))) %>% accuracy()Fit a linear model with time series components
Description
The model formula will be handled usingstats::model.matrix(), and sothe the same approach to include interactions instats::lm() applies whenspecifying theformula. In addition tostats::lm(), it is possible toincludecommon_xregs in the model formula, such astrend(),season(),andfourier().
Usage
TSLM(formula)Arguments
formula | Model specification. |
Value
A model specification.
Specials
xreg
Exogenous regressors can be included in a TSLM model without explicitly using thexreg() special. Common exogenous regressor specials as specified incommon_xregs can also be used. These regressors are handled usingstats::model.frame(), and so interactions and other functionality behaves similarly tostats::lm().
xreg(...)
... | Bare expressions for the exogenous regressors (such aslog(x)) |
See Also
stats::lm(),stats::model.matrix()Forecasting: Principles and Practices, Time series regression 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)Estimate a VAR model
Description
Searches through the vector of lag orders to find the best VAR model whichhas 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 |
Details
Exogenous regressors andcommon_xregs can be specified in the modelformula.
Value
A model specification.
Specials
AR
TheAR 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 minimisesic will be chosen. |
xreg
Exogenous regressors can be included in an VAR model without explicitly using thexreg() special. Common exogenous regressor specials as specified incommon_xregs can also be used. These regressors are handled usingstats::model.frame(), and so interactions and other functionality behaves similarly tostats::lm().
The inclusion of a constant in the model follows the similar rules tostats::lm(), where including1 will add a constant and0 or-1 will remove the constant. If left out, the inclusion of a constant will be determined by minimisingic.
xreg(...)
... | Bare expressions for the exogenous regressors (such aslog(x)) |
See Also
Forecasting: Principles and Practices, Vector autoregressions (section 11.2)
Examples
lung_deaths <- cbind(mdeaths, fdeaths) %>% as_tsibble(pivot_longer = FALSE)fit <- lung_deaths %>% model(VAR(vars(mdeaths, fdeaths) ~ AR(3)))report(fit)fit %>% forecast() %>% autoplot(lung_deaths)Estimate a VARIMA model
Description
Estimates a VARIMA model of a given order.
Usage
VARIMA(formula, identification = c("kronecker_indices", "none"), ...)## S3 method for class 'VARIMA'forecast( object, new_data = NULL, specials = NULL, bootstrap = FALSE, times = 5000, ...)## S3 method for class 'VARIMA'fitted(object, ...)## S3 method for class 'VARIMA'residuals(object, ...)## S3 method for class 'VARIMA'tidy(x, ...)## S3 method for class 'VARIMA'glance(x, ...)## S3 method for class 'VARIMA'report(object, ...)## S3 method for class 'VARIMA'generate(x, new_data, specials, ...)## S3 method for class 'VARIMA'IRF(x, new_data, specials, impulse = NULL, orthogonal = FALSE, ...)Arguments
formula | Model specification (see "Specials" section). |
identification | The identification technique used to estimate the model. |
... | Further arguments for arima |
object | A model for which forecasts are required. |
new_data | A tsibble containing the time points and exogenous regressors to produce forecasts for. |
specials | (passed by |
bootstrap | If |
times | The number of sample paths to use in estimating the forecast distribution when |
x | A fitted model. |
impulse | A character string specifying the name of the variable that is shocked (the impulse variable). |
orthogonal | If TRUE, orthogonalised impulse responses will be computed. |
Details
Exogenous regressors andcommon_xregs can be specified in the modelformula.
Value
A model specification.
A one row tibble summarising the model's fit.
Specials
pdq
Thepdq special is used to specify non-seasonal components of the model.
pdq(p = 0:5, d = 0:2, q = 0:5)
p | The order of the non-seasonal auto-regressive (AR) terms. If multiple values are provided, the one which minimisesic will be chosen. |
d | The order of integration for non-seasonal differencing. If multiple values are provided, one of the values will be selected via repeated KPSS tests. |
q | The order of the non-seasonal moving average (MA) terms. If multiple values are provided, the one which minimisesic will be chosen. |
xreg
Exogenous regressors can be included in an VARIMA model without explicitly using thexreg() special. Common exogenous regressor specials as specified incommon_xregs can also be used. These regressors are handled usingstats::model.frame(), and so interactions and other functionality behaves similarly tostats::lm().
The inclusion of a constant in the model follows the similar rules tostats::lm(), where including1 will add a constant and0 or-1 will remove the constant. If left out, the inclusion of a constant will be determined by minimisingic.
xreg(...)
... | Bare expressions for the exogenous regressors (such aslog(x)) |
See Also
Examples
library(tsibbledata)aus_production %>% autoplot(vars(Beer, Cement))fit <- aus_production %>% model(VARIMA(vars(Beer, Cement) ~ pdq(4,1,1), identification = "none"))fitfit %>% forecast(h = 50) %>% autoplot(tail(aus_production, 100))fitted(fit)residuals(fit)tidy(fit)glance(fit)report(fit)generate(fit, h = 10)IRF(fit, h = 10, impulse = "Beer")Estimate a VECM model
Description
Searches through the vector of lag orders to find the best VECM model whichhas lowest AIC, AICc or BIC value. The model is estimated using the Johansenprocedure (maximum likelihood).
Usage
VECM(formula, ic = c("aicc", "aic", "bic"), r = 1L, ...)Arguments
formula | Model specification (see "Specials" section). |
ic | The information criterion used in selecting the model. |
r | The number of cointegrating relationships |
... | Further arguments for arima |
Details
Exogenous regressors andcommon_xregs can be specified in the modelformula.
Value
A model specification.
Specials
AR
TheAR 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 minimisesic will be chosen. |
xreg
Exogenous regressors can be included in an VECM model without explicitly using thexreg() special. Common exogenous regressor specials as specified incommon_xregs can also be used. These regressors are handled usingstats::model.frame(), and so interactions and other functionality behaves similarly tostats::lm().
The inclusion of a constant in the model follows the similar rules tostats::lm(), where including1 will add a constant and0 or-1 will remove the constant. If left out, the inclusion of a constant will be determined by minimisingic.
xreg(...)
... | Bare expressions for the exogenous regressors (such aslog(x)) |
Examples
lung_deaths <- cbind(mdeaths, fdeaths) %>% as_tsibble(pivot_longer = FALSE)fit <- lung_deaths %>% model(VECM(vars(mdeaths, fdeaths) ~ AR(3)))report(fit)fit %>% forecast() %>% autoplot(lung_deaths)Breusch-Godfrey Test
Description
Breusch-Godfrey test for higher-order serial correlation.
Usage
breusch_godfrey(x, ...)## S3 method for class 'TSLM'breusch_godfrey(x, order = 1, type = c("Chisq", "F"), ...)Arguments
x | A model object to be tested. |
... | Further arguments for methods. |
order | The maximum order of serial correlation to test for. |
type | The type of test statistic to use. |
See Also
Common exogenous regressors
Description
These special functions provide interfaces to more complicated functions withinthe model formulae interface.
Usage
common_xregsSpecials
trend
Thetrend special includes common linear trend regressors in the model. It also supports piecewise linear trend via theknots 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
Theseason 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 seasonal period, or text to indicate the duration of the seasonal window (for example, annual seasonality would be "1 year"). |
fourier
Thefourier special includes seasonal fourier terms in the model. The maximum order of the fourier terms must be specified usingK.
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 seasonal period, or text to indicate the duration of the seasonal window (for example, annual seasonality would be "1 year"). |
K | The maximum order of the fourier terms. |
origin | An optional time value to act as the starting time for the fourier series. |
Extract estimated states from an ETS model.
Description
Extract estimated states from an ETS model.
Usage
## S3 method for class 'ETS'components(object, ...)Arguments
object | An estimated model. |
... | Unused. |
Value
Afabletools::dable() containing estimated states.
Examples
as_tsibble(USAccDeaths) %>% model(ets = ETS(log(value) ~ season("A"))) %>% components()Extract fitted values from a fable model
Description
Extracts the fitted values.
Usage
## S3 method for class 'AR'fitted(object, ...)Arguments
object | A model for which forecasts are required. |
... | Other arguments passed to methods |
Value
A vector of fitted values.
Examples
as_tsibble(lh) %>% model(AR(value ~ order(3))) %>% fitted()Extract fitted values from a fable model
Description
Extracts the fitted values.
Usage
## S3 method for class 'ARIMA'fitted(object, ...)Arguments
object | A model for which forecasts are required. |
... | Other arguments passed to methods |
Value
A vector of fitted values.
Examples
USAccDeaths %>% as_tsibble() %>% model(arima = ARIMA(log(value) ~ pdq(0, 1, 1) + PDQ(0, 1, 1))) %>% fitted()Extract fitted values from a fable model
Description
Extracts the fitted values.
Usage
## S3 method for class 'ETS'fitted(object, ...)Arguments
object | A model for which forecasts are required. |
... | Other arguments passed to methods |
Value
A vector of fitted values.
Examples
as_tsibble(USAccDeaths) %>% model(ets = ETS(log(value) ~ season("A"))) %>% fitted()Extract fitted values from a fable model
Description
Extracts the fitted values.
Usage
## S3 method for class 'NNETAR'fitted(object, ...)Arguments
object | A model for which forecasts are required. |
... | Other arguments passed to methods |
Value
A vector of fitted values.
Examples
as_tsibble(airmiles) %>% model(nn = NNETAR(box_cox(value, 0.15))) %>% fitted()Extract fitted values from a fable model
Description
Extracts the fitted values.
Usage
## S3 method for class 'RW'fitted(object, ...)Arguments
object | A model for which forecasts are required. |
... | Other arguments passed to 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()Extract fitted values from a fable model
Description
Extracts the fitted values.
Usage
## S3 method for class 'TSLM'fitted(object, ...)Arguments
object | A model for which forecasts are required. |
... | Other arguments passed to methods |
Value
A vector of fitted values.
Examples
as_tsibble(USAccDeaths) %>% model(lm = TSLM(log(value) ~ trend() + season())) %>% fitted()Extract fitted values from a fable model
Description
Extracts the fitted values.
Usage
## S3 method for class 'VAR'fitted(object, ...)Arguments
object | A model for which forecasts are required. |
... | Other arguments passed to methods |
Value
A vector of fitted values.
Examples
lung_deaths <- cbind(mdeaths, fdeaths) %>% as_tsibble(pivot_longer = FALSE)lung_deaths %>% model(VAR(vars(mdeaths, fdeaths) ~ AR(3))) %>% fitted()Extract fitted values from a fable model
Description
Extracts the fitted values.
Usage
## S3 method for class 'croston'fitted(object, ...)Arguments
object | A model for which forecasts are required. |
... | Other arguments passed to methods |
Value
A vector of fitted values.
Examples
library(tsibble)sim_poisson <- tsibble( time = yearmonth("2012 Dec") + seq_len(24), count = rpois(24, lambda = 0.3), index = time)sim_poisson %>% model(CROSTON(count)) %>% tidy()Extract fitted values from a fable model
Description
Extracts the fitted values.
Usage
## S3 method for class 'fable_theta'fitted(object, ...)Arguments
object | A model for which forecasts are required. |
... | Other arguments passed to methods |
Value
A vector of fitted values.
Examples
library(tsibbledata)vic_elec %>% model(avg = MEAN(Demand)) %>% fitted()Extract fitted values from a fable model
Description
Extracts the fitted values.
Usage
## S3 method for class 'model_mean'fitted(object, ...)Arguments
object | A model for which forecasts are required. |
... | Other arguments passed to methods |
Value
A vector of fitted values.
Examples
library(tsibbledata)vic_elec %>% model(avg = MEAN(Demand)) %>% fitted()Forecast a model from the fable package
Description
Produces forecasts from a trained model.
Usage
## S3 method for class 'AR'forecast( object, new_data = NULL, specials = NULL, bootstrap = FALSE, times = 5000, ...)Arguments
object | A model for which forecasts are required. |
new_data | A tsibble containing the time points and exogenous regressors to produce forecasts for. |
specials | (passed by |
bootstrap | If |
times | The number of sample paths to use in estimating the forecast distribution when |
... | Other arguments passed to methods |
Value
A list of forecasts.
Examples
as_tsibble(lh) %>% model(AR(value ~ order(3))) %>% forecast()Forecast a model from the fable package
Description
Produces forecasts from a trained model.
Usage
## S3 method for class 'ARIMA'forecast( object, new_data = NULL, specials = NULL, bootstrap = FALSE, times = 5000, ...)Arguments
object | A model for which forecasts are required. |
new_data | A tsibble containing the time points and exogenous regressors to produce forecasts for. |
specials | (passed by |
bootstrap | If |
times | The number of sample paths to use in estimating the forecast distribution when |
... | Other arguments passed to methods |
Value
A list of forecasts.
Examples
USAccDeaths %>% as_tsibble() %>% model(arima = ARIMA(log(value) ~ pdq(0, 1, 1) + PDQ(0, 1, 1))) %>% forecast()Forecast a model from the fable package
Description
Produces forecasts from a trained model.
Usage
## S3 method for class 'ETS'forecast( object, new_data, specials = NULL, simulate = FALSE, bootstrap = FALSE, times = 5000, ...)Arguments
object | A model for which forecasts are required. |
new_data | A tsibble containing the time points and exogenous regressors to produce forecasts for. |
specials | (passed by |
simulate | If |
bootstrap | If |
times | The number of sample paths to use in estimating the forecast distribution if simulated intervals are used. |
... | Other arguments passed to methods |
Value
A list of forecasts.
Examples
as_tsibble(USAccDeaths) %>% model(ets = ETS(log(value) ~ season("A"))) %>% forecast()Forecast a model from the fable package
Description
Produces forecasts from a trained model.
Usage
## S3 method for class 'NNETAR'forecast( object, new_data, specials = NULL, simulate = TRUE, bootstrap = FALSE, times = 5000, ...)Arguments
object | A model for which forecasts are required. |
new_data | A tsibble containing the time points and exogenous regressors to produce forecasts for. |
specials | (passed by |
simulate | If |
bootstrap | If |
times | The number of sample paths to use in producing the forecast distribution. Setting |
... | Other arguments passed to methods |
Value
A list of forecasts.
Examples
as_tsibble(airmiles) %>% model(nn = NNETAR(box_cox(value, 0.15))) %>% forecast(times = 10)Forecast a model from the fable package
Description
Produces forecasts from a trained model.
Usage
## S3 method for class 'RW'forecast( object, new_data, specials = NULL, simulate = FALSE, bootstrap = FALSE, times = 5000, ...)Arguments
object | A model for which forecasts are required. |
new_data | A tsibble containing the time points and exogenous regressors to produce forecasts for. |
specials | (passed by |
simulate | If |
bootstrap | If |
times | The number of sample paths to use in estimating the forecast distribution when |
... | Other arguments passed to methods |
Value
A list of forecasts.
Examples
as_tsibble(Nile) %>% model(NAIVE(value)) %>% forecast()library(tsibbledata)aus_production %>% model(snaive = SNAIVE(Beer ~ lag("year"))) %>% forecast()Forecast a model from the fable package
Description
Produces forecasts from a trained model.
Usage
## S3 method for class 'TSLM'forecast( object, new_data, specials = NULL, bootstrap = FALSE, approx_normal = TRUE, times = 5000, ...)Arguments
object | A model for which forecasts are required. |
new_data | A tsibble containing the time points and exogenous regressors to produce forecasts for. |
specials | (passed by |
bootstrap | If |
approx_normal | Should the resulting forecast distributions beapproximated as a Normal distribution instead of a Student's Tdistribution. Returning Normal distributions (the default) is a usefulapproximation to make it easier for using TSLM models in model combinationsor reconciliation processes. |
times | The number of sample paths to use in estimating the forecast distribution when |
... | Other arguments passed to methods |
Value
A list of forecasts.
Examples
as_tsibble(USAccDeaths) %>% model(lm = TSLM(log(value) ~ trend() + season())) %>% forecast()Forecast a model from the fable package
Description
Produces forecasts from a trained model.
Usage
## S3 method for class 'VAR'forecast( object, new_data = NULL, specials = NULL, bootstrap = FALSE, times = 5000, ...)Arguments
object | A model for which forecasts are required. |
new_data | A tsibble containing the time points and exogenous regressors to produce forecasts for. |
specials | (passed by |
bootstrap | If |
times | The number of sample paths to use in estimating the forecast distribution when |
... | Other arguments passed to methods |
Value
A list of forecasts.
Examples
lung_deaths <- cbind(mdeaths, fdeaths) %>% as_tsibble(pivot_longer = FALSE)lung_deaths %>% model(VAR(vars(mdeaths, fdeaths) ~ AR(3))) %>% forecast()Forecast a model from the fable package
Description
Produces forecasts from a trained model.
Usage
## S3 method for class 'croston'forecast(object, new_data, specials = NULL, ...)Arguments
object | A model for which forecasts are required. |
new_data | A tsibble containing the time points and exogenous regressors to produce forecasts for. |
specials | (passed by |
... | Other arguments passed to methods |
Value
A list of forecasts.
Examples
library(tsibble)sim_poisson <- tsibble( time = yearmonth("2012 Dec") + seq_len(24), count = rpois(24, lambda = 0.3), index = time)sim_poisson %>% model(CROSTON(count)) %>% forecast()Forecast a model from the fable package
Description
Produces forecasts from a trained model.
Usage
## S3 method for class 'fable_theta'forecast( object, new_data, specials = NULL, bootstrap = FALSE, times = 5000, ...)Arguments
object | A model for which forecasts are required. |
new_data | A tsibble containing the time points and exogenous regressors to produce forecasts for. |
specials | (passed by |
bootstrap | If |
times | The number of sample paths to use in estimating the forecast distribution when |
... | Other arguments passed to methods |
Value
A list of forecasts.
Examples
USAccDeaths %>% as_tsibble() %>% model(arima = ARIMA(log(value) ~ pdq(0, 1, 1) + PDQ(0, 1, 1))) %>% forecast()Forecast a model from the fable package
Description
Produces forecasts from a trained model.
Usage
## S3 method for class 'model_mean'forecast( object, new_data, specials = NULL, bootstrap = FALSE, times = 5000, ...)Arguments
object | A model for which forecasts are required. |
new_data | A tsibble containing the time points and exogenous regressors to produce forecasts for. |
specials | (passed by |
bootstrap | If |
times | The number of sample paths to use in estimating the forecast distribution when |
... | Other arguments passed to methods |
Value
A list of forecasts.
Examples
library(tsibbledata)vic_elec %>% model(avg = MEAN(Demand)) %>% forecast()Generate new data from a fable model
Description
Simulates future paths from a dataset using a fitted model. Innovations aresampled by the model's assumed error distribution. Ifbootstrap isTRUE,innovations will be sampled from the model's residuals. Ifnew_datacontains the.innov column, those values will be treated as innovations.
Usage
## S3 method for class 'AR'generate(x, new_data = NULL, specials = NULL, bootstrap = FALSE, ...)Arguments
x | A fitted model. |
new_data | A tsibble containing the time points and exogenous regressors to produce forecasts for. |
specials | (passed by |
bootstrap | If |
... | Other arguments passed to methods |
See Also
Examples
as_tsibble(lh) %>% model(AR(value ~ order(3))) %>% generate()Generate new data from a fable model
Description
Simulates future paths from a dataset using a fitted model. Innovations aresampled by the model's assumed error distribution. Ifbootstrap isTRUE,innovations will be sampled from the model's residuals. Ifnew_datacontains the.innov column, those values will be treated as innovations.
Usage
## S3 method for class 'ARIMA'generate(x, new_data, specials, bootstrap = FALSE, ...)Arguments
x | A fitted model. |
new_data | A tsibble containing the time points and exogenous regressors to produce forecasts for. |
specials | (passed by |
bootstrap | If |
... | Other arguments passed to methods |
See Also
Examples
fable_fit <- as_tsibble(USAccDeaths) %>% model(model = ARIMA(value ~ 0 + pdq(0,1,1) + PDQ(0,1,1)))fable_fit %>% generate(times = 10)Generate new data from a fable model
Description
Simulates future paths from a dataset using a fitted model. Innovations aresampled by the model's assumed error distribution. Ifbootstrap isTRUE,innovations will be sampled from the model's residuals. Ifnew_datacontains the.innov column, those values will be treated as innovations.
Usage
## S3 method for class 'ETS'generate(x, new_data, specials, bootstrap = FALSE, ...)Arguments
x | A fitted model. |
new_data | A tsibble containing the time points and exogenous regressors to produce forecasts for. |
specials | (passed by |
bootstrap | If |
... | Other arguments passed to methods |
See Also
Examples
as_tsibble(USAccDeaths) %>% model(ETS(log(value) ~ season("A"))) %>% generate(times = 100)Generate new data from a fable model
Description
Simulates future paths from a dataset using a fitted model. Innovations aresampled by the model's assumed error distribution. Ifbootstrap isTRUE,innovations will be sampled from the model's residuals. Ifnew_datacontains 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 the time points and exogenous regressors to produce forecasts for. |
specials | (passed by |
bootstrap | If |
... | Other arguments passed to methods |
See Also
Examples
as_tsibble(airmiles) %>% model(nn = NNETAR(box_cox(value, 0.15))) %>% generate()Generate new data from a fable model
Description
Simulates future paths from a dataset using a fitted model. Innovations aresampled by the model's assumed error distribution. Ifbootstrap isTRUE,innovations will be sampled from the model's residuals. Ifnew_datacontains the.innov column, those values will be treated as innovations.
Usage
## S3 method for class 'RW'generate(x, new_data, bootstrap = FALSE, ...)Arguments
x | A fitted model. |
new_data | A tsibble containing the time points and exogenous regressors to produce forecasts for. |
bootstrap | If |
... | Other arguments passed to methods |
See Also
Examples
as_tsibble(Nile) %>% model(NAIVE(value)) %>% generate()library(tsibbledata)aus_production %>% model(snaive = SNAIVE(Beer ~ lag("year"))) %>% generate()Generate new data from a fable model
Description
Simulates future paths from a dataset using a fitted model. Innovations aresampled by the model's assumed error distribution. Ifbootstrap isTRUE,innovations will be sampled from the model's residuals. Ifnew_datacontains 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 the time points and exogenous regressors to produce forecasts for. |
specials | (passed by |
bootstrap | If |
... | Other arguments passed to methods |
See Also
Examples
as_tsibble(USAccDeaths) %>% model(lm = TSLM(log(value) ~ trend() + season())) %>% generate()Generate new data from a fable model
Description
Simulates future paths from a dataset using a fitted model. Innovations aresampled by the model's assumed error distribution. Ifbootstrap isTRUE,innovations will be sampled from the model's residuals. Ifnew_datacontains the.innov column, those values will be treated as innovations.
Usage
## S3 method for class 'VAR'generate(x, new_data, specials, ...)Arguments
x | A fitted model. |
new_data | A tsibble containing the time points and exogenous regressors to produce forecasts for. |
specials | (passed by |
... | Other arguments passed to methods |
See Also
Examples
as_tsibble(USAccDeaths) %>% model(ETS(log(value) ~ season("A"))) %>% generate(times = 100)Generate new data from a fable model
Description
Simulates future paths from a dataset using a fitted model. Innovations aresampled by the model's assumed error distribution. Ifbootstrap isTRUE,innovations will be sampled from the model's residuals. Ifnew_datacontains the.innov column, those values will be treated as innovations.
Usage
## S3 method for class 'VECM'generate(x, new_data, specials, ...)Arguments
x | A fitted model. |
new_data | A tsibble containing the time points and exogenous regressors to produce forecasts for. |
specials | (passed by |
... | Other arguments passed to methods |
See Also
Examples
as_tsibble(USAccDeaths) %>% model(ETS(log(value) ~ season("A"))) %>% generate(times = 100)Generate new data from a fable model
Description
Simulates future paths from a dataset using a fitted model. Innovations aresampled by the model's assumed error distribution. Ifbootstrap isTRUE,innovations will be sampled from the model's residuals. Ifnew_datacontains 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 the time points and exogenous regressors to produce forecasts for. |
bootstrap | If |
... | Other arguments passed to methods |
See Also
Examples
library(tsibbledata)vic_elec %>% model(avg = MEAN(Demand)) %>% generate()Glance a AR
Description
Construct a single row summary of the AR model.
Usage
## S3 method for class 'AR'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
as_tsibble(lh) %>% model(AR(value ~ order(3))) %>% glance()Glance an ARIMA model
Description
Construct a single row summary of the ARIMA model.
Usage
## S3 method for class 'ARIMA'glance(x, ...)Arguments
x | model or other R object to convert to single-row data frame |
... | other arguments passed to methods |
Format
A data frame with 1 row, with columns:
- sigma2
The unbiased variance of residuals. Calculated as
sum(residuals^2) / (num_observations - num_pararameters + 1)- log_lik
The log-likelihood
- AIC
Akaike information criterion
- AICc
Akaike information criterion, corrected for small sample sizes
- BIC
Bayesian information criterion
- ar_roots, ma_roots
The model's characteristic 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()Glance an ETS model
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.
Examples
as_tsibble(USAccDeaths) %>% model(ets = ETS(log(value) ~ season("A"))) %>% glance()Glance a NNETAR model
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()Glance a lag walk model
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 |
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()Glance a TSLM
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()Glance a VAR
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(mdeaths, fdeaths) ~ AR(3))) %>% glance()Glance a VECM
Description
Construct a single row summary of the VECM model.
Usage
## S3 method for class 'VECM'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), the cointegrating vector (beta) and information criterion(AIC,AICc,BIC).
Value
A one row tibble summarising the model's fit.
Glance a theta method
Description
Construct a single row summary of the average method model.
Usage
## S3 method for class 'fable_theta'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).
Value
A one row tibble summarising the model's fit.
Glance a average method model
Description
Construct a single row summary of the average method model.
Usage
## S3 method for class 'model_mean'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).
Value
A one row tibble summarising the model's fit.
Examples
library(tsibbledata)vic_elec %>% model(avg = MEAN(Demand)) %>% glance()Interpolate missing values from a fable model
Description
Applies a model-specific estimation technique to predict the values of missing values in atsibble, and replace them.
Usage
## S3 method for class 'ARIMA'interpolate(object, new_data, specials, ...)Arguments
object | A model for which forecasts are required. |
new_data | A tsibble containing the time points and exogenous regressors to produce forecasts for. |
specials | (passed by |
... | Other arguments passed to methods |
Value
A tibble of the same dimension ofnew_data with missing values interpolated.
Examples
library(tsibbledata)olympic_running %>% model(arima = ARIMA(Time ~ trend())) %>% interpolate(olympic_running)Interpolate missing values from a fable model
Description
Applies a model-specific estimation technique to predict the values of missing values in atsibble, and replace them.
Usage
## S3 method for class 'TSLM'interpolate(object, new_data, specials, ...)Arguments
object | A model for which forecasts are required. |
new_data | A tsibble containing the time points and exogenous regressors to produce forecasts for. |
specials | (passed by |
... | Other arguments passed to methods |
Value
A tibble of the same dimension ofnew_data with missing values interpolated.
Examples
library(tsibbledata)olympic_running %>% model(lm = TSLM(Time ~ trend())) %>% interpolate(olympic_running)Interpolate missing values from a fable model
Description
Applies a model-specific estimation technique to predict the values of missing values in atsibble, and replace them.
Usage
## S3 method for class 'model_mean'interpolate(object, new_data, specials, ...)Arguments
object | A model for which forecasts are required. |
new_data | A tsibble containing the time points and exogenous regressors to produce forecasts for. |
specials | (passed by |
... | Other arguments passed to methods |
Value
A tibble of the same dimension ofnew_data with missing values interpolated.
Examples
library(tsibbledata)olympic_running %>% model(mean = MEAN(Time)) %>% interpolate(olympic_running)Objects exported from other packages
Description
These objects are imported from other packages. Follow the linksbelow to see their documentation.
- dplyr
- tsibble
Refit an AR model
Description
Applies a fitted AR model to a new dataset.
Usage
## S3 method for class 'AR'refit(object, new_data, specials = NULL, reestimate = FALSE, ...)Arguments
object | A model for which forecasts are required. |
new_data | A tsibble containing the time points and exogenous regressors to produce forecasts for. |
specials | (passed by |
reestimate | If |
... | Other arguments passed to methods |
Value
A refitted model.
Examples
lung_deaths_male <- as_tsibble(mdeaths)lung_deaths_female <- as_tsibble(fdeaths)fit <- lung_deaths_male %>% model(AR(value ~ 1 + order(10)))report(fit)fit %>% refit(lung_deaths_female) %>% report()Refit an ARIMA model
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 | A model for which forecasts are required. |
new_data | A tsibble containing the time points and exogenous regressors to produce forecasts for. |
specials | (passed by |
reestimate | If |
... | Other arguments passed to methods |
Value
A refitted model.
Examples
lung_deaths_male <- as_tsibble(mdeaths)lung_deaths_female <- as_tsibble(fdeaths)fit <- lung_deaths_male %>% model(ARIMA(value ~ 1 + pdq(2, 0, 0) + PDQ(2, 1, 0)))report(fit)fit %>% refit(lung_deaths_female) %>% report()Refit an ETS model
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 | A model for which forecasts are required. |
new_data | A tsibble containing the time points and exogenous regressors to produce forecasts for. |
specials | (passed by |
reestimate | If |
reinitialise | If TRUE, the initial parameters will be re-estimated to suit the new data. |
... | Other arguments passed to methods |
Examples
lung_deaths_male <- as_tsibble(mdeaths)lung_deaths_female <- as_tsibble(fdeaths)fit <- lung_deaths_male %>% model(ETS(value))report(fit)fit %>% refit(lung_deaths_female, reinitialise = TRUE) %>% report()Refit a NNETAR model
Description
Applies a fitted NNETAR model to a new dataset.
Usage
## S3 method for class 'NNETAR'refit(object, new_data, specials = NULL, reestimate = FALSE, ...)Arguments
object | A model for which forecasts are required. |
new_data | A tsibble containing the time points and exogenous regressors to produce forecasts for. |
specials | (passed by |
reestimate | If |
... | Other arguments passed to methods |
Value
A refitted model.
Examples
lung_deaths_male <- as_tsibble(mdeaths)lung_deaths_female <- as_tsibble(fdeaths)fit <- lung_deaths_male %>% model(NNETAR(value))report(fit)fit %>% refit(new_data = lung_deaths_female, reestimate = FALSE) %>% report()Refit a lag walk model
Description
Applies a fitted random walk model to a new dataset.
Usage
## S3 method for class 'RW'refit(object, new_data, specials = NULL, reestimate = FALSE, ...)Arguments
object | A model for which forecasts are required. |
new_data | A tsibble containing the time points and exogenous regressors to produce forecasts for. |
specials | (passed by |
reestimate | If |
... | Other arguments passed to methods |
Details
The modelsNAIVE andSNAIVE have no specific model parameters. Usingrefitfor one of these models will provide the same estimation results as one wouldusefabletools::model(NAIVE(...)) (orfabletools::model(SNAIVE(...)).
Examples
lung_deaths_male <- as_tsibble(mdeaths)lung_deaths_female <- as_tsibble(fdeaths)fit <- lung_deaths_male %>% model(RW(value ~ drift()))report(fit)fit %>% refit(lung_deaths_female) %>% report()Refit aTSLM
Description
Applies a fittedTSLM to a new dataset.
Usage
## S3 method for class 'TSLM'refit(object, new_data, specials = NULL, reestimate = FALSE, ...)Arguments
object | A model for which forecasts are required. |
new_data | A tsibble containing the time points and exogenous regressors to produce forecasts for. |
specials | (passed by |
reestimate | If |
... | Other arguments passed to methods |
Examples
lung_deaths_male <- as_tsibble(mdeaths)lung_deaths_female <- as_tsibble(fdeaths)fit <- lung_deaths_male %>% model(TSLM(value ~ trend() + season()))report(fit)fit %>% refit(lung_deaths_female) %>% report()Refit a MEAN model
Description
Applies a fitted average method model to a new dataset.
Usage
## S3 method for class 'model_mean'refit(object, new_data, specials = NULL, reestimate = FALSE, ...)Arguments
object | A model for which forecasts are required. |
new_data | A tsibble containing the time points and exogenous regressors to produce forecasts for. |
specials | (passed by |
reestimate | If |
... | Other arguments passed to methods |
Examples
lung_deaths_male <- as_tsibble(mdeaths)lung_deaths_female <- as_tsibble(fdeaths)fit <- lung_deaths_male %>% model(MEAN(value))report(fit)fit %>% refit(lung_deaths_female) %>% report()Extract residuals from a fable model
Description
Extracts the residuals.
Usage
## S3 method for class 'AR'residuals(object, type = c("innovation", "regression"), ...)Arguments
object | A model for which forecasts are required. |
type | The type of residuals to extract. |
... | Other arguments passed to methods |
Value
A vector of fitted residuals.
Examples
as_tsibble(lh) %>% model(AR(value ~ order(3))) %>% residuals()Extract residuals from a fable model
Description
Extracts the residuals.
Usage
## S3 method for class 'ARIMA'residuals(object, type = c("innovation", "regression"), ...)Arguments
object | A model for which forecasts are required. |
type | The type of residuals to extract. |
... | Other arguments passed to 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()Extract residuals from a fable model
Description
Extracts the residuals.
Usage
## S3 method for class 'ETS'residuals(object, ...)Arguments
object | A model for which forecasts are required. |
... | Other arguments passed to methods |
Value
A vector of fitted residuals.
Examples
as_tsibble(USAccDeaths) %>% model(ets = ETS(log(value) ~ season("A"))) %>% residuals()Extract residuals from a fable model
Description
Extracts the residuals.
Usage
## S3 method for class 'NNETAR'residuals(object, ...)Arguments
object | A model for which forecasts are required. |
... | Other arguments passed to methods |
Value
A vector of fitted residuals.
Examples
as_tsibble(airmiles) %>% model(nn = NNETAR(box_cox(value, 0.15))) %>% residuals()Extract residuals from a fable model
Description
Extracts the residuals.
Usage
## S3 method for class 'RW'residuals(object, ...)Arguments
object | A model for which forecasts are required. |
... | Other arguments passed to methods |
Value
A vector of fitted residuals.
Examples
as_tsibble(Nile) %>% model(NAIVE(value)) %>% residuals()library(tsibbledata)aus_production %>% model(snaive = SNAIVE(Beer ~ lag("year"))) %>% residuals()Extract residuals from a fable model
Description
Extracts the residuals.
Usage
## S3 method for class 'TSLM'residuals(object, ...)Arguments
object | A model for which forecasts are required. |
... | Other arguments passed to methods |
Value
A vector of fitted residuals.
Examples
as_tsibble(USAccDeaths) %>% model(lm = TSLM(log(value) ~ trend() + season())) %>% residuals()Extract residuals from a fable model
Description
Extracts the residuals.
Usage
## S3 method for class 'VAR'residuals(object, ...)Arguments
object | A model for which forecasts are required. |
... | Other arguments passed to methods |
Value
A vector of fitted residuals.
Examples
lung_deaths <- cbind(mdeaths, fdeaths) %>% as_tsibble(pivot_longer = FALSE)lung_deaths %>% model(VAR(vars(mdeaths, fdeaths) ~ AR(3))) %>% residuals()Extract residuals from a fable model
Description
Extracts the residuals.
Usage
## S3 method for class 'croston'residuals(object, ...)Arguments
object | A model for which forecasts are required. |
... | Other arguments passed to methods |
Value
A vector of fitted residuals.
Examples
library(tsibble)sim_poisson <- tsibble( time = yearmonth("2012 Dec") + seq_len(24), count = rpois(24, lambda = 0.3), index = time)sim_poisson %>% model(CROSTON(count)) %>% residuals()Extract residuals from a fable model
Description
Extracts the residuals.
Usage
## S3 method for class 'fable_theta'residuals(object, ...)Arguments
object | A model for which forecasts are required. |
... | Other arguments passed to methods |
Value
A vector of fitted residuals.
Examples
library(tsibbledata)vic_elec %>% model(avg = MEAN(Demand)) %>% residuals()Extract residuals from a fable model
Description
Extracts the residuals.
Usage
## S3 method for class 'model_mean'residuals(object, ...)Arguments
object | A model for which forecasts are required. |
... | Other arguments passed to methods |
Value
A vector of fitted residuals.
Examples
library(tsibbledata)vic_elec %>% model(avg = MEAN(Demand)) %>% residuals()Tidy a fable model
Description
Returns the coefficients from the model in atibble format.
Usage
## S3 method for class 'AR'tidy(x, ...)Arguments
x | An object to be converted into a tidy |
... | Additional arguments to tidying method. |
Value
The model's coefficients in atibble.
Examples
as_tsibble(lh) %>% model(AR(value ~ order(3))) %>% tidy()Tidy a fable model
Description
Returns the coefficients from the model in atibble format.
Usage
## S3 method for class 'ARIMA'tidy(x, ...)Arguments
x | An object to be converted into a tidy |
... | Additional arguments to tidying method. |
Value
The model's coefficients in atibble.
Examples
USAccDeaths %>% as_tsibble() %>% model(arima = ARIMA(log(value) ~ pdq(0, 1, 1) + PDQ(0, 1, 1))) %>% tidy()Tidy a fable model
Description
Returns the coefficients from the model in atibble format.
Usage
## S3 method for class 'ETS'tidy(x, ...)Arguments
x | An object to be converted into a tidy |
... | Additional arguments to tidying method. |
Value
The model's coefficients in atibble.
Examples
as_tsibble(USAccDeaths) %>% model(ets = ETS(log(value) ~ season("A"))) %>% tidy()Tidy a fable model
Description
Returns the coefficients from the model in atibble format.
Usage
## S3 method for class 'NNETAR'tidy(x, ...)Arguments
x | An object to be converted into a tidy |
... | Additional arguments to tidying method. |
Value
The model's coefficients in atibble.
Examples
as_tsibble(airmiles) %>% model(nn = NNETAR(box_cox(value, 0.15))) %>% tidy()Tidy a fable model
Description
Returns the coefficients from the model in atibble format.
Usage
## S3 method for class 'RW'tidy(x, ...)Arguments
x | An object to be converted into a tidy |
... | Additional arguments to tidying method. |
Value
The model's coefficients in atibble.
Examples
as_tsibble(Nile) %>% model(NAIVE(value)) %>% tidy()library(tsibbledata)aus_production %>% model(snaive = SNAIVE(Beer ~ lag("year"))) %>% tidy()Tidy a fable model
Description
Returns the coefficients from the model in atibble format.
Usage
## S3 method for class 'TSLM'tidy(x, ...)Arguments
x | An object to be converted into a tidy |
... | Additional arguments to tidying method. |
Value
The model's coefficients in atibble.
Examples
as_tsibble(USAccDeaths) %>% model(lm = TSLM(log(value) ~ trend() + season())) %>% tidy()Tidy a fable model
Description
Returns the coefficients from the model in atibble format.
Usage
## S3 method for class 'VAR'tidy(x, ...)Arguments
x | An object to be converted into a tidy |
... | Additional arguments to tidying method. |
Value
The model's coefficients in atibble.
Examples
lung_deaths <- cbind(mdeaths, fdeaths) %>% as_tsibble(pivot_longer = FALSE)lung_deaths %>% model(VAR(vars(mdeaths, fdeaths) ~ AR(3))) %>% tidy()Tidy a fable model
Description
Returns the coefficients from the model in atibble format.
Usage
## S3 method for class 'croston'tidy(x, ...)Arguments
x | An object to be converted into a tidy |
... | Additional arguments to tidying method. |
Value
The model's coefficients in atibble.
Examples
library(tsibble)sim_poisson <- tsibble( time = yearmonth("2012 Dec") + seq_len(24), count = rpois(24, lambda = 0.3), index = time)sim_poisson %>% model(CROSTON(count)) %>% tidy()Tidy a fable model
Description
Returns the coefficients from the model in atibble format.
Usage
## S3 method for class 'fable_theta'tidy(x, ...)Arguments
x | An object to be converted into a tidy |
... | Additional arguments to tidying method. |
Value
The model's coefficients in atibble.
Examples
USAccDeaths %>% as_tsibble() %>% model(arima = ARIMA(log(value) ~ pdq(0, 1, 1) + PDQ(0, 1, 1))) %>% tidy()Tidy a fable model
Description
Returns the coefficients from the model in atibble format.
Usage
## S3 method for class 'model_mean'tidy(x, ...)Arguments
x | An object to be converted into a tidy |
... | Additional arguments to tidying method. |
Value
The model's coefficients in atibble.
Examples
library(tsibbledata)vic_elec %>% model(avg = MEAN(Demand)) %>% tidy()Options for the unit root tests for order of integration
Description
By default, a kpss test (viafeasts::unitroot_kpss()) will be performedfor testing the required first order differences, and a test of the seasonalstrength (viafeasts::feat_stl() seasonal_strength) being above the 0.64threshold is used for determining seasonal required differences.
Usage
unitroot_options( ndiffs_alpha = 0.05, nsdiffs_alpha = 0.05, ndiffs_pvalue = ~feasts::unitroot_kpss(.)["kpss_pvalue"], nsdiffs_pvalue = ur_seasonal_strength(0.64))Arguments
ndiffs_alpha,nsdiffs_alpha | The level for the test specified in the |
ndiffs_pvalue,nsdiffs_pvalue | A function (or lambda expression) that provides a p-value for the unit root test. As long as For the function for the seasonal p-value, the seasonal period will be provided as the |
Value
A list of parameters