9
$\begingroup$

I am doing time series analysis using R. I have to decompose my data into trend, seasonal and random component. I have weekly data for 3 years. I have found two functions in R -- stl() and decompose(). I have read that stl() is not good for multiplicative decomposition. Can anybody tell me in what scenario these functions can be used?

$\endgroup$
  • 1
    $\begingroup$ You will need to provide some context to your problem, otherwise we'll have to migrate to stack exchange or close with the recommendation you try ?stl and ?decompose. $\endgroup$ – AdamO Feb 9 '14 at 22:03
4
$\begingroup$

I would say STL. STL does trend and seasonal see: http://www.wessa.net/download/stl.pdf

Decompose only does seasonal see the documentation here: http://stat.ethz.ch/R-manual/R-devel/library/stats/html/decompose.html

When you work with them be sure to include your trend type (multiplicative, additive) and season type (multiplicative, additive). Trends can also sometimes have a damping factor too.

By multiplicative decomposition I assume you mean in the case for trend. You are not likely to use multiplicative decomposition unless you are decomposing a exponential growth function.

$\endgroup$
  • $\begingroup$ Multiplicative decomposition in the simple case is where the underlying model is Y = trend * seasonal * error. Multiplicative models come up in non-exponential contexts. For example with sales you have a certain level of traffic and a certain conversion rate, and so the seasonal component varies proportionally with the trend. Solution is the one Natalie describes. $\endgroup$ – Willie Wheeler Aug 7 '15 at 17:19
3
$\begingroup$

Disadvantages of decompose function in R:

  1. The estimate of the trend is unavailable for the first few and last few observations.
  2. It assumes that the seasonal component repeats from year to year.

So I would prefer STL. It is possible to obtain a multiplicative decomposition by first taking logs of the data and then back-transforming the components.

$\endgroup$
0
$\begingroup$

STL is a more advanced technique to extract seasonality, in the sense that is allows seasonality to vary, which is not the case in decompose.

To get an understanding at how STL works:

  • the algorithm estimates every seasonal sub-serie (in a 7-day seasonality, it will estimate 7 sub-series: the Monday time serie, the Tuesday time serie, etc.),
  • it will then estimate the local seasonality by running a loess regression on every sub-serie.

This allows to capture the varying effect in the seasonality. If you do not want your seasonality to vary (in other words the estimated effect of each sub-serie will remain constant across the whole time serie), you can specify the seasonal window to be infinite or "periodic". This is equivalent to average each sub-serie and giving an equal weight to all points (you do not have any "local" effect anymore). decompose is essentially the same, as the seasonal sub-components will remain constant across your whole time serie, which is a special configuration of STL.

This is pretty well explained here: https://www.otexts.org/fpp/6/1.

STL estimates seasonality in an additive way. As explained a few pages later in the previous source, you can estimate seasonality in a multiplicative way by resorting to log transformation (or Cox-Box transformation).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.