代写代考 QBUS6840 Lecture 03 Time Series Decomposition and Moving Average

QBUS6840 Lecture 03 Time Series Decomposition and Moving Average

QBUS6840 Lecture 03 04

Copyright By PowCoder代写 加微信 powcoder

Time Series Decomposition and Moving Average

The University of School

Time series decomposition: Additive and multiplicative models
Forecasting using decompositions
Moving average for smoothing
X11 decomposition (optional)

Readings: Online text Chapter 6:
otexts.com/fpp2/decomposition.html and/or BOK Section
6.3 (from pg 295), BOK Ch. 7

otexts.com/fpp2/decomposition.html

Objectives

Be able to conduct time series decomposition for both
Additive and multiplicative cases

Fully understand how forecasting is conducted via
decompositions

Be able to use moving average for smoothing

Fully understand how moving average is used for forecasting

Be able to distinguish different types of moving averages

Understand X11

Time Series Decomposition

Decompose a time series into its four components

Yt = f (Tt , St ,Ct ,Rt)

where Tt , Ct and St denote the trend, cycle and seasonal
components. Rt is the remainder/irregular. Both the trend
and remainder are often modeled by mathematical models.

Pioneered by the French government in 1911, then US Bureau
of Census and Bureau of Labor Statistics. Developed by many
academics around the world

The goal of time series decomposition is usually to understand
and interpret the time series rather than for forecasting.
However it also helps improve forecast accuracy.

Time Series Decomposition

Note: There might be a cycle component in the time series
but this component is often combined into the trend
component, as it is more mathematically convenient to model
these two components together. Most decomposition methods
are developed to estimate this trend-cycle component

From now on, we aim to decompose

Yt = f (Tt ,St ,Rt)

where Tt is the trend-cycle component, and often simply
referred to as trend.

Decomposition Models

yt = Tt + St + Ct + �t

Appropriate when the
variation (around the trend,
or the seasonal pattern)
doesn’t change over time

Multiplicative

yt = Tt × St × Ct × �t

variation (around the trend,
or the seasonal pattern)
changes over time

Additive or Multiplicative?

Is the seasonal variation proportional to the trend?

Short-term visitor arrivals to Australia (monthly data),
available from the Australian Bureau of Statistics

Additive or Multiplicative?

A multiplicative model seems best for the visitor arrival series

If this proportional is (linearly) shrinking, then what?

Additive or multiplicative?

Alcohol related assaults in

Data from the NSW Bureau
of Crime Statistics and
Research: www.bocsar.
nsw.gov.au/Pages/

bocsar_pages/Alcohol_

Related_Violence.aspx

www.bocsar.nsw.gov.au/Pages/bocsar_pages/Alcohol_Related_Violence.aspx
www.bocsar.nsw.gov.au/Pages/bocsar_pages/Alcohol_Related_Violence.aspx
www.bocsar.nsw.gov.au/Pages/bocsar_pages/Alcohol_Related_Violence.aspx
www.bocsar.nsw.gov.au/Pages/bocsar_pages/Alcohol_Related_Violence.aspx

Again: Additive or Multiplicative?

Again: Additive or Multiplicative?

Multiplicative Model vs Additive Model

We can convert the multiplicative model into an additive
model by noting that

Yt = Tt × St × Rt

logYt = logTt + log St + logRt

Another way to visualize whether a multiplicative model is
adequate is to plot the log series.

Some Notes

Usually intuitive methods are applied to estimate these models

Most often used when components or parameters are NOT
changing over time

Additive or multiplicative depends on the type of seasonal

Additive if seasonal variation does not change much;
multiplicative if the seasonal variation is proportional to the

Seasonal adjustment

Seasonal adjustment is a statistical technique that estimates
and removes the influences of predictable seasonal patterns, in
order to reveal how time series values change from time to

We obtain the seasonally adjusted data if the seasonal
component is removed from the original time series

Ỹt = Yt − St(Additive) or Ỹt = Yt/St(Multiplicative)

Working with seasonally adjusted data also leads to more
accurate forecasts.

Seasonal adjustment

The Australian Bureau of Statistics (ABS) adjusts series such
as: Building approvals, unemployment rate, labour force,
change in gross domestic product, average weekly earnings,
population growth (by state).

Seasonal adjustment helps better reveal the change in these
time series

How to get the seasonally adjusted data?

Moving Average (MA) Methods

MA is often used to smooth out noise and reveal the trend
component:

Smoothing with a moving average of order 3 (denoted as
MA-3): Given the time series {Y1,Y2, …,YT}, its smoothed
time series is

