Decompositions

It is useful to be able to turn a time series into components. The function stl (letter L, not numeral one) performs seasonal decomposition of a time series into seasonal, trend and irregular components using loess. First, we make a time series object, specifying the start date and the frequency (above), then use stl to decompose the series:

up<-stl(high,"periodic")

The plot function produces the data series, the seasonal component, the trend and the residuals in a single frame:

plot(up)

images

The remainder component is the residuals from the seasonal plus trend fit. The bars at the right-hand side are of equal heights (in user coordinates).

Get The R Book now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.