How to Seasonally Adjust a Time Series in R

December 3, 2015 One Comment math

seasonal-adjustment

What is seasonal adjustment? Why is it important, and when should we use it? How should it be done? In this article, we will answer these and many other questions related to seasonality in data.

Why Seasonally Adjust Data ?

Many industries experience fluctuations in various metrics based on the time of year. This means that it is not possible to effectively assess performance by comparing data from one time of year to data from another. Furthermore, these seasonal fluctuations can sometimes be so large that they can mask important business trends hiding in the data.

Consider the sales of an ice cream parlor, for example. It is normal for this sort of business to have higher sales during the warm summer months than during the winter, so you cannot compare January’s sales figures to those from July. Furthermore, the oscillations due to seasonality can be so large that they make business trends hard to see. If sales are up in the most recent month of July, for example, was this due to seasonal variation or an actual increase in sales? To get these answers we need to remove “seasonality” from the data, a process called seasonal adjustment.

Airline Passenger Numbersair-passager-1949-1960

Airline Passenger Numbers – Seasonally Adjustedseasonaly-adjusted-air-passager-1949-1960

The images above show airline passenger numbers from 1949 to 1960. The chart on the left shows the raw data, which illustrates substantial seasonality: people travel more in the summer. The seasonal variations make it difficult to observe potentially noteworthy fluctuations. The seasonally adjusted chart on the right has removed the seasonal patterns from the raw data, allowing us to see the actual trend in passenger activity over time. In so doing, we’ve exposed an anomaly in the year 1960 that was not readily noticeable in the raw data.

Airline Passenger Numbers
air-passager-1996-2015

Airline Passenger Numbers – Seasonally Adjustedseasonaly-adjusted-air-passager-1996-2015

Sometimes an anomaly is so large that it is obvious even in the raw data. For example, the graph above left shows airline passenger numbers from 1996 to 2015. The severe drop in late 2001 was due to the 9/11 attack on the United States, which caused all of North American air space to be closed for several days. But the seasonally adjusted time series on the right makes some more subtle variances easier to see, such as the dip starting in 2008 caused by the Great Recession.

How to Seasonally Adjust Time Series

To seasonally adjust a time series we must first find the seasonality. Performing a time series decomposition will “break down” a time series into multiple sub-time series, one of which will contain the seasonality. The decompose( ) function in R does the heavy lifting here, but there are two requirements to use this function:

  • You must know if you’re dealing with an additive or multiplicative model; read about time series decomposition to know which one to use.
  • You must know the period of the seasonality. This may be a fixed period such as daily, weekly, monthly, or yearly. If unknown, it is also possible to detect the seasonality mathematically.

Another article can help you understand how to perform a time series decomposition by explaining seasonal adjustment formulas:

Additive:
Seasonally Adjusted = Time series – Seasonal

Multiplicative:
Seasonally Adjusted = Time series / Seasonal

This seasonality is annual with four data points per years (frequency = 4). As an example, here is the seasonally adjusted time series for Australian beer production:

Australian Beer Production – Seasonally Adjustedseasonaly-adjusted-beer

This is annual seasonality with 12 data points per year (frequency = 12). Here again, as an example, is the seasonally adjusted time series for airline passengers:

Airline Passenger Numbers – Seasonally Adjustedseasonaly-adjusted-air-passager-1996-2015

Conclusion

Seasonally adjusted time series provide a way to understand the underlying trends in data by removing the “noise” of seasonal fluctations so outliers and anomalies are easier to see. Just as removing seasonality makes problems easier to spot with your eyes, it also makes them easier for the computer. This is one of many techniques we use at Anomaly.io to automatically detect problems in monitored data.

Monitor & detect anomalies with Anomaly.io

SIGN UP
  • Juan

    Esto no me sirvió para nada no muestran como ajustar la serie con estacionalidad.

help with term papers