Decompose a time series into seasonal, trend and irregular components using moving averages. Deals with additive or multiplicative seasonal component.

classical_decomposition(.data, formula, type = c("additive",
  "multiplicative"), ...)

Arguments

.data

A tsibble.

formula

Decomposition specification (see "Specials" section).

type

The type of seasonal component. Can be abbreviated.

...

Other arguments passed to decompose.

Details

The additive model used is: $$Y_t = T_t + S_t + e_t$$ The multiplicative model used is: $$Y_t = T_t\,S_t\, e_t$$

The function first determines the trend component using a moving average (if filter is NULL, a symmetric window with equal weights is used), 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 centered. 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.

Specials

season

The season special is used to specify seasonal attributes of the decomposition.
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").

Examples

USAccDeaths %>% as_tsibble %>% classical_decomposition(value)
#> # A dable: 72 x 6 [1M] #> # Classical Decomposition: value = trend + seasonal + random #> index value trend seasonal random season_adjust #> <mth> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 1973 Jan 9007 NA -806. NA 9813. #> 2 1973 Feb 8106 NA -1523. NA 9629. #> 3 1973 Mar 8928 NA -741. NA 9669. #> 4 1973 Apr 9137 NA -515. NA 9652. #> 5 1973 May 10017 NA 340. NA 9677. #> 6 1973 Jun 10826 NA 745. NA 10081. #> 7 1973 Jul 11317 9599. 1679. 38.2 9638. #> 8 1973 Aug 10744 9500. 986. 258. 9758. #> 9 1973 Sep 9713 9416. -109. 406. 9822. #> 10 1973 Oct 9938 9349. 264. 325. 9674. #> # … with 62 more rows
USAccDeaths %>% as_tsibble %>% classical_decomposition(value ~ season(12), type = "mult")
#> # A dable: 72 x 6 [1M] #> # Classical Decomposition: value = trend * seasonal * random #> index value trend seasonal random season_adjust #> <mth> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 1973 Jan 9007 NA 0.908 NA 9922. #> 2 1973 Feb 8106 NA 0.825 NA 9829. #> 3 1973 Mar 8928 NA 0.915 NA 9762. #> 4 1973 Apr 9137 NA 0.941 NA 9713. #> 5 1973 May 10017 NA 1.04 NA 9633. #> 6 1973 Jun 10826 NA 1.09 NA 9960. #> 7 1973 Jul 11317 9599. 1.19 0.989 9491. #> 8 1973 Aug 10744 9500. 1.11 1.02 9656. #> 9 1973 Sep 9713 9416. 0.987 1.05 9843. #> 10 1973 Oct 9938 9349. 1.03 1.03 9649. #> # … with 62 more rows