# decompose

##### Classical Seasonal Decomposition by Moving Averages

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

- Keywords
- ts

##### Usage

`decompose(x, type=c("additive", "multiplicative"), filter=NULL)`

##### Arguments

- x
- A time series.
- type
- The type of seasonal component. Can be abbreviated.
- filter
- A vector of filter coefficients in reverse time order (as for
AR or MA coefficients), used for filtering out the seasonal
component. If
`NULL`

, a moving average with symmetric window is performed.

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

##### Value

- An object of class
`"decomposed.ts"`

with following components: seasonal The seasonal component (i.e., the repeated seasonal figure) figure The estimated seasonal figure only trend The trend component random The remainder part type The value of `type`

##### Note

This function is a modification of the `decompose`

function in the `stats`

package. In this version, the seasonal component is not incorrectly truncated, the trend is correctly calculated for odd frequencies, and the data is returned as part of the object. It is hoped that this function will replace the version in `stats`

package, and then it will be removed from the `forecast`

package.

##### References

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

##### See Also

##### Examples

```
m <- decompose(co2)
plot(m)
```

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