Learn R Programming

tsforecast (version 1.3.0)

tsdecomp: Decompose a Time Series

Description

Decompose a time series into trend, cyclical, seasonal and irregular components. Deals with additive or multiplicative components.

Usage

tsdecomp(
  x,
  type = c("additive", "multiplicative"),
  trend.method = c("lm", "loess"),
  tcc.order = 3,
  x.name = NULL,
  show.plot = TRUE,
  ...
)

# S3 method for tsdecomp print( x, decomp.incl = c("all", "tc", "tcc", "cc", "detrend", "ic", "scadj", "sc", "sceffect"), ... )

# S3 method for tsdecomp plot( x, plot.incl = c("all", "tc", "tcc", "cc", "detrend", "ic", "scadj", "sc", "sceffect"), ... )

Value

An object of class "tsdecomp" with following components:

x

original series data

x.time

list of time in which the series values were observed.

x.timegap

time gap between the series and forecasted values.

x.name

name of the time series for which forecasts was requested.

trend

value of the trend component for each observation.

cycle

value of the cyclical component for each observation.

trend.cycle

trend-cyclical component value of each observation.

detrended

value of each observation after removing the trend component.

seasonal

value of the seasonal component for each observation.

seasonal.adjusted

value of each observation after removing the seasonal component

random

value of the irregular component for each observation.

seasonal.effect

value expressing the estimated overall effect of each season in the time series.

type

type of the time series decomposition.

Arguments

x

a time series for which decomposition is required or a `tsdecomp` object.

type

type of the time series components. Available options are `additive` and `multiplicative`. Can be abbreviated. Default is `additive`.

trend.method

estimating method of the trend. Available options are `lm` (linear) and `loess` (non-linear). Default is `lm`.

tcc.order

moving average order for the estimation of the trend-cycle component.

x.name

name of the series. If omitted here, the series name found by tsname() will be taken over here. If tsname() is NULL, the variable name will be used instead. Default is NULL.

show.plot

logical. If TRUE, forecasting plot will be displayed directly. Default is TRUE.

...

parameter values that can affect the time series decomposition plots.

decomp.incl

time series components that should be printed. Available options are `all` (default), `tc` (trend), `tcc` (trend-cycles), `tcc` (cycles), `detrend`, `ic` (irregular), `scadj` (seasonally adjusted), `sc` (seasonality), and `sceffect` (seasonal effects).

plot.incl

time series components that should be plotted. Available options are `all` (default), `tc` (trend), `tcc` (trend-cycles), `tcc` (cycles), `detrend`, `ic` (irregular), `scadj` (seasonally adjusted), `sc` (seasonality), and `sceffect` (seasonal effects). Ignored if show.plot = FALSE.

Author

Ka Yui Karl Wu

Details

The additive model used is: $$Y_t = T_t + C_t + S_t + I_t$$ The multiplicative model used is: $$Y_t = T_t \cdot C_t \cdot S_t \cdot I_t$$ The function first determines the trend-cycle component using a moving average, and removes it from the time series. Then, the seasonal figure is computed by averaging, for each time unit, over all periods. The seasonal figure is then centred. Finally, the error component is determined by removing trend and seasonal figure (recycled as needed) from the original time series.

This only works well if `x` covers an integer number of complete periods.

The function `plot` generates the following plots:

Trenda time series line plot together with a trend line.
Trend-Cyclesa time series line plot together with the trend-cycle component (moving averages).
Cyclesa line plot of the trend-cycle component (moving averages).
Detrendeda line plot of the time series after removing the trend component.
Irregulara line plot of the irregular component.
Seasonally Adjusteda line plot of the time series after removing the seasonal component.
Seasonala line plot of the seasonal component.
Seasonal Effecta line plot of the overall estimated effect of each season in the time series.

References

Hyndman, R. J., & Athanasopoulos, G. (2021). Forecasting: Principles and practice (3rd ed.). OTexts.
https://otexts.com/fpp3/

Kendall, M., & Stuart, A. (1983) The Advanced Theory of Statistics, Vol.3, Griffin. pp. 410-414.

Examples

Run this code
tsdecomp(airport$Travellers, type = "multiplicative")

Run the code above in your browser using DataLab