Presentation on theme: "1 11. Time Series Analysis and Forecasting ECON 251 Research Methods."— Presentation transcript:
1 11. Time Series Analysis and Forecasting ECON 251 Research Methods
2 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. The time series exhibit a downward trend pattern. Future expected value
3 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.
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) 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
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) The seasonal component of the time-series exhibits a short term (less than one year) calendar repetitive behavior
6 We try to remove random variation thereby, identify the other components. 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 unpredictable changes in the time series. It tends to hide the other (more predictable) components.
7 There are two commonly used time series models: The additive model The multiplicative model y t = T t + C t + S t + R t y t = T t x C t x S t x R t Time-series models
8 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 easily done by smoothing techniques: moving averages exponential smoothing
9 Moving Averages A k-period moving average for time period t is the arithmetic average of the time series values where the period t is the center observation. Example: A 3-period moving average for period t is calculated by (y t+1 + y t + y t-1 )/3. Example: A 5-period moving average for period t is calculated by (y t+2 + y t+1 + y t + y t-1 + y t-2 )/5.
10 Example: Gasoline Sales To forecast future gasoline sales, the last four years quarterly sales were recorded. Calculate the three-quarter and five-quarter moving average. Data
11 Solution Solving by hand **** **** * * 3 period moving average (y t+1 + y t + y t-1 )/3 5 period moving average ( y t+2 + y t+1 + y t + y t-1 + y t-2 )/5
12 Notice how the averaging process removes some of the random variation. as well as seasonality.There is some trend component present, Example: Gasoline Sales
13 5-period moving average3-period moving average The 5-period moving average removes more variation than the 3-period moving average. Too much smoothing may eliminate patterns of interest. Here, the seasonality component is removed when using 5-period moving average. Too little smoothing leaves much of the variation, which disguises the real patterns. Example: Gasoline Sales
14 Example – Armani’s Pizza Sales Below are the daily sales figures for Armani’s pizza. Compute a 3-day moving average. ( Armani TS.xls ) Week 1 Week 2 Monday3538 Tuesday4246 Wednesday5661 Thursday4652 Friday6773 Saturday5158 Sunday3942 The moving average that is associated with Monday of week 2 is?
15 Centered moving average With 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.
16 Example – Armani’s Pizza Sales Calculate the 4-period moving average and center it, for the data given below: Period Time series Moving Avg. Centerd Mov.Avg (2.5) 21.5 (3.5) (4.5)
17 Example – Armani’s Pizza Sales Armani’s pizza is back. Compute a 2-day centered moving average. Week 1 Monday35 Tuesday42 Wednesday56 Thursday46 Friday67 Saturday51 Sunday39 The centered moving average that is associated with Friday of week 1 is?
18 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.
19 Trend Analysis The trend component of a time series can be linear or non- linear. It is easy to isolate the trend component by using linear regression. For linear trend use the model y = 0 + 1 t + . For non-linear trend with one (major) change in slope use the quadratic model y = 0 + 1 t + 2 t 2 +
20 Example – Pharmaceutical Sales (Identify trend) Annual sales for a pharmaceutical company are believed to change linearly over time. Based on the last 10 year sales records, measure the trend component. Start by renaming your years 1, 2, 3, etc.
21 Example – Pharmaceutical Sales (Identify trend) Solution Using Excel we have 11 Forecast for period 11
22 Example – Cigarette Consumption Determine the long-term trend of the number of cigarettes smoked by Americans 18 years and older. Data ( Cigarettes.xls ) Solution Cigarette consumption increased between 1955 and 1963, but decreased thereafter. A quadratic model seems to fit this pattern.
23 Example – Cigarette Consumption The quadratic model fits the data very well.
24 Example Forecast the trend components for the previous two examples for periods 12, and 41 respectively.
25 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) 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.
26 Measuring the Cyclical Effects Although often unpredictable, cycles need to be isolated. To identify cyclical variation we use the percentage of trend. Determine the trend line (by regression). Compute the trend value for each period t. Calculate the percentage of trend by
27 Example – Energy Demand Does the demand for energy in the US exhibit cyclic behavior over time? Assume a linear trend and calculate the percentage of trend. Data ( Energy Demand.xls ) The collected data included annual energy consumption from 1970 through Find the values for trend and percentage of trend for years 1975 and 1976.
28 Example – Energy Demand Now consider the multiplicative model The regression line represents trend. (Assuming no seasonal effects). No trend is observed, but cyclicality and randomness still exist.
29 When groups of the percentage of trend alternate around 100%, the cyclical effects are present. (66.4/69.828)100
30 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.
31 Measuring the Seasonal effects Seasonal variation may occur within a year or even within a shorter time interval. To measure the seasonal effects we can use two common methods: 1. constructing seasonal indexes 2. using indicator variables We will do each in turn
32 Example – Hotel Occupancy Calculate the quarterly seasonal indexes for hotel occupancy rate in order to measure seasonal variation. Data ( Hotel Occupancy.xls )
33 Example – Hotel Occupancy Perform regression analysis for the model y = 0 + 1 t + where t represents the chronological time, and y represents the occupancy rate. Time (t) Rate The regression line represents trend.
34 Example – Hotel Occupancy Now let’s consider the multiplicative model, and let’s DETREND data (Assuming no cyclical effects) The regression line represents trend. No trend is observed, but seasonality and randomness still exist.
35 To remove most of the random variation but leave the seasonal effects, average the terms S t R t for each season. ( )/5 =.878Average ratio for quarter 1: Average ratio for quarter 2: ( )/5 = Average ratio for quarter 3: ( )/5 = Average ratio for quarter 4: ( )/ 5 =.875 Example – Hotel Occupancy
36 Quarter 2 Quarter 3 Quarter 2 Interpreting the results 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: Annual average occupancy (100%) Quarter 1 Quarter 4 Quarter 1 Quarter % 107.6% 117.1% 87.5% 12.2% below the annual average 7.6% above the annual average 17.1% above the annual average 12.5% below the annual average Example – Hotel Occupancy
37 Creating Seasonal Indexes Normalizing the ratios: The sum of all the ratios must be 4, such that the average ratio per season is equal to 1. If the sum of all the ratios is not 4, we need to normalize (adjust) them proportionately. Suppose the sum of ratios equaled 4.1. Then each ratio will be multiplied by 4/4.1 (Seasonal averaged ratio) (number of seasons) Sum of averaged ratios Seasonal index = In our problem the sum of all the averaged ratios is equal to 4: = 4.0. No normalization is needed. These ratios become the seasonal indexes.
38 Example Using a different example on quarterly GDP, assume that the averaged ratios were: Quarter 1:.97 Quarter 2:1.03 Quarter 3:.87 Quarter 4:1.00 Determine the seasonal indexes.
39 Deseasonalizing time series By removing the seasonality, we can: compare data across different seasons identify changes in the other components of the time - series. Seasonally adjusted time series = Actual time series Seasonal index
40 Example – Hotel Occupancy A new manager was hired in Q3 1994, when hotel occupancy rate was 80.6%. In the next quarter, the occupancy rate was 63.2%. Should the manager be fired because of poor performance? Method 1: compare occupancy rates in Q (0.632) and Q (0.806) the manager has underperformed he should be fired Method 2: compare occupancy rates in Q (0.632) and Q (0.600) the manager has performed very well he should get a raise
41 Example – Hotel Occupancy Method 3: compare deseasonalized occupancy rates in Q and Q the manager has indeed performed well he should be maybe get a raise Seasonally adjusted time series = Actual time series Seasonal index Recall: Seasonally adjusted occupancy rate in Q Actual occupancy rate in Q Seasonal index for Q4 = Seasonally adjusted occupancy rate in Q3 1994
42 Recomposing the time series Recomposition will recreate the time series, based only on the trend and seasonal components – you can then deduce the value of the random component. In period #1 ( quarter 1): In period #2 ( quarter 2): Actual series Smoothed series The linear trend (regression) line
43 Example – Recomposing the Time Series Recompose the smoothed time series in the above example for periods 3 and 4 assuming our initial seasonal index figures of: Quarter 1: 0.878Quarter 3:1.171 Quarter 2:1.076 Quarter 4:0.875 and equation of:
44 Seasonal Time Series with Indicator Variables We create a seasonal time series model by using indicator variables to determine whether there is seasonal variation in data. Then, we can use this linear regression with indicator variables to forecast seasonal effects. If there are n seasons, we use n-1 indicator variables to define the season of period t: [Indicator variable n] = 1 if season n belongs to period t [Indicator variable n] = 0 if season n does not belong to period t
45 Example – Hotel Occupancy Let’s again build a model that would be able to forecast quarterly occupancy rates at a luxurious hotel, but this time we will use a different technique. Data ( Hotel Occupancy.xls )
46 Example – Hotel Occupancy Use regression analysis and indicator variables to forecast hotel occupancy rate in 1996 Data Quarter 1 belongs to t = 1 Quarter 2 does not belong to t = 1 Quarter 3 does not belong to t = 1 Quarters 1, 2, 3, do not belong to period t = 4. Q i = 1 if quarter i occur at t 0 otherwise
47 The regression model y = 0 + 1 t + 2 Q 1 + 3 Q 2 + 4 Q 3 + Good fitThere is sufficient evidence to conclude that trend is present. There is insufficient evidence to conclude that seasonality causes occupancy rate in quarter 1 be different than this of quarter 4! Seasonality effects on occupancy rate in quarter 2 and 3 are different than this of quarter 4!
48 The estimated regression model y = 0 + 1 t + 2 Q 1 + 3 Q 2 + 4 Q 3 + 1234 b2b2 b3b3 b4b4 Trend line b0b0
49 Autocorrelation among the errors of the regression model provides opportunity to produce accurate forecasts. Correlation between consecutive residuals leads to the following autoregressive model: This is type of model is termed a first-order autoregressive model, and is denoted AR(1). A model which also includes both y t-1 and y t-2 is a second order model AR(2) and so on. Selecting between them is done on the basis of the significance of the highest order term. If you reject the highest order term, re- run the model without it. Apply the same criterion for the new highest order term, and so on. y t = 0 + 1 y t-1 + t Time-Series Forecasting with Autoregressive (AR) models
50 Example – Consumer Price Index (CPI) Forecast the increase in the Consumer Price Index (CPI) for the year 1994, based on the data collected for the years Data ( CPI.xls )
51 Example – Consumer Price Index (CPI) Regress the Percent increase (y t ) on the time variable (t) it does not lead to good results. Y t = t r 2 = 15.0% this indicates the potential presence of first order autocorrelation between consecutive residuals. (-) (+) (-) The residuals form a pattern over time. Also,
52 An autoregressive model appears to be a desirable technique. The increase in the CPI for periods 1, 2, 3,… are predictors of the increase in the CPI for periods 2, 3, 4,…, respectively. Example – Consumer Price Index (CPI)
53 Compare linear trend model autoregressive model
54 Selecting Among Alternative Forecasting Models There are many forecasting models available * * * * * * * * o o o o o o o o Model 1Model 2 Which model performs better? ?
55 Model selection To choose a forecasting method, we can evaluate forecast accuracy using the actual time series. The two most commonly used measures of forecast accuracy are: Mean Absolute Deviation Sum of Squares for Forecast Error In practice, SSE is SS F E are used interchangeably.
56 Procedure for model selection. 1. Use some of the observations to develop several competing forecasting models. 2. Run the models on the rest of the observations. 3. Calculate the accuracy of each model using both MAD and SSE criterion. 4. Use the model which generates the lowest MAD value, unless it is important to avoid (even a few) large errors - in this case use best model as indicated by the lowest SSE. Model selection
57 Example – Model selection I Assume we have annual data from 1950 to We used data from 1950 to 1997 to develop three alternate forecasting models (two different regression models and an autoregressive model), Use MAD and SSE to determine which model performed best using the model forecasts versus the actual data for
58 Example – Model selection I Solution For model 1 Summary of results Actual y in 1998 Forecast for y in 1998
59 Example – Model selection II For the actual values and the forecast values of a time series shown in the following table, calculate MAD and SSE. Forecast Value Actual Value MADSSE F t y t