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

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

## Arguments

formula Decomposition specification (see "Specials" section). The type of seasonal component. Can be abbreviated. Other arguments passed to stats::decompose().

## Value

A fabletools::dable() containing the decomposed trend, seasonality and remainder from the classical decomposition.

## 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

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