Yt−1 + Yt + Yt+1

, t = 2, 3, …,T − 1.

Smoothing with a moving average of order 5 (denoted as

Yt−2 + Yt−1 + Yt + Yt+1 + Yt+2

, t = 3, …,T − 2.

Question: How to write the smoothing formula for a k (k is
an odd integer) MA-k similar to MA-3 and MA-5? We
sometimes call them centered MA-k .

Moving Average (MA) Methods

Example: Smoothing a time series using MA-5

Y = {Y1,Y2,Y3,Y4,Y5,Y6,Y7,Y8,Y9,Y10}

The time point we can start smooth is t = 3, and the last time
point we can smooth is t = 8. The smoothed time series is

Ŷ = {−,−, Ŷ3, Ŷ4, Ŷ5, Ŷ6, Ŷ7, Ŷ8,−,−}

losing two values on both sides, where we calculate them as

Y1 + Y2 + Y3 + Y4 + Y5

, · · · , Ŷ8 =

Y6 + Y7 + Y8 + Y9 + Y10

Why cannot we calculate Ŷ2?

Symmetrically centred MA

An MA is said to be centred if the same number of
observations on either side of Yt , together with Yt , are
averaged to compute Ŷt .

An MA is said to be symmetrically centred if it is centred and
the coefficients of Yt−i and Yt+i are the same in the average

It’s easy to see that a MA-k , with k being an odd number, is
symmetrically centred.

How can we make a MA-k with an even k to be symmetrically

Even Order Moving Average: CMA-(2k)

Odd Order MAs are symmetrically centred (i.e. Centred MA-5
or simply MA-5)

Yt+2 + Yt+1 + Yt + Yt−1 + Yt−2

Consider possible MA-4. Which way?

Yt−2 + Yt−1 + Yt + Yt+1

Even Order Moving Average: CMA-(2k)

Odd Order MAs are symmetrically centred (i.e. Centred MA-5
or simply MA-5)

Yt+2 + Yt+1 + Yt + Yt−1 + Yt−2

Consider possible MA-4. Which way?

Yt−1 + Yt + Yt+1 + Yt+2

Even Order Moving Average: CMA-(2k)

Work out the half time smoothing, then average them

Yt−2 + Yt−1 + Yt + Yt+1

; Ŷt+0.5 =

Yt−1 + Yt + Yt+1 + Yt+2

Ŷt−0.5 + Ŷt+0.5

(Yt+1 + Yt + Yt−1) +

That is, we do a two-layer MA: MA-4, followed by MA-2.

Example: Quarterly product sales

Notice we lose 2
data points at the
beginning of the
series and 2 data
at the end

Odd Order MAs are symmetrically centred.

Even Order MAs are constructed in two-layer MA. This way
makes them centred.

We call them all the Centred MA, denoted by CMA-(M)
where M is either odd number or even number (When M is
odd number, simply denoted as MA-M)

When M is even number, in the construction of CMA-M, we
do two half centred averages at t − 0.5 and t + 0.5 first, then
take the average of two half centred averages.

Similarly we can conduct many layers even with different
orders. For example:
m × n-MA means we will do m (C)MA-n’s, then take the
average over m (C)MAs.

Derive the formula for 3× 5-MA.

MA for estimating trend

The smoothed time series (red curve) produced by MA-5. This can
be viewed as the trend component. The grey line is the data.

Selecting k

Heavier smoothing
VS Responsiveness
Useful to compare
results with
different k
What will happen
here if k = 12 or

— MA 3 — MA 7

When k increase, we lose more data on both sides

See demo in Lecture03 Example01.py

Four Minutes Exercise

Show that the formula for a CMA-6 is

(Yt+3 + Yt−3) +

(Yt+2 + Yt+1 + Yt + Yt−1 + Yt−2)

The formula for a CMA-k (k is an even number) is

(Yt+k/2 + Yt−k/2) +

Yt+k/2−1 + Yt+k/2−2 + · · ·

+Yt + · · ·+ Yt−k/2+2 + Yt−k/2+1

Write the formula for k = 8

Or we write it as the CMA-(2k),

(Yt+k + Yt−k) +

(Yt+k−1 + Yt+k−2 + · · ·

+Yt + · · ·+ Yt−k+2 + Yt−k+1)

In this form, k = 3 corresponds to CMA-6.

Prove the formula for the CMA-(2k) (Homework!)

Four Minutes Exercise

Show that the formula for a CMA-6 is

(Yt+3 + Yt−3) +

(Yt+2 + Yt+1 + Yt + Yt−1 + Yt−2)

The formula for a CMA-k (k is an even number) is

(Yt+k/2 + Yt−k/2) +

Yt+k/2−1 + Yt+k/2−2 + · · ·

+Yt + · · ·+ Yt−k/2+2 + Yt−k/2+1

Write the formula for k = 8

Or we write it as the CMA-(2k),

(Yt+k + Yt−k) +

(Yt+k−1 + Yt+k−2 + · · ·

+Yt + · · ·+ Yt−k+2 + Yt−k+1)

Prove the formula for the CMA-(2k) (Homework!)

Four Minutes Exercise

Show that the formula for a CMA-6 is

(Yt+3 + Yt−3) +

(Yt+2 + Yt+1 + Yt + Yt−1 + Yt−2)

The formula for a CMA-k (k is an even number) is

(Yt+k/2 + Yt−k/2) +

Yt+k/2−1 + Yt+k/2−2 + · · ·

+Yt + · · ·+ Yt−k/2+2 + Yt−k/2+1

Write the formula for k = 8

Or we write it as the CMA-(2k),

(Yt+k + Yt−k) +

(Yt+k−1 + Yt+k−2 + · · ·

+Yt + · · ·+ Yt−k+2 + Yt−k+1)

In this form, k = 3 corresponds to CMA-6.

Moving Average for Forecasting

Forecasting (using k pasts)

Ŷt+1|1:t =
Yt + Yt−1 + Yt−2 + · · ·+ Yt−k+1

For example, MA-5 for forecasting

Ŷt+1|1:t =
Yt + Yt−1 + Yt−2 + Yt−3 + Yt−4

At t = 5, we forecast for the time t + 1 = 6 as

Y5 + Y4 + Y3 + Y2 + Y1

which is the same as the smoothed value Ŷ3 at time t = 3 via
MA-5 Smoothing.

Moving Average for Forecasting

In terms of algorithm, we can do a MA-5 smoothing, and shift THREE units
time, then we have a one-step ahead forecast of MA-5

This can be shown by the following pattern, (example for MA-5),
Smoothing:

Y1, Y2, Y3, Y4, · · · , YT−2, YT−1, YT
Ŷ3, Ŷ4, · · · , ŶT−2

Forecasting, shifting THREE units time

Y1, Y2, Y3, Y4, Y5, Y6, · · · , YT ???
Ŷ3, · · · , ŶT−3, ŶT−2

Note here Ŷ3 is the average of Y1,Y2,Y3,Y4,Y5, …

Why? First according to the MA-5 forecast formula (the second dot item on
slide 28), the forecast should be

ŶT+1|1:T =
YT + YT−1 + Yt−2 + YT−3 + YT−4

where the smoothing value for the time T − 2 is also given by

YT + YT−1 + Yt−2 + YT−3 + YT−4

That is why we can shift three positions from the MA-5 smoothing result.

Weighted Moving Averages

MA is a special case of Weighted Moving Averages (WMA)

Smoothing (A window-5 WMA)

Ŷt = w−2Yt−2 + w−1Yt−1 + w0Yt + w1Yt+1 + w2Yt+2

wi := w−2 + w−1 + w0 + w1 + w2 = 1.

More general WMA-k, with k = 2m + 1 odd

Ŷt = w−mYt−m + w−m+1Yt−m+1 + · · ·+ Yt + · · ·+ wmYt+m

i=−m wi = w−m + w−m+1 + · · ·+ wm = 1
WMA-5 for Forecasting (Example):

Ŷt+1 = w2Yt + w1Yt−1 + w0Yt−2 + w−1Yt−3 + w−2Yt−4

Weighted Moving Averages (WMA): Examples

Smoothing (A (symmetric) WMA-5)

Ŷt = 0.15Yt−2 + 0.2Yt−1 + 0.3Yt + 0.2Yt+1 + 0.15Yt+2

i.e., w−2 = w2 = 0.15,w−1 = w1 = 0.2, and w0 = 0.3.

Smoothing (A CMA-4 is a WMA-5)

(Yt−2 + Yt+2) +

(Yt−1 + Yt + Yt+1)

Find out w−2,w−1,w0,w1,w2 please.

More Examples

Some popular sets of weights

(Yt+2 + Yt−2) +

(Yt+1 + Yt−1) +

(Yt+3 +Yt−3)+

(Yt+2 +Yt−2)+

(Yt+1 +Yt +Yt−1)
CMA-12 (WMA-13):

(Yt+6 + Yt−6) +

(Yt+5 + Yt+4 + Yt+3 + Yt+2

+ Yt+1 + Yt + Yt−1 + Yt−2 + Yt−3 + Yt−4 + Yt−5)

H9: Due to Henderson

Ŷt =0.33Yt + 0.267(Yt+1 + Yt−1) + 0.119(Yt+2 + Yt−2)

− 0.01(Yt+3 + Yt−3)− 0.0041(Yt+4 + Yt−4)

MA smoothing — some notes

Smoothing can reveal structure and components more clearly
than raw data.

Later, smoothing will help us model and estimate these
components.

Weighted MA smoothing can be better than equal weights.

If data have seasonal frequency M, a (C)MA-M smoother will
remove the seasonal pattern to reveal trend and cyclic
patterns. Recall our demo.

New approach is to learn weights for MA that most suits for a
special kind of time series

Estimating the Seasonal Component (Multiplicative)

Model Assumption: Yt = Tt × St × Rt ⇒ St × Rt = YtTt
Assume M is the seasonal frequency

Estimate the trend T̂t by smoothing the data (using e.g. an
centred MA-M). Compute the de-trend series Yt/T̂t .

For each season m, m = 1, …,M, compute the average of the
de-trended values for that season. Denote these values by
s1, s2, · · · , sM .
Normalise these M values to make sure that they add up to

compute the normalising constant c = M/(s1 + s2 + · · ·+ sM)
compute the seasonal indices

Sm = c × sm, m = 1, 2, …,M.

The estimated seasonal component Ŝt is obtained by
concatenating these seasonal indices.

Example: Approximated Seasonal Series Ŝt × Rt = Yt

(2012-2015)

How to convert this to an actual seasonal series?

Example: Calculation

Use three years de-trend data to demonstrate

Example: Calculation

take the average of the three of the same months

Example: Calculation

Calculate the normalized constant by

sum of All month values

=12/(0.992 + · · ·+ 0.808) = 1.00026

Month indices
S1 = 0.9446 ∗ 1.00026 = 0.9449, …,
S12 = 1.3926 ∗ ∗1.00026 = 1.3930
The seasonal component is

{Ŝ1, Ŝ2, …, Ŝ12, Ŝ13, …, Ŝ24, …}

={S1, S2, …, S12,S1, · · · , S12, · · ·}

For monthly data, there are only 12
different Ŝt values. For example,
when t = 37, we know this is a
January, so Ŝt = SJan (ie. m = 1)

Seasonally Adjusted Series T̂t × Rt (one combined
notation not two)

We now calculate
the seasonally
adjusted series
(taking off
components)

Yt =Tt × St × Rt ⇒

T̂t × Rt =

Adjusted Series against the Original Series

Modelling Trend

Sometimes, it’s desirable to model the trend (of the seasonally
adjusted series). For example, forecasting requires a
parametric model for trend.

Common models are

Tt = β0 + β1t

Tt = β0 + β1t + β2t

where the coefficients β’s are estimated by fitting the
seasonally adjusted series on time.

Modelling trend: Example

We regress
seasonally
adjusted data (in
orange) on time to
obtain the trend

Using which
mathematical
model depends on
the shape of
seasonally
adjusted series.
Here we have used
a linear model

̂Tt × Ct × �t =β0 + β1t + �t ⇒

T̂t = β̂0 + β̂1t

= 476759.25 + 3261.33t

Can we directly model the Trend on time series?

Suppose we want
to estimate the
trend using the
linear model
Tt = β0 + β1t.
We could simply
regress Yt by

Regressing over Yt
may not be the
best practice in
some cases

Can we directly model the Trend on time series?

The accepted
practice is to
smooth the data
seasonal variation,
and then regress
smoothed values

Fitting a quadratic trend

Do we have to use linear model? No

Notes on Trend

Smooth to remove seasonality first.

This reveals trend-cycle component.

Also removes possible end and start effects.

This is the initial trend estimate to only help estimate
seasonality. Normally we don’t model this initial trend.

Estimate the seasonal component and remove it to get the
seasonally adjust series

We then re-estimate the trend.

Be very careful when extrapolating trend models for
forecasting.

Forecasting Future Values (Multiplicative)

We set et+h = 1 to make forecasts

ŷt+h = T̂t+h × Ĉt+h × Ŝt+h

if a well-defined cycle exists; otherwise, set Ĉt+h to 1 to have

ŷt+h = T̂t+h × Ŝt+h

if the cycle cannot be predicted.

For example, suppose we are in t = 48-th month (Dec 2015)
and we wish to forecast for Feb and May 2016, which means
h = 2, 5. Hence t + h = 50 and 53 respectively. First use
trend formula, e.g., calculate

T̂t+h = T̂48+2 = β̂0 + β̂1(48 + 2) = β̂0 + 50 ∗ β̂1 = 639825.75,

T̂t+h = T̂48+5 = β̂0 + 53 ∗ β̂1 = 649609.74

Forecasting Future Values (Multiplicative)

We set et+h = 1 to make forecasts

ŷt+h = T̂t+h × Ĉt+h × Ŝt+h

if a well-defined cycle exists; otherwise, set Ĉt+h to 1 to have

ŷt+h = T̂t+h × Ŝt+h

if the cycle cannot be predicted.

For example, suppose we are in t = 48-th month (Dec 2015)
and we wish to forecast for Feb and May 2016, which means
h = 2, 5. Hence t + h = 50 and 53 respectively. First use
trend formula, e.g., calculate

T̂t+h = T̂48+2 = β̂0 + β̂1(48 + 2) = β̂0 + 50 ∗ β̂1 = 639825.75,

T̂t+h = T̂48+5 = β̂0 + 53 ∗ β̂1 = 649609.74

Forecasting Future Values (Multiplicative)

As t + h = 53 means May 2016 and t + h = 50 Feb 2016, we
will have Ŝ50 = SFeb = S2 and Ŝ53 = SMay = S5 in the final
forecast calculation

The Final forecast for Feb 2016 is

Ŷ50 = T̂50 × Ŝ50 = T̂50 × S2 = 639825.75 ∗ 1.162 ≈ 743477

The Final forecast for May 2016 is

Ŷ53 = T̂53 × Ŝ53 = T̂53 × S5 = 649609.74 ∗ 0.798 ≈ 518388

Forecasting T and S in 2016

Trend T̂t+h Seasonal Ŝt+h

Visitor Arrival Forecast

We have used
data from 2012 to
2015 to estimate
the multiplicative
model in which a
linear model is
used for the
trend-cycle, and
then forecast
arrivals from Jan
2016 to Dec 2016
(in blue).

T̂t × Rt = β0 + β1t + Rt ⇒ T̂t = β̂0 + β̂1t

Does the model fit well? Check the estimated remainder!

Fit the multiplicative
trend-seasonal model
using the 2010-2015
data and compute

It seems okay. Ideally it

should be noise around

1 (for additive model,

this should be around

Is this model fitting well?

There are some patterns that have not been picked up by the trend
and seasonal component. So this could be Cycle component!

Estimating the Cyclic Component (Multiplicative)

Go back to the model Yt = Tt × Ct × St × Rt
We can estimate the cycle at each time t by first computing

Ĉt × Rt =

And then smoothing, e.g., with an MA-3

T̂t+1 × Ŝt+1

T̂t−1 × Ŝt−1

Estimating the Cyclic Component (Multiplicative)

Why do we use an MA3 here? How about an MA12?

If we are going to model this cycle, what model do you
recommend?

Does the fit improve?

T̂t×Ŝt×Ĉt

Notes on the multiplicative decomposition (MD) model

Lots of intuitive choices. Not the best method

Different smoothers can be used at each step: WMA is often

Median smoothers can be used for robustness

Outlier could be modelled and/or removed

The Full Decomposition Algorithm (Multiplicative)

Model Assumption: Yt = Tt × St ×Rt ⇒ St ×Rt = YtTt Assume M
is the seasonal frequency

Step 1: Estimate the trend T̂t by smoothing the data (using
e.g. an centred MA-M). Compute the de-trend series Yt/T̂t .
Step 2: For each season m, m = 1, …,M, compute the
average of the de-trended values for that season. Denote
these values by s1, s2, · · · , sM .
Step 3: Normalise these M values to make sure that they add

compute the normalising constant c = M/(s1 + s2 + · · ·+ sM)
compute the seasonal indices

Sm = c × sm, m = 1, 2, …,M.

Step 4: The estimated seasonal component Ŝt is obtained by
concatenating these seasonal indices, then compute seasonally
adjusted series:

T̂t × Rt =

The Full Decomposition Algorithm (Multiplicative)

Step 5: If forecasting, fit a trend model for T̂t × Rt to obtain
T̂t otherwise smooth T̂t × Rt to obtain T̂t
Step 6: Check the estimated remainder

R̂t = Yt/(T̂t × Ŝt)

if the series {R̂t} does not show any pattern, stop! otherwise
continue to the next steps (to find possible cycle for example)

Estimate the cycle-re

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com