12
$\begingroup$

I plotted with following code with stl (Seasonal Decomposition of Time Series by Loess) function:

plot(stl(ts(rnorm(144), frequency=12), s.window="periodic"))

It shows signficant seasonal variation with random data put in code above (rnorm function). Signficant variation is seen every time this is run, though the pattern is different. Two such patterns are shown below:

enter image description here

enter image description here

How can we rely on stl function on some data when it shows seasonal variation. Does this seasonal variation need to be seen in view of some other parameters? Thanks for your insight.

The code has been taken from this page: Is this an appropriate method to test for seasonal effects in suicide count data?

$\endgroup$
3
  • 1
    $\begingroup$ That happens because there are "patterns" in random data, if your fitting technique has enough parameters. $\endgroup$
    – bill_080
    Commented Apr 19, 2015 at 15:22
  • 4
    $\begingroup$ The term "significant" here doesn't seem to reflect any kind of significance testing. $\endgroup$
    – Nick Cox
    Commented Apr 21, 2015 at 11:24
  • 1
    $\begingroup$ Stl is a nonparametric data driven method, so there is no way to quantify presence absence of seasonal uncertainties via significance testing. $\endgroup$
    – forecaster
    Commented Apr 21, 2015 at 11:32

2 Answers 2

15
$\begingroup$

Loess decomposition is intended to smooth the series by applying averages to the data so that it collapses into components, e.g. the trend or seasonal, that are interesting for the analysis of the data. But this methodology is not intended to do a formal test for the presence of seasonality.

Although in your example stl returns a smoothed pattern of seasonal periodicity, this pattern is not relevant to explain the dynamics of the series. In order to see that, we can compare the variance of each component with respect to the variance of the original series.

set.seed(123)
x <- ts(rnorm(144, sd=1), frequency=12)
a <- stl(x, s.window="periodic")
apply(a$time.series, 2, var) / var(x)
#   seasonal      trend  remainder 
# 0.07080362 0.07487838 0.81647852 

We can see that it is the remainder what explains most of the variance in the data (as we would expect for a white noise process).

If we take a series with seasonality, the relative variance of the seasonal component is much more relevant (although we don't have a straightforward way to test it since loess is not parametric).

y <- diff(log(AirPassengers))
b <- stl(y, s.window="periodic")
apply(b$time.series, 2, var) / var(y)
#    seasonal       trend   remainder 
# 0.875463620 0.001959407 0.117832537 

The relative variances indicate that seasonality is the main component explaining the dynamics of the series.


A careless look at the plot from stl can be deceptive. The nice pattern returned by stl may make us think that a relevant seasonal pattern can be identified in the data, but a closer look may reveal that it's not actually the case. If the purpose is to decide on the presence of seasonality, loess decomposition can be useful as a preliminary view but it should be complemented with other tools.

$\endgroup$
9
  • 1
    $\begingroup$ In your AirPassengers example, there is no trend coming in output, while there is a clear trend on plot(AirPassengers). The trend comes to 0.86 (with seasonal of only 0.1) if "diff(log(AirPassengers))" statement is removed. What should be done? $\endgroup$
    – rnso
    Commented Apr 21, 2015 at 13:38
  • $\begingroup$ I gave an example that is numerically clear. In practice, just by comparing the variance of the smoothed components may not be enough to reach a conclusion about the presence of seasonality. For example, as you found in this case, if the trend is not removed by taking differences, the variance of the trend dominates the variance of the seasonal component. The question is: is a relative variance of 0.1 large enough to consider this component relevant? The problem is that, based on loess, there isn't a straightforward way to test whether the variance of the component is significant. $\endgroup$
    – javlacalle
    Commented Apr 21, 2015 at 14:25
  • $\begingroup$ Like I said, what we should do in this and other cases is to use other methods to test for the presence of seasonality. See for example the second part of my answer here. Once we have concluded that seasonality is present in the data, we can use loess to obtain the pattern of this component. $\endgroup$
    – javlacalle
    Commented Apr 21, 2015 at 14:28
  • $\begingroup$ Just for more clarification, how does relative variance show how much a part of the decomposition plays in the overall data? I.E 70% seasonal, 20% trend. etc. $\endgroup$
    – Ted Mosby
    Commented Feb 7, 2017 at 21:45
  • 2
    $\begingroup$ @TedMosby The variance is a measure of variability/dispersion in the data. The sum of the variances of the components (e.g., trend, seasonal) and the variance of the remainder add up to the variance of the original series. In this way, by comparing the variance of a component with the variance of the original series, we can get an idea of how much relevant the component is (i.e., how much of the variability in the data is explained by the component). $\endgroup$
    – javlacalle
    Commented Feb 8, 2017 at 21:20
2
$\begingroup$

In a similar vein I have seen the utilization of Fourier Models to non-seasonal data , forcing a seasonal structure into the fit and forecast values, causing a similar (gasp !) result. Fitting a presumed model gives the user what he is imposing/presuming which is not always what good analytics would suggest/deliver.

$\endgroup$
2
  • 2
    $\begingroup$ stl() is not based on Fourier ideas. Although I have yet to see anyone advocating "mindless" analysis, note that any model family fitted could be regarded as imposed or presumed. The question is how far any procedure offers scope for users to realise if and how it works badly for a particular dataset. $\endgroup$
    – Nick Cox
    Commented Apr 21, 2015 at 11:27
  • $\begingroup$ @NickCox quite true .... $\endgroup$
    – IrishStat
    Commented Apr 21, 2015 at 11:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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