# forecast.stl

##### Forecasting using stl objects

Forecasts of STL objects are obtained by applying a non-seasonal forecasting method to the seasonally adjusted data and re-seasonalizing using the last year of the seasonal component.

- Keywords
- ts

##### Usage

```
stlm(x, s.window=7, robust=FALSE, method=c("ets","arima"),
modelfunction=NULL, etsmodel="ZZN", lambda=NULL, xreg=NULL,
allow.multiplicative.trend=FALSE, ...)
stlf(x, h=frequency(x)*2, s.window=7, t.window=NULL, robust=FALSE, lambda=NULL, ...)
## S3 method for class 'stlm':
forecast(object, h = 2*object$m,
level = c(80, 95), fan = FALSE, lambda=object$lambda, newxreg=NULL,
allow.multiplicative.trend=FALSE, ...)
## S3 method for class 'stl':
forecast(object, method=c("ets","arima","naive","rwdrift"),
etsmodel="ZZN", forecastfunction=NULL,
h=frequency(object$time.series)*2, level=c(80,95),
fan=FALSE, lambda=NULL, xreg=NULL, newxreg=NULL,
allow.multiplicative.trend=FALSE, ...)
```

##### Arguments

- x
- A univariate numeric time series of class
`ts`

- object
- An object of class
`stl`

or`stlm`

. Usually the result of a call to`stl`

or`stlm`

. - method
- Method to use for forecasting the seasonally adjusted series.
- modelfunction
- An alternative way of specifying the function for modelling the seasonally adjusted series. If
`modelfunction`

is not`NULL`

, then`method`

is ignored. Otherwise`method`

is used to specify the time series model - forecastfunction
- An alternative way of specifying the function for forecasting the seasonally adjusted series. If
`forecastfunction`

is not`NULL`

, then`method`

is ignored. Otherwise`method`

is used to specify the forecasting - etsmodel
- The ets model specification passed to
`ets`

. By default it allows any non-seasonal model. If`method!="ets"`

, this argument is ignored. - xreg
- Historical regressors to be used in
`auto.arima()`

when`method=="arima"`

. - newxreg
- Future regressors to be used in
`forecast.Arima()`

. - h
- Number of periods for forecasting.
- level
- Confidence level for prediction intervals.
- fan
- If
`TRUE`

, level is set to seq(50,99,by=1). This is suitable for fan plots. - lambda
- Box-Cox transformation parameter. Ignored if
`NULL`

. Otherwise, data transformed before decomposition and back-transformed after forecasts are computed. - s.window
- Either the character string ``periodic'' or the span (in lags) of the loess window for seasonal extraction.
- t.window
- A number to control the smoothness of the trend. See
`stl`

for details. - robust
- If
`TRUE`

, robust fitting will used in the loess procedure within`stl`

. - allow.multiplicative.trend
- If TRUE, then ETS models with multiplicative trends are allowed. Otherwise, only additive or no trend ETS models are permitted.
- ...
- Other arguments passed to
`forecast.stl`

,`modelfunction`

or`forecastfunction`

.

##### Details

`stlm`

takes a time series `x`

, applies an STL decomposition, and models the seasonally adjusted data using the model passed as `modelfunction`

or specified using `method`

. It returns an object that includes the original STL decomposition and a time series model fitted to the seasonally adjusted data. This object can be passed to the `forecast.stlm`

for forecasting.

`forecast.stlm`

forecasts the seasonally adjusted data, then re-seasonalizes the results by adding back the last year of the estimated seasonal component.

`stlf`

combines `stlm`

and `forecast.stlm`

. It takes a `ts`

argument, applies an STL decomposition, models the seasonally adjusted data, reseasonalizes, and returns the forecasts. However, it allows more general forecasting methods to be specified via `forecastfunction`

.

`forecast.stl`

is similar to `stlf`

except that it takes the STL decomposition as the first argument, instead of the time series.

Note that the prediction intervals ignore the uncertainty associated with the seasonal component. THey are computed using the prediction intervals from the seasonally adjusted series, which are then reseasonalized using the last year of the seasonal component. The uncertainty in the seasonal component is ignored.

The time series model for the seasonally adjusted data can be specified in `stlm`

using either `method`

or `modelfunction`

. The `method`

argument provides a shorthand way of specifying `modelfunction`

for a few special cases. More generally, `modelfunction`

can be any function with first argument a `ts`

object, that returns an object that can be passed to `forecast`

. For example, `forecastfunction=ar`

uses the `ar`

function for modelling the seasonally adjusted series.

The forecasting method for the seasonally adjusted data can be specified in `stlf`

and `forecast.stl`

using either `method`

or `forecastfunction`

. The `method`

argument provides a shorthand way of specifying `forecastfunction`

for a few special cases. More generally, `forecastfunction`

can be any function
with first argument a `ts`

object, and other `h`

and `level`

, which returns an object of class `forecast`

. For example, `forecastfunction=thetaf`

uses the `thetaf`

function for forecasting the seasonally adjusted series.

##### Value

`stlm`

returns an object of class`stlm`

. The other functions return objects of class`forecast`

.There are many methods for working with

`forecast`

objects including`summary`

to obtain and print a summary of the results, while`plot`

produces a plot of the forecasts and prediction intervals. The generic accessor functions`fitted.values`

and`residuals`

extract useful features.

##### See Also

##### Examples

```
tsmod <- stlm(USAccDeaths, modelfunction=ar)
plot(forecast(tsmod, h=36))
plot(stlf(AirPassengers, lambda=0))
decomp <- stl(USAccDeaths,s.window="periodic")
plot(forecast(decomp))
```

*Documentation reproduced from package forecast, version 6.0, License: GPL (>= 2)*