# Why is stl function giving significant seasonal variation with random data

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:

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?

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

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.

• 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? – rnso Apr 21 '15 at 13:38
• 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. – javlacalle Apr 21 '15 at 14:25
• 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. – javlacalle Apr 21 '15 at 14:28
• 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. – Ted Mosby Feb 7 '17 at 21:45
• @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). – javlacalle Feb 8 '17 at 21:20

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.

• 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. – Nick Cox Apr 21 '15 at 11:27
• @NickCox quite true .... – IrishStat Apr 21 '15 at 11:31