In the last post on the changepoint package, I concluded with a brief example of time series decomposition with the “decompose” command. After further reading, I discovered the “stl” command, which to me appears a superior method. STL stands for “Seasonal Decomposition of Time Series by LOESS”. By decomposition, we mean breaking it down into trend, seasonal and irregular (noise) components.
Let’s try it on the same data set as the past two week, looking at it from 2008 until now.
#put the data into a time series
house.ts = ts(Value, frequency=12, start=c(1968,1), end=c(2013,6))
#subset the time series from 2008 forward using window commd
> house2 = window(house.ts, start=c(2008,1), end=c(2013, 6))
# fit the stl model using only the s.window argument
> fit = stl(house2, s.window=”periodic”)
# another fit this time setting the t.window argument, which changes the number of lags used in the LOESS smoothing parameters
> fit2 = stl(house2, s.window=”periodic”, t.window=15)
By changing the smoothing parameter in fit2 with the t.window argument, we have put slightly more of the variation in the trend and less in the seasonal component (you can see the effect in R by plotting the different fits). What is clear is the fact that examining the residuals in the remainder component shows us clear outliers in early 2008 and the summer of 2010.
We could mess around with the parameters further, but I don’t think it would dramatically improve what we already have here.
Now, here is the question. If we make this time series stationary, will the seasonality still be relevant?