13
Part II – TIME SERIES ANALYSIS C2 Simple Time Series Methods & Moving Averages © Angel A. Juan & Carles Serrat - UPC 2007/2008

Part II – TIME SERIES ANALYSIS C2 Simple Time Series Methods & Moving Averages © Angel A. Juan & Carles Serrat - UPC 2007/2008

  • View
    225

  • Download
    6

Embed Size (px)

Citation preview

Page 1: Part II – TIME SERIES ANALYSIS C2 Simple Time Series Methods & Moving Averages © Angel A. Juan & Carles Serrat - UPC 2007/2008

Part II – TIME SERIES ANALYSIS

C2 Simple Time Series Methods & Moving Averages

© Angel A. Juan & Carles Serrat - UPC 2007/2008

Page 2: Part II – TIME SERIES ANALYSIS C2 Simple Time Series Methods & Moving Averages © Angel A. Juan & Carles Serrat - UPC 2007/2008

2.2.1: Simple TS and Smoothing Methods

The simple forecasting and smoothing methods model components in a series that are usually easy to see in a time series plot of the data.

These methods decompose the data into its trend and seasonal components, and then extend the estimates of the components into the future to provide forecasts.

Static methods have patterns that do not change over time; dynamic methods have patterns that do change over time and estimates are updated using neighboring values.

You may use two methods in combination. That is, you may choose a static method to model one component and a dynamic method to model another component.

A disadvantage of combining methods is that the confidence intervals for forecasts are not valid.

A disadvantage of combining methods is that the confidence intervals for forecasts are not valid.

STATIC (SIMPLE) METHODS

• Trend Analysis

• Decomposition

STATIC (SIMPLE) METHODS

• Trend Analysis

• Decomposition

DYNAMIC (SMOOTHING) METHODS

• Moving Averages

• Single Exponential Smoothing

• Double Exponential Smoothing

• Winters’ Method (Triple Exp. Smoothing)

DYNAMIC (SMOOTHING) METHODS

• Moving Averages

• Single Exponential Smoothing

• Double Exponential Smoothing

• Winters’ Method (Triple Exp. Smoothing)

The decomposition approach to TSA involves an attempt to identify the component factors (Trend, Cyclical, Seasonal and Irregular) that influence each of the values in a series. Each component is identified separately. Projections of each of the components can then be combined to produce forecasts of future values of the time series.

The decomposition approach to TSA involves an attempt to identify the component factors (Trend, Cyclical, Seasonal and Irregular) that influence each of the values in a series. Each component is identified separately. Projections of each of the components can then be combined to produce forecasts of future values of the time series.

Naive methods are used to develop simple models that assume that very recent data provide the best predictors of the future. Averaging methods generate forecasts based on an average of past observations. Smoothing methods produce forecasts by averaging past values of a series with a decreasing (exponential) series of weights.

Naive methods are used to develop simple models that assume that very recent data provide the best predictors of the future. Averaging methods generate forecasts based on an average of past observations. Smoothing methods produce forecasts by averaging past values of a series with a decreasing (exponential) series of weights.

Page 3: Part II – TIME SERIES ANALYSIS C2 Simple Time Series Methods & Moving Averages © Angel A. Juan & Carles Serrat - UPC 2007/2008

2.2.2: Smoothing

If the time series data contain considerable error, smoothing is the first step in the process of trend identification.

It always involves some form of local averaging of data such that the nonsystematic components of individual observations cancel each other out.

The most common technique is Moving Averages (MA) smoothing which replaces each element of the series by either the simple or weighted average of m surrounding elements.

Medians can be used instead of means (results are then less biased by outliers)

The MA method smooth out the “noise” in a time series. You have to select the MA length, m. Different lengths provide different results.

The MA method smooth out the “noise” in a time series. You have to select the MA length, m. Different lengths provide different results.

Page 4: Part II – TIME SERIES ANALYSIS C2 Simple Time Series Methods & Moving Averages © Angel A. Juan & Carles Serrat - UPC 2007/2008

2.2.3: Selecting a Simple Method or MA

TREND ANALYSIS

Series with trend but without seasonal component.

TREND ANALYSIS

Series with trend but without seasonal component.

CLASSICAL DECOMPOSITION

Series with trend and seasonal component.

CLASSICAL DECOMPOSITION

Series with trend and seasonal component.

MOVING AVERAGES (SMOOTHING)

Series without trend and without seasonal component.

MOVING AVERAGES (SMOOTHING)

Series without trend and without seasonal component.

It is often convenient to fit a trend curve to a time series for two reasons: (1) It provides some indication of the general direction of the observed series, and (2) it can be removed from the original series to get a clearer picture of the seasonality.

It is often convenient to fit a trend curve to a time series for two reasons: (1) It provides some indication of the general direction of the observed series, and (2) it can be removed from the original series to get a clearer picture of the seasonality.

The basic idea is to first estimate and remove the trend from the original series and then smooth out the irregular component. This leaves data containing only seasonal variation. The seasonal values are collected and summarized to produce a number (generally an index number) for each observed interval of the year.

The basic idea is to first estimate and remove the trend from the original series and then smooth out the irregular component. This leaves data containing only seasonal variation. The seasonal values are collected and summarized to produce a number (generally an index number) for each observed interval of the year.

After the seasonal component has been isolated, it can be used to calculate seasonally adjusted data.

After the seasonal component has been isolated, it can be used to calculate seasonally adjusted data.

A moving average of order k is the mean value of k consecutive observations. The most recent moving average value provides a forecast for the next period.

A moving average of order k is the mean value of k consecutive observations. The most recent moving average value provides a forecast for the next period.

Page 5: Part II – TIME SERIES ANALYSIS C2 Simple Time Series Methods & Moving Averages © Angel A. Juan & Carles Serrat - UPC 2007/2008

2.2.4: Measures of Accuracy

Mean Absolute Percentage Error

MAPE

Mean Absolute Percentage Error

MAPE

Mean Absolute Deviation MAD

Mean Absolute Deviation MAD

Mean Squared Deviation MSD

Mean Squared Deviation MSD

One major difference between MSD and MAD is that the MSD measure is influenced much more by large fitting errors than by small errors (since for the MSD measure the errors are squared).

One major difference between MSD and MAD is that the MSD measure is influenced much more by large fitting errors than by small errors (since for the MSD measure the errors are squared).

Page 6: Part II – TIME SERIES ANALYSIS C2 Simple Time Series Methods & Moving Averages © Angel A. Juan & Carles Serrat - UPC 2007/2008

2.2.5: Moving Average Smoothing (1/2)

A strategy frequently used by some stock market investors is to buy if the current price of the stock exceeds the average of its ten most recent prices. Conversely, if the present price is lower than the average of the last ten, it is time to sell.

A strategy frequently used by some stock market investors is to buy if the current price of the stock exceeds the average of its ten most recent prices. Conversely, if the present price is lower than the average of the last ten, it is time to sell.

To smooth the unpredictable ups and downs of a time series, you can form averages of consecutive observations.

To smooth the unpredictable ups and downs of a time series, you can form averages of consecutive observations.

Page 7: Part II – TIME SERIES ANALYSIS C2 Simple Time Series Methods & Moving Averages © Angel A. Juan & Carles Serrat - UPC 2007/2008

2.2.5: Moving Average Smoothing (2/2)

File: RIVERC.MTW

Stat > Time Series > Moving Average…

Three measures of the accuracy of the fitted values are provided: Mean Squared Deviation (MSD), Mean Absolute Deviation (MAD), and Mean Absolute Percentage Error (MAPE).

Three measures of the accuracy of the fitted values are provided: Mean Squared Deviation (MSD), Mean Absolute Deviation (MAD), and Mean Absolute Percentage Error (MAPE).

Different lengths provide different results.Different lengths provide different results.

Hour

Tem

p

700210011001001500500190090023001400

46

44

42

40

38

36

34

32

30

Moving AverageLength 12

Accuracy MeasuresMAPE 7,8201MAD 3,1672MSD 12,2784

Variable

Forecasts95,0% PI

ActualFits

Moving Average Plot for Temp

Hour

Tem

p

700210011001001500500190090023001400

47,5

45,0

42,5

40,0

37,5

35,0

Moving AverageLength 20

Accuracy MeasuresMAPE 7,3234MAD 2,9792MSD 11,7305

Variable

Forecasts95,0% PI

ActualFits

Moving Average Plot for Temp

You can generate forecasts of future values of the series.

You can generate forecasts of future values of the series.

Page 8: Part II – TIME SERIES ANALYSIS C2 Simple Time Series Methods & Moving Averages © Angel A. Juan & Carles Serrat - UPC 2007/2008

2.2.6: Trend Analysis (1/2)

Page 9: Part II – TIME SERIES ANALYSIS C2 Simple Time Series Methods & Moving Averages © Angel A. Juan & Carles Serrat - UPC 2007/2008

2.2.6: Trend Analysis (2/2)

File: RIVERC.MTW

Stat > Time Series > Trend Analysis…

Three measures of the accuracy of the fitted values are provided: Mean Squared Deviation (MSD), Mean Absolute Deviation (MAD), and Mean Absolute Percentage Error (MAPE).

Three measures of the accuracy of the fitted values are provided: Mean Squared Deviation (MSD), Mean Absolute Deviation (MAD), and Mean Absolute Percentage Error (MAPE).

Trend analysis is closely related to linear regression. You choose from among four models (Linear, Quadratic, Exponential and S-Curve) to fit a particular type of trend line to a time series.

Trend analysis is closely related to linear regression. You choose from among four models (Linear, Quadratic, Exponential and S-Curve) to fit a particular type of trend line to a time series.

HourTe

mp

700210011001001500500190090023001400

45,0

42,5

40,0

37,5

35,0

Accuracy MeasuresMAPE 6,13991MAD 2,51294MSD 8,26801

Variable

Forecasts

ActualFits

Trend Analysis Plot for TempLinear Trend Model

Yt = 42,6710 - 0,0210505*t

You can generate forecasts of future values of the series.

You can generate forecasts of future values of the series.

Hour

RES

I1

700210011001001500500190090023001400

5,0

2,5

0,0

-2,5

-5,0

Accuracy MeasuresMAPE 100,000MAD 2,513MSD 8,268

Variable

Forecasts

ActualFits

Trend Analysis Plot for RESI1Linear Trend Model

Yt = 2,139454E-15 - 8,404967E-18*t

Use residuals to detrend the time series.Use residuals to detrend the time series.

Page 10: Part II – TIME SERIES ANALYSIS C2 Simple Time Series Methods & Moving Averages © Angel A. Juan & Carles Serrat - UPC 2007/2008

2.2.7: Seasonality

Seasonality is defined as an autocorrelation of order k, i.e., a correlation between each element i of the series and the element i-k; k is called the lag.

If the measurement error is not too large, seasonality can be visually identified in the series as a pattern that repeats every k elements.

A model that treats the time-series values as a sum of the components is called an additive components model:

Yt = Tt + St + It

A model that threats the time-series values as the product of the components is called a multiplicative components model:

Yt = Tt * St * It

A model that treats the time-series values as a sum of the components is called an additive components model:

Yt = Tt + St + It

A model that threats the time-series values as the product of the components is called a multiplicative components model:

Yt = Tt * St * It

In plots of the series, the distinguishing characteristic between these two types of seasonal components is that in the additive case, the series shows steady seasonal fluctuations, regardless of the overall level of the series; in the multiplicative case, the size of the seasonal fluctuations vary, depending on the overall level of the series.

In plots of the series, the distinguishing characteristic between these two types of seasonal components is that in the additive case, the series shows steady seasonal fluctuations, regardless of the overall level of the series; in the multiplicative case, the size of the seasonal fluctuations vary, depending on the overall level of the series.

Seasonal components can be additive in nature or multiplicative. For example, during the month of December the sales for a particular toy may increase by 1 million dollars every year. Thus, we could add to our forecasts for every December the amount of 1 million dollars (over the respective annual average) to account for this seasonal fluctuation. In this case, the seasonality is additive. Alternatively, during the month of December the sales for a particular toy may increase by 40%, that is, increase by a factor of 1.4. in this case the seasonal component is multiplicative in nature.

Seasonal components can be additive in nature or multiplicative. For example, during the month of December the sales for a particular toy may increase by 1 million dollars every year. Thus, we could add to our forecasts for every December the amount of 1 million dollars (over the respective annual average) to account for this seasonal fluctuation. In this case, the seasonality is additive. Alternatively, during the month of December the sales for a particular toy may increase by 40%, that is, increase by a factor of 1.4. in this case the seasonal component is multiplicative in nature.

Page 11: Part II – TIME SERIES ANALYSIS C2 Simple Time Series Methods & Moving Averages © Angel A. Juan & Carles Serrat - UPC 2007/2008

2.2.8: Classical Decomposition (1/3)

t t t tY T S t t t tY T S t t t tY T S t t t tY T S

time series value

trend component

seasonal component

random error component

t

t

t

t

Y

T

S

time series value

trend component

seasonal component

random error component

t

t

t

t

Y

T

S

Page 12: Part II – TIME SERIES ANALYSIS C2 Simple Time Series Methods & Moving Averages © Angel A. Juan & Carles Serrat - UPC 2007/2008

Hour

Tem

p1001100210070017003001400

45,0

42,5

40,0

37,5

35,0

Accuracy MeasuresMAPE 1,55603MAD 0,62846MSD 0,91504

Variable

TrendForecasts

ActualFits

Time Series Decomposition Plot for TempAdditive Model

2.2.8: Classical Decomposition (2/3)

File: RIVERC.MTW

Stat > Time Series > Decomposition…

This window includes plots of the original data, detrended data, seasonally adjusted data, and the seasonally adjusted and detrended data.

This window includes plots of the original data, detrended data, seasonally adjusted data, and the seasonally adjusted and detrended data.

Classical decomposition separates the time series into trend, seasonal and error components by using least-squares analysis, trend analysis, and moving averages. You can select either a multiplicative or an additive model.

Classical decomposition separates the time series into trend, seasonal and error components by using least-squares analysis, trend analysis, and moving averages. You can select either a multiplicative or an additive model.

The graph depicts a slight download trend, with a 24-hour seasonal component. It also reflects the divergence of the predicted values from the actual values at the top of peaks and at the last valley.

The graph depicts a slight download trend, with a 24-hour seasonal component. It also reflects the divergence of the predicted values from the actual values at the top of peaks and at the last valley.

In this case, an additive model with a seasonal length of 24 hours has been chosen.

In this case, an additive model with a seasonal length of 24 hours has been chosen.

Hour

Data

1200170022003008001400

45

40

35

Hour

Seas.

Adj.

Data

1200170022003008001400

45

40

35

Hour

Detr

. D

ata

1200170022003008001400

3

0

-3

-6

Hour

Seas.

Adj.

and D

etr

. D

ata

1200170022003008001400

3

0

-3

-6

Component Analysis for TempAdditive Model

Original Data

Seasonally Adjusted Data

Detrended Data

Seasonally Adj. and Detrended Data

Note the unusual pattern at the end of the last two time series plots.

Note the unusual pattern at the end of the last two time series plots.

Initial fits overestimate actual values, indicating that a problem may exist.

Initial fits overestimate actual values, indicating that a problem may exist.

Page 13: Part II – TIME SERIES ANALYSIS C2 Simple Time Series Methods & Moving Averages © Angel A. Juan & Carles Serrat - UPC 2007/2008

242322212019181716151413121110987654321

2

0

-2

-4

242322212019181716151413121110987654321

12

8

4

0

242322212019181716151413121110987654321

5

0

-5

242322212019181716151413121110987654321

0,0

-2,5

-5,0

Seasonal Analysis for TempAdditive Model

Seasonal Indices

Percent Variation, by Seasonal Period

Detrended Data, by Seasonal Period

Residuals, by Seasonal Period

2.2.8: Classical Decomposition (3/3)

File: RIVERC.MTW

Stat > Time Series > Decomposition…

This window provides a seasonal analysis for the time series data. It contains a plot of the seasonal indices. In addition, by seasonal period, it contains plots of the original data, present variation, and residuals.

This window provides a seasonal analysis for the time series data. It contains a plot of the seasonal indices. In addition, by seasonal period, it contains plots of the original data, present variation, and residuals.

Note the large number of negative residuals present in four of the five last periods in the Residuals plot.

Note the large number of negative residuals present in four of the five last periods in the Residuals plot.

Some of these concepts will be explained in detail in future chapters.

Some of these concepts will be explained in detail in future chapters.