\Header{stl}{Seasonal Decomposition of Time Series by Loess}
\alias{plot.stl}{stl}
\alias{print.stl}{stl}
\keyword{ts}{stl}
\begin{Description}\relax
Decompose a time series into seasonal, trend and irregular
components.\end{Description}
\begin{Usage}
\begin{verbatim}
stl(x, s.window = NULL, s.degree = 0, t.window = NULL, t.degree = 1,
    robust = FALSE, na.action = na.fail)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] A univariate time series to be decomposed.
This should be an object of class \code{"ts"} with a frequency
greater than one.
\item[\code{s.window}] Either the string \code{"periodic"} or the span (in
lags) of the loess window for seasonal extraction, which should
be odd.  This has no default.
\item[\code{s.degree}] Degree of locally-fitted polynomial in seasonal
extraction.  Should be zero or one.
\item[\code{t.window}] The span (in lags) of the loess window for trend
extraction, which should be odd.  There is a reasonable
default.
\item[\code{t.degree}] Degree of locally-fitted polynomial in trend
extraction.  Should be zero or one.
\item[\code{robust}] Should robust fitting be used in the \code{loess}
procedure?
\item[\code{na.action}] Action on missing values.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
The seasonal component is found by \emph{loess} smoothing the
seasonal sub-series (the series of all January values, \ldots); if
\code{s.window = "periodic"} smoothing is effectively replaced by
taking the mean. The seasonal values are removed, and the remainder
smoothed to find the trend. The overall level is removed from the
seasonal component and added to the trend component. This process is
iterated a few times.  The \code{remainder} component is the
residuals from the seasonal plus trend fit.\end{Details}
\begin{Value}
An object of class \code{"stl"} with components
\begin{ldescription}
\item[\code{time.series}] a multiple time series with columns
\code{seasonal}, \code{trend} and \code{remainder},
\item[\code{weights}] the final robust weights (all one if fitting is not
done robustly,
\item[\code{call}] the matched call.
\end{ldescription}
\end{Value}
\begin{Note}\relax
This is similar to but not identical to the \code{stl} function in
S-PLUS. The \code{remainder} component given by S-PLUS is the sum of
the \code{trend} and \code{remainder} series from this function.\end{Note}
\begin{Author}\relax
B.D. Ripley; Fortran code by Cleveland \emph{et al.} (1990) from
\file{netlib}.\end{Author}
\begin{References}\relax
R. B. Cleveland, W. S. Cleveland, J.E.  McRae, and I. Terpenning
(1990).
STL:  A  Seasonal-Trend  Decomposition  Procedure Based on Loess.
\emph{Journal of Official Statistics}, \bold{6}, 3--73.\end{References}
\begin{SeeAlso}\relax
\code{\Link{loess}} in package \file{modreg} (which is not
actually used in \code{stl}).\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
data(nottem)
plot(stl(nottem, "per"))
data(co2)
plot(stl(log(co2), s.window=21))
## linear trend, strict period.
plot(stl(log(co2), s.window="per", t.window=1000))
\end{ExampleCode}
\end{Examples}

