\HeaderA{decompose}{Classical Seasonal Decomposition by Moving Averages}{decompose}
\aliasA{plot.decomposed.ts}{decompose}{plot.decomposed.ts}
\keyword{ts}{decompose}
\begin{Description}\relax
Decompose a time series into seasonal, trend and irregular components
using moving averages.  Deals with additive or multiplicative
seasonal component.
\end{Description}
\begin{Usage}
\begin{verbatim}
decompose(x, type = c("additive", "multiplicative"), filter = NULL)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] A time series.
\item[\code{type}] The type of seasonal component. Can be abbreviated.
\item[\code{filter}] A vector of filter coefficients in reverse time order (as for
AR or MA coefficients), used for filtering out the seasonal
component. If \code{NULL}, a moving average with symmetric window is
performed.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
The additive model used is:
\deqn{Y_t = T_t + S_t + e_t}{}
The multiplicative model used is:
\deqn{Y_t = T_t\,S_t\, e_t}{}

The function first determines the trend component using a moving
average (if \code{filter} is \code{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.
\end{Details}
\begin{Value}
An object of class \code{"decomposed.ts"} with following components:
\begin{ldescription}
\item[\code{seasonal}] The seasonal component (i.e., the repeated seasonal figure)
\item[\code{figure}] The estimated seasonal figure only
\item[\code{trend}] The trend component
\item[\code{random}] The remainder part
\item[\code{type}] The value of \code{type}
\end{ldescription}
\end{Value}
\begin{Note}\relax
The function \code{\LinkA{stl}{stl}} provides a much more sophisticated
decomposition.
\end{Note}
\begin{Author}\relax
David Meyer \email{David.Meyer@wu-wien.ac.at}
\end{Author}
\begin{References}\relax
M. Kendall and A. Stuart (1983)
The Advanced Theory of Statistics, Vol.3,
\emph{Griffin}, 410--414.
\end{References}
\begin{SeeAlso}\relax
\code{\LinkA{stl}{stl}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
require(graphics)

m <- decompose(co2)
m$figure
plot(m)

## example taken from Kendall/Stuart
x <- c(-50, 175, 149, 214, 247, 237, 225, 329, 729, 809, 
       530, 489, 540, 457, 195, 176, 337, 239, 128, 102, 232, 429, 3, 
       98, 43, -141, -77, -13, 125, 361, -45, 184)
x <- ts(x, start = c(1951, 1), end = c(1958, 4), frequency = 4)
m <- decompose(x)
## seasonal figure: 6.25, 8.62, -8.84, -6.03
round(decompose(x)$figure / 10, 2)
\end{ExampleCode}
\end{Examples}

