CS代考 Time Series Decomposition STAT317-455

Time Series Decomposition STAT317-455

Semester 2 2021
Fidelio Statistical Services
Time Series Decomposition Semester 2 2021 1 / 22

Components
To a major extent we are describing or explaining the shape of a series. In simple terms we start with
Trend Cyclic
Seasonal Residual
Long-term increase or decrease in the data. Usually from underlying temporal effects e.g. population increase, inflation
Medium term increase of decrease in the data, often with some approximate regularity e.g. related to election cycle, business cycle. I will combine this with trend from now on.
Series increases and decreases with a regular annual pattern e.g. weather-related, calendar related
Effectively random effects on the time series – hopefully white noise. Sometimes I may call it irregular as that’s the term we use at StatsNZ.
Fidelio Statistical Services Time Series Decomposition Semester 2 2021 2 / 22

Time Series Decomposition
Given these components
yt = data measurement at time t
Tt = value of trend-cycle component at time t St = value of seasonal component at time t
Rt = value of residual component at time t
We assume what we measure is some function, yt = f (St , Tt , Rt ), of these components. Our task is, given our measured time series {yt} what are our estimates for the components?
Fidelio Statistical Services Time Series Decomposition Semester 2 2021 3 / 22

Time Series Decomposition
Generally we consider two possible functions to decompose the measured time series {yt}.
Additive decomposition yt = Tt + St + Rt
To enable us to decompose the time series into its components by definition we expect the mean value of Rt over the whole time series to be zero, and over any year the mean value for St should approximately be zero. Of course at any time point t either could also be zero, but for decomposition this is not required.
Multiplicative decomposition yt = Tt × St × Rt
By definition here we expect the mean value of Rt over the whole time series to be one, and over any year the mean value for St should approximately be one. Multiplicative implies St and Rt have a percentage effect. If either is 1 at time t then it does not change the trend value.
Fidelio Statistical Services Time Series Decomposition Semester 2 2021 4 / 22

Time Series Decomposition
In previous lectures we have seen having trend and seasonal variation in a time series can make it difficult to model. The trend is the underlying long-term behaviour of the time series, so should not change much in the immediate term. The seasonal is a regular variation within the time series. When we forecast we are attempting to predict the values in the immediate term, so the trend and seasonal are nuisance components. However we need to be aware that the time series model we have,
yt = Tt + St + Rt , is an unobserved components model. That is, we have assume the time series is made of these components, but it is impossible to observe them (measure their values).
Fidelio Statistical Services Time Series Decomposition Semester 2 2021 5 / 22

Time Series Decomposition – Moving Averages
To decompose a time series into its components we use the way we defined the components. There are several ways to do this, with the one you use depending, again, on why you are investigating the time series
Let us start with estimating the trend. Since it is the medium to long-term level of the series we could start by saying the trend level at time t is the “average” level at that point. To calculate the average we use
ˆ 1 􏰋k
yt+j
By taking values before and after we are smoothing out the expected randomness of the Rt term on a point. We “move” the calculation of the average over the series, hence moving average.
Tt = m
j =−k
Fidelio Statistical Services Time Series Decomposition Semester 2 2021 6 / 22

Time Series Decomposition – Moving Averages
Simple moving averages such as these are usually of an odd order (e.g., 3, 5, 7, etc.). This is so they are symmetric: in a moving average of order
m = 2k + 1 the middle observation and k observations on either side, are averaged. But if m was even, it would no longer be symmetric, and thus not centred. The length of the MA is sometimes termed the window as it is a window through which you see the data to create the MA value for yt. The MA you use is written as a “m-term MA”.
Fidelio Statistical Services Time Series Decomposition Semester 2 2021 7 / 22

However where I work we do use even numbered MA, but we centre it by taking a moving average of the moving average. A 3 × 3-MA is where we calculate the 3-term MA series, then take a 3-term MA of that series. Technically it resolves as a 5-term MA, but the weights applied to the 5 values are not the same – though they will be symmetric. I use a
2 × 12-MA rather than a 13-term MA for monthly series at StatsNZ.
Fidelio Statistical Services Time Series Decomposition Semester 2 2021 8 / 22

Time Series Decomposition – Moving Averages
So how do we choose m? As shown it depends on how smooth you need the trend. However for series with a seasonal variation you will need m to be at least a long as the number of points in the seasonal cycle. That is, 13 for monthly or 5 for quarterly data if you suspect there is a seasonal cycle. Similarly if using daily data you would use at least a 7-term MA. Of course there are problems at the ends of the series where we do not have all the required values, but I will come back to that.
Fidelio Statistical Services Time Series Decomposition Semester 2 2021 9 / 22

Time Series Decomposition – Seasonal Adjustment
Seasonal adjustment is estimating the seasonal component, then removing it from the series. That is for additive decomposition yt − St = Tt + Rt , multiplicative yt/St = Tt × Rt .
We use estimates of S based on past values to seasonally adjust a current value. But seasonally adjusted series reflect remainders as well as trend. A seasonally adjusted series will generally not be very smooth so using it to identify a downturn or upturn is not a very good idea. This is particularly noticeable when you have outliers.
Fidelio Statistical Services Time Series Decomposition Semester 2 2021 10 / 22

