Skip to content

Instantly share code, notes, and snippets.

@christophsax
Created September 21, 2016 15:38
Show Gist options
  • Save christophsax/713ba85ec7540541a140cb000189e190 to your computer and use it in GitHub Desktop.
Save christophsax/713ba85ec7540541a140cb000189e190 to your computer and use it in GitHub Desktop.
An easy way to share an X-13 story
---
title: "The X-11 Method"
subtitle: A sightly more detailed subtitle here
author:
- name: "James Livsey"
affiliation: United States Census Bureau
abstract: >
An abstract of less than 150 words.
output: x13story::x13story
---
```{r, echo = FALSE, fig.width = 11, fig.height = 6}
library(x13story)
m <- seas(AirPassengers, x11 = "")
x13view(m, series = "main")
```
## Overview
### The X-11 method
The X-11 method is an iterative process, using appropriate moving averages to
decompose a time series into trend/cycle, seasonal, and irregular components:
trend $T_t$
: long-term evolution of a time series
cycle $C_t$
: Smooth movement around the trend usually of longer period than the seasonal
component. The X-11 method does not distinguish between trend and cycle and is
usually refered to as trend/cycle component of a time series.
seasonal $S_t$
: Intra-year fluctuations repeated regularly year after year
irregular $I_t$
: Random fluctuations not explained by previous components
### Additive vs Multiplicative Decomposition
Given an original time series $X_t$
Additive decomposition:
$$X_t = T_t + S_t + I_t$$
Multiplicitive decomposition:
$$X_t = T_t \cdot S_t \cdot I_t$$
How is this X-11 decomposition performed?
```{r, echo = FALSE, fig.width = 11, fig.height = 6}
x13view(m, series = "x11.trend")
```
## Estimate a trend
We omit the specific choice of weights for each moving average [to learn more
about this see another "story"] and instead will refer to a moving averages by
whether or not they estimate a trend (trend moving average) or a seasonal
component (seasonal moving average)
### Apply trend Moving Average
The first component that gets estimated is the trend/cycle component. It gets
estimated by applying a moving average filter speficially for trends. An example
of an estimated trend/cycle component is displayed at the right.
### After Estimating Trent $T_t$ Subtract it!
Here inlies the main concept of the X-11 method. By subtracting off our first
estimate of the trend we in effect have a series that is free of long-term
movement. The only remaining movement should be either seasonal or irregular.
```{r, echo = FALSE, fig.width = 11, fig.height = 6}
x13view(m, series = "x11.seasonal")
```
## Estimate seasonal component in the de-trended series
Recall we have a detrended series that has just had the estimated trend removed.
Again we omit the detail of exactly how a seasonal moving average filter looks
and acts.
Notice the *detrended* series is void of long term drift and is centered roughly
around zero
### Apply Seasonal Moving Average Filter
The second component that will be estimated is the seasonal component. An
example of the estimated seasonal component (estimated from the de-trended
series) is displayed at the right
### We also have the Irregular series now too
By subtracting the newly estimated seasonal component from the de-trended
series, we have in essence an original estimate of the irregular component.
```{r, echo = FALSE, fig.width = 11, fig.height = 6}
x13view(m, series = "x11.seasadj")
```
## Now we have our inital estimates
The first run through the X-11 moving average filters provides us with initial
estimates of the trend, seasonal and irregualar components of our original
time series.
### First Estimate of Seasonally Adjusted Series
From these estimated components, the first estimate of the seasonally adjusted
series is given as:
$A_t = \widehat{T_t} + \widehat{I_t}$
```{r, echo = FALSE, fig.width = 11, fig.height = 6}
x13view(m, series = "x11.irregular")
```
## Estimate extreme values
The irregular estimates give us a first glimpse into identifying extreme values
and other regression typ effects...
### Now estimate any nessesary regression effects
Since we have removed all trend and seasonallity, what is left are the irregular
components. From these estimated values we can identify extremes and outliers.
The irregular values are plotted along with some outliers idetified.
There are other effects that can be found from estimated irregular series. This
includes trading day (TD) and holiday effects.
### Trading Day effects
Measures the impact of the day-of-the-week composition of a month. For example,
January 2016 will have 5 Fridays, 5 Saturdays, and 5 Sundays. While January 2013
had 4 Fridays, 4 Saturdays and 4 Sundays. This can have a dramatic effect on a
seasonal adjustment
### Moving Holiday Effects
Holidays that occur at the same time every year will be included in the seasonal
component estimates. However, some holidays effect a time series and move from
month-to-month e.g.) Easter which can call March or April depending on the
calendar
```{r, echo = FALSE, fig.width = 11, fig.height = 6}
x13view(m, series = "x11.seasadj")
```
## Now iterate the method
*The beauty of the X11 method is through iteration comes improved estimates of each trend, seasonal and irregular components.*
### A "less seasonal" trend
By construction of the moving average filters, the first estimates of the
seasonally adjusted series $A_t$, MUST have less sesaonality than the original
series $X_t$.
### Repeat previous methodology on $A_t$
1. Estimate trend: use a trend moving average filter
2. Estimate seasonal and irregular: use seasonal moving average filter
3. Identify Extreme observation and calendar effects
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment