Last chance! 50% off unlimited learning
Sale ends in
loess
, acronym STL.
stl(x, s.window, s.degree = 0, t.window = NULL, t.degree = 1, l.window = nextodd(period), l.degree = t.degree, s.jump = ceiling(s.window/10), t.jump = ceiling(t.window/10), l.jump = ceiling(l.window/10), robust = FALSE, inner = if(robust) 1 else 2, outer = if(robust) 15 else 0, na.action = na.fail)
"ts"
with a frequency
greater than one."periodic"
or the span (in
lags) of the loess window for seasonal extraction, which should
be odd and at least 7, according to Cleveland et al. This has no default.NULL
, the default,
nextodd(ceiling((1.5*period) / (1-(1.5/s.window))))
, is taken.frequency(x)
which is
recommended since it prevents competition between the trend and
seasonal components. If not an odd integer its given value is
increased to the next odd one.*.jump
th value.loess
procedure.stl
returns an object of class "stl"
with components
seasonal
, trend
and remainder
."s"
,
"t"
, and "l"
smoothers.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 remainder
component is the
residuals from the seasonal plus trend fit. Several methods for the resulting class "stl"
objects, see,
plot.stl
.
plot.stl
for stl
methods;
loess
in package stats (which is not actually
used in stl
). StructTS
for different kind of decomposition.
require(graphics)
plot(stl(nottem, "per"))
plot(stl(nottem, s.window = 7, t.window = 50, t.jump = 1))
plot(stllc <- stl(log(co2), s.window = 21))
summary(stllc)
## linear trend, strict period.
plot(stl(log(co2), s.window = "per", t.window = 1000))
## Two STL plotted side by side :
stmd <- stl(mdeaths, s.window = "per") # non-robust
summary(stmR <- stl(mdeaths, s.window = "per", robust = TRUE))
op <- par(mar = c(0, 4, 0, 3), oma = c(5, 0, 4, 0), mfcol = c(4, 2))
plot(stmd, set.pars = NULL, labels = NULL,
main = "stl(mdeaths, s.w = \"per\", robust = FALSE / TRUE )")
plot(stmR, set.pars = NULL)
# mark the 'outliers' :
(iO <- which(stmR $ weights < 1e-8)) # 10 were considered outliers
sts <- stmR$time.series
points(time(sts)[iO], 0.8* sts[,"remainder"][iO], pch = 4, col = "red")
par(op) # reset
Run the code above in your browser using DataLab