Time Series Decomposition – Methods
This approach to time series has been around since at least the 1920’s and there is a decomposition function in R. It is not recommended as it assumes seasonal variation does not change over time, plus does not provide MA values at the beginning and end of the series.
Since the 1920’s much work has been done and there are better ways, broadly 3 common methods.
1 X-11 decomposition – more correctly the Census II method. Introduced in 1957 and developed continuously since then. Currently StatsNZ uses X13-ARIMA-SEATS. Available in seasonal package
2 TRAMO/SEATs decomposition. Introduced in 1990’s and used by some official statistics agencies. Available in seasonal package
3 STL decomposition. Introduced in 1983 and in base R – no need to install a package.
Fidelio Statistical Services Time Series Decomposition Semester 2 2021 11 / 22

Time Series Decomposition – X-11 Approach
Advantages
Relatively robust to outliers.
Most official seasonally adjusted series produced by it, so widely tested and used.
Can be automated in terms of choices for trend and seasonal MA
Disadvantages
No prediction or confidence intervals, though not designed to forecast. No underlying model
Can only be used for monthly or quarterly data
Fidelio Statistical Services Time Series Decomposition Semester 2 2021 12 / 22

Time Series Decomposition – X-11 Approach
X-11 until late 70’s, then X-12-ARIMA, X-13-ARIMA and latest X13-ARIMA-SEATS
later versions allow adjustments for trading days and other explanatory – exogenous – variables
Know outliers can be omitted
Level shifts and ramp effect can be modelled
Missing values can be estimated and replaced
Moving holiday factors (e.g. Easter, Chinese NY) can be modelled and estimated.
Fidelio Statistical Services Time Series Decomposition Semester 2 2021 13 / 22

Time Series Decomposition – SEATS Approach
Advantages
Model-based
Smooth trend estimate
Slightly better estimates at end points
Disadvantages
Can only be used for monthly or quarterly data
Fidelio Statistical Services Time Series Decomposition Semester 2 2021 14 / 22

Time Series Decomposition – STL Approach
STL: “ Seasonal and Trend decomposition using Loess”. It is very versatile and robust to outliers and other oddities – LOESS was developed for that.
Will handle any type of seasonality
Rates of change of seasonal and trend components under more control by user.
Only decomposes to 3 classic unobserved components, which are additively combined.
Fidelio Statistical Services Time Series Decomposition Semester 2 2021 15 / 22

Time Series Decomposition – Some final comments
Decomposition is a very good tool to have, particularly for EDA.
If you have seasonality it is often useful to do your analysis on the seasonally adjusted series. While you can directly put it into your t.s. model it there are difficulties with allowing for changing seasonality.
If the level of your series stays mainly constant you have no need to worry about trend. However this is rare, so usually you want to “detrend” the series, either indirectly – e.g. differencing – or by directly estimating the trend.
One difficulty is defining what a trend is – i.e. how “bendy” do you want it to be?
Fidelio Statistical Services Time Series Decomposition Semester 2 2021 16 / 22

Time Series Decomposition – Some final comments
Since you are “averaging” how much data you need for stability depends on the size of the residual. The more variation there is, the more data you need to ensure MA at time t is not too different to MA at times t − 1 and t + 1
Economists rather like the Hodrick-Prescott filter. Be aware of what main purpose of the H-P filter is to primarily separate out the trend and the cyclic components.
When using ARMA models the MA is also “moving average”, but is not the same thing.
Fidelio Statistical Services Time Series Decomposition Semester 2 2021 17 / 22

Time Series Analyses – Some further Information
What length MA you use depends partly on how much smoothness you want. There are methodological ways to do this which require working in the frequency-domain and thus examining band-pass filters. There are two approaches to looking at time series
In the time domain, which is what we will be doing mainly
In the frequency domain, which is common in physical sciences and engineering
Fidelio Statistical Services Time Series Decomposition Semester 2 2021 18 / 22

Time Series Analyses – Frequency Domain
The starting point for frequency domain analysis is the Fourier Transform. It can be shown that any time series can be represented as the sum of a infinite sine waves, and well approximated in many cases by a small number. Here is an example of a sine wave which is identified by the its amplitude and its frequency or period. It’s how music is stored on your digital device.
Fidelio Statistical Services Time Series Decomposition Semester 2 2021 19 / 22

Time Series Analyses – Frequency Domain
So you can build a time series from sine waves by the reverse, taking a measured time series and representing it as a set of sine waves is trickier. You have to put the time series through a spectrum function to generate the periodogram. From Wikipedia
In signal processing, a periodogram is an estimate of the spectral density of a signal. … Today, the periodogram is a component of more sophisticated methods (see spectral estimation). It is the most common tool for examining the amplitude vs frequency char- acteristics of FIR filters and window functions. FFT spectrum an- alyzers are also implemented as a time-sequence of periodograms.
Fidelio Statistical Services Time Series Decomposition Semester 2 2021 20 / 22

Time Series Analyses – Frequency Domain
Here is the periodogram for QGDP series. It is quarterly, 4 values per cycle.
Notice the peak in the middle? That is the quarterly seasonal cycle in
QGDP.
Fidelio Statistical Services Time Series Decomposition Semester 2 2021 21 / 22

Time Series Analyses – Frequency Domain and filters
When I talk about filters, a filter is a function that “filters out” certain frequencies. Examples of some filters – what frequencies are removed when I use certain MA – are here:
Fidelio Statistical Services Time Series Decomposition Semester 2 2021 22 / 22