You are on page 1of 36

Time Series Analysis

and Forecasting
1 Introduction
• Any variable that is measured over time in
sequential order is called a time series.
• We analyze time series to detect patterns.
• The patterns help in forecasting future values of
the time series.

Predicted value
The time series exhibit a
downward trend pattern.
2
2 Components of a Time Series
• A time series can consist of four components.
• Long - term trend (T).
• Cyclical effect (C).
• Seasonal effect (S).
• Random variation (R).

A trend is a long term relatively


smooth pattern or direction, that
persists usually for more than one year.

3
Components of a Time Series

• A time series can consists of four components.


• Long - term trend (T)
• Cyclical variation (C)
• Seasonal variation (S)
• Random variation (R)

A cycle is a wavelike pattern describing


a long term behavior (for more than one
year). Cycles are seldom regular, and
often appear in combination with
other components.
4
Components of a Time Series

• A time series can consists of four components.


• Long - term trend (T).
• Cyclical effect (C).
• Seasonal effect (S).
• Random variation (R).

The seasonal component of the time series


exhibits a short term (less than one year)
calendar repetitive behavior.

5
Components of a Time Series

• A time series can consists of four components.


• Long - term trend (T).
• Cyclical effect (C).
• Seasonal effect (S).
• Random variation (R).

Random variation comprises the irregular We try to remove random variation


unpredictable changes in the time series. thereby, identify the other components.
It tends to hide the other (more predictable)
components.
6
3 Smoothing Techniques
• To produce a better forecast we need to determine which
components are present in a time series.
• To identify the components present in the time series, we need first
to remove the random variation.
• This can be done by smoothing techniques.

7
Moving Averages
• A k-period moving average for time period t is the
arithmetic average of the time series values around
period t.

– For example: A 3-period moving average at period t


is calculated by (yt-1 + yt + yt+1)/3

8
Moving Average: Example
• Example 1
• To forecast future gasoline sales, the last four years quarterly sales were
recorded.
• Calculate the three-quarter and five-quarter moving average. Show the
relevant graphs.

Period Year/Quarter Gas Sales


1 1 1 39
2 2 37
3 3 61
4 4 58
5 2 1 18
6 2 56 9
Moving Average: Example
• Solution Period Gas 3-period 5-period
• Solving by hand Sales moving Avg. moving Avg.
1 39
2
(39+37+61)/3= 37
*
45.6667
*
3
(37+61+58)/3= 61 52.0000
*
42.6000
(39+37+61+58+18)/5=
4 58 45.6667 46.0000
5 18 44.0000 55.0000
6 56 52.0000 48.2000
7 82 55.0000 44.8000
8 27 50.0000 55.0000
9 41 45.6667 53.6000
10 69 53.0000 50.4000
11 49 61.3333 55.8000
12 66 56.3333 56.0000
13 54 54.0000 60.2000
14 42 62.0000 63.6000
15 90 66.0000
16 66
*
* * 10
Moving Average: Smoothing effect

Moving Average
3-period moving average
100
Value

50

0 Comment: We can identify


1 2 3 4 5 6 7 8 9 10 11 12a13
trend component
14 15 16 and
seasonality as well.
Data Point

Notice how the averaging process removes some of


the random variation.
11
Moving Average: Smoothing effect

3-period moving average


100
Too much
80
smoothing may
60
eliminate
40
patterns of
The 5-period 20
interest.
0
moving average 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Here, the
removes more seasonality is
removed when
variation than 5-period moving using 5-period
the 3-period 100 moving average.
average
80 Too little
moving 60 smoothing
average. 40 leaves much
20 of the variation,
0 which disguises
the real
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 12
patterns.
Centered Moving Average
• With an even number of observations included in the moving average, the
average is placed between the two periods in the middle.
• To place the moving average in an actual time period, we need to center it.
• Two consecutive moving averages are centered by taking their average, and
placing it in the middle between them.

13
Centered Moving Average: Example
• Calculate the 4-period moving average and center it, for
the data given below:
Period Time series Moving Avg. Centerd Mov.Avg.
1 15
2 27
3
(2.5)
20 19.0
4 14 20.25
(3.5) 21.5
5 25 19.50
(4.5) 17.5
6 11

14
Exponential Smoothing

– The exponential smoothing – When smoothing the


method provides smoothed time series at time t,
values for all the time > the exponential
smoothing method
periods observed. considers all the data
available at t
– The moving average (yt, yt-1,…)
method does not > the moving average method
provide smoothed values considers only the
(moving average values) observations included in the
for the first and last set calculation of the average
of periods. value, and “forgets” the rest.

15
Exponentially Smoothed Time Series

SStt == wy
wytt ++ (1-w)S
(1-w)St-1
t-1

St = exponentially smoothed time series at time t.


yt = time series at time t.
St-1 = exponentially smoothed time series at time t-1.
w = smoothing constant, where 0 £ w £ 1.

16
The Exponentially Smoothed Process
• Example 2
Calculate the gasoline sale smoothed time series
using exponential smoothing with w = .2, and w
= .7. Period Gas
Sales
Set S1 = y1 1 39 S1 = 39
S2 = wy2 + (1-w)S1 2 37 S2 = (.2)(37) + (1-.2)(39) = 38.6
S3 = wy3 + (1-w)S2 3 61 S3 = (.2)(61) + (1-.2)(38.6) = 43.1
4 58
5 18
6 56
. .
. .

17
The Exponentially Smoothed Process
• Example 2-continued
Exponential Smoothing, w=.2 Small ‘w’ provides
100 a lot of smoothing
Value

50

0
1

11

13

15
Exponential Smoothing , w=.7

100
Value

50

0
1 3 5 7 9 11 13 15
18
4 Trend and Seasonal Effects
Trend Analysis
• The trend component of a time series can be linear
or non-linear.
• It is easy to isolate the trend component using linear
regression.
• For linear trend use the model y = b0 + b1t + e.
• For non-linear trend with one (major) change in slope use
the quadratic model y = b0 + b1t + b2t2 + e

19
Seasonal Analysis
• Seasonal variation may occur within a year or within a shorter period
(month, week)
• To measure the seasonal effects we construct seasonal indexes.
• Seasonal indexes express the degree to which the seasons differ from
the average time series value across all seasons.

20
Computing Seasonal Indexes
• Remove the effects of the seasonal and random
variations by regression analysis
= b0 + ŷbt 1t
• For each time period compute the ratio

>
yt/yt This is based on the Multiplicative Model.

which removes most of the trend variation

>
• For each season calculate the average of yt/yt
which provides the measure of seasonality.
• Adjust the average above so that the sum of averages
of all seasons is 1 (if necessary)
21
Computing Seasonal Indexes
• Example 3
• Calculate the quarterly seasonal indexes for hotel
occupancy rate in order to measure seasonal variation.
• Data:

Year Quarter Rate Year Quarter Rate Year Quarter Rate


2015 1 0.561 2017 1 0.594 2019 1 0.665
2 0.702 2 0.738 2 0.835
3 0.8 3 0.729 3 0.873
4 0.568 4 0.6 4 0.67
2016 1 0.575 2018 1 0.622
2 0.738 2 0.708
3 0.868 3 0.806
4 0.605 4 0.632

22
Computing Seasonal Indexes
• Perform regression analysis for the model
y = b0 + b1t + e where t represents the time, and y
represents the occupancy rate.
Time (t) Rate
1 0.561
ŷ  .639368  .005246t
2 0.702
3 0.800
4 0.568

Rate
5 0.575
6 0.738
7 0.868
8 0.605 0 5 10 15 20 25
. . The regression line
t represents trend.
. .
23
The Ratios yt / yt

>
t yt ŷ t Ratio
1 .561 .645 .561/.645=.870
2 .702 .650 .702/.650=1.08
3 ………………………………………………….
=.639368+.005245(1)
No trend is observed, but
yt seasonality and randomness
Rate/Predicted rate
ŷ t still exist.
1.5

0.5

0 11

15

17

19
1

13 24
The Average Ratios by Seasons
Rate/Predicted rate
0.870
• To remove most of the random variation
1.080
1.221 but leave the seasonal effects,average
0.860
0.864
the termsyt / yˆ t for each season.
1.100
1.284 Rate/Predicted rate
0.888
0.865 1.5
1.067
1.046 1
0.854
0.5
0.879
0.993 0
1.122
1 3 5 7 9 11 13 15 17 19
0.874 Average ratio for quarter 1:(.870 + .864 + .865 + .879 + .913)/5 = .878
0.913
1.138
Average ratio for quarter 2: (1.080+1.100+1.067+.993+1.138)/5 = 1.076
1.181 Average ratio for quarter 3: (1.221+1.284+1.046+1.122+1.181)/5 = 1.171
0.900 25
Average ratio for quarter 4: (.860 +.888 + .854 + .874 + .900)/ 5 = .875
Interpreting the Seasonal Indexes
• The seasonal indexes tell us what is the ratio
between the time series value at a certain season,
and the overall seasonal average.
• In our problem: 17.1% above the
117.1% annual average
7.6% above the 12.5% below the
annual average annual average
Annual average
occupancy (100%) 107.6%
87.8% 87.5%
12.2% below the
annual average

Quarter 1 Quarter 2Quarter 3 Quarter 4Quarter 1 Quarter 2Quarter 3 Quarter 4

26
The Smoothed Time Series
• The trend component and the seasonality component are
recomposed using the multiplicative model.

ŷ t  T̂t  Ŝ t  (.639  .0052t )Ŝ t

In period #1 ( quarter 1): ŷ1  T̂1  Ŝ1  (.639  .0052(1))(.878)  .566


In period #2 ( quarter 2): ŷ 2  T̂2  Ŝ 2  (.639  .0052(2))(1.076)  .699
0.9
Actual series Smoothed series
0.8

0.7

0.6

0.5 The linear trend (regression) line


1 3 5 7 9 11 13 15 17 19
27
Deseasonalized Time Series

Seasonally adjusted time seriesActual


= time series
Seasonal index

By removing the seasonality, we can identify changes in


the other components of the time series, that might
have occurred over time.

28
Deseasonalized Time Series
In period #1 ( quarter 1): y 1 / SI1  .561 / .870  .639
In period #2 ( quarter 2):y 2 / SI2  .708 1.076  .652
In period #5 ( quarter 1): y 5 / SI1  .575 .870  .661
There was a gradual increase in occupancy rate
1
0.8
0.6
0.4
0.2
0
0 5 10 15 20 25

29
6 Forecasting Models
• The choice of a forecasting technique depends on the components
identified in the time series.
• The techniques discussed next are:
• Exponential smoothing
• Seasonal indexes
• Autoregressive models (a brief discussion)

30
Forecasting with Exponential
Smoothing
• The exponential smoothing model can be used to
produce forecasts when the time series…
• exhibits gradual(not a sharp) trend
• no cyclical effects
• no seasonal effects

• Forecast for period t+k is computed by


Ft+k = St
t is the current period; St = wyt + (1-w)St-1

31
Forecasting with Seasonal Indexes

• Linear regression and seasonal indexes to forecast the


time series that composes trend with seasonality
• The model

Ft  [b 0  b1t ]  SIt
Linear trend value for period t, Seasonal index
obtained from the linear regression for period t.

32
Forecasting with Seasonal Indexes;
Example
• Example 5
• Use the seasonal indexes calculated in Example 3
along with the trend line, to forecast each quarter
occupancy rate in 2020.
• The solution procedure
– Use simple linear regression to find the trend line.
– Use the trend line to calculate the seasonal indexes.
– To calculate Ft multiply the trend value for period t by the
seasonal index of period t.

33
Forecasting with indicator variables

Forecasting with Seasonal Indexes:


Example
• Solution
• The trend line was obtained from the regression
analysis.
ŷ t  .639  .00525t
– For the year 2020 we have:
yˆ 21  .639  .00525 (21)  .749 F21 = .749(.878)
t Trend value Quarter SI Forecast
21 .749 1 .878 .658
22 .755 2 1.076 .812
23 .760 3 1.171 .890
24 .765 4 .875 .670

34
Autoregressive models
• Autocorrelation among the errors of the regression
model provides opportunity to produce accurate
forecasts.
• In a stationary time series (no trend and no
seasonality) correlation between consecutive
residuals leads to the following autoregressive model:

yt = b0 + b1yt-1 + et

35
Autoregressive model;

• The estimated model has the form

y t  b 0  b1y t 1
Y (t) Y (t-1)
13.5 The increase in the y
10.4 13.5 for periods 1, 2, 3,…
6.1 10.4 are predictors of the
3.2 6.1 increase in the y for
4.3 3.2
. 4.3
periods 2, 3, 4,…,
. . respectively.
36

You might also like