You are on page 1of 52

BUSINESS ANALYTICS

Time Series Analysis and Forecasting


Introduction
Forecasting is a very difficult task, both in the short run and in the long
run.
Analysts search for patterns or relationships in historical data and then
make forecasts.
◦ There are two problems with this approach:
◦ It is not always easy to undercover historical patterns or relationships.
◦ It is often difficult to separate the noise, or random behavior, from the underlying patterns.
◦ Some forecasts may attribute importance to patterns that are in fact random variations and
are unlikely to repeat themselves.
◦ There are no guarantees that past patterns will continue in the future.
Forecasting Methods:
An Overview
There are many forecasting methods available, and there is little
agreement as to the best forecasting method.
The methods can be divided into three groups:
1. Judgmental methods
2. Extrapolation (or time series) methods
3. Econometric (or causal) methods

The first method is basically nonquantitative; the last two are


quantitative.
Extrapolation Models
Extrapolation models are quantitative models that use past data of a
time series variable to forecast future values of the variable.
Many extrapolation models are available:
◦ Trend-based regression
◦ Autoregression
◦ Moving averages
◦ Exponential smoothing
All of these methods look for patterns in the historical series and then
extrapolate these patterns into the future.
Complex models are not always better than simpler models.
◦ Simpler models track only the most basic underlying patterns and can be
more flexible and accurate in forecasting the future.
Econometric Models
Econometric models, also called causal or regression-based models, use
regression to forecast a time series variable by using other explanatory
time series variables.
Prediction from regression equation:

Causal regression models present mathematical challenges, including:


◦ Determining the appropriate “lags” for the regression equation
◦ Deciding whether to include lags of the dependent variable as explanatory
variables
◦ Autocorrelation (correlation of a variable with itself) and cross-correlation
(correlation of a variable with a lagged version of another variable)
Combining Forecasts
This method combines two or more forecasts to obtain the final
forecast.
The reasoning is simple: The forecast errors from different forecasting
methods might cancel one another.
Forecasts that are combined can be of the same general type, or of
different types.
The number of forecasts to combine and the weights to use in
combining them have been the subject of several research studies.
Components of Time Series Data
(slide 1 of 4)
If observations increase or decrease regularly through time, the time series has
a trend.
◦ Linear trend—occurs if the observations increase by the same amount from period to
period.
◦ Exponential trend—occurs when observations increase at a tremendous rate.
◦ S-shape trend—occurs when it takes a while for observations to start increasing, but
then a rapid increase occurs, before finally tapering off to a fairly constant level.
Components of Time Series Data
(slide 2 of 4)

If a time series has a seasonal component, it exhibits


seasonality—that is, the same seasonal pattern tends to
repeat itself every year.
Components of Time Series Data
(slide 3 of 4)
A time series has a cyclic component when business cycles affect the
variables in similar ways.
◦ The cyclic component is more difficult to predict than the seasonal component,
because seasonal variation is much more regular.
◦ The length of the business cycle varies, sometimes substantially.
◦ The length of a seasonal cycle is generally one year, while the length of a business
cycle is generally longer than one year and its actual length is difficult to predict.
Components of Time Series Data
(slide 4 of 4)
Random variation (or noise) is the unpredictable component that gives most
time series graphs their irregular, zigzag appearance.
◦ A time series can be determined only to a certain extent by its trend, seasonal, and
cyclic components; other factors determine the rest.
◦ These other factors combine to create a certain amount of unpredictability in
almost all time series.
Measures of Accuracy
(slide 1 of 2)
The forecast error is the difference between the actual value and the
forecast. It is denoted by E with appropriate subscripts.
Forecasting software packages typically report several summary
measures of the forecast errors:
◦ MAE (Mean Absolute Error):

◦ RMSE (Root Mean Square Error):

◦ MAPE (Mean Absolute Percentage Error):


Measures of Accuracy
(slide 2 of 2)
Some forecasting software packages choose the best model from a
given class by minimizing MAE, RMSE, or MAPE.
◦ However, small values of these measures guarantee only that the
model tracks the historical observations well.
◦ There is still no guarantee that the model will forecast future values
accurately.
Unlike residuals from the regression equation, forecast errors are not
guaranteed to always average to zero.
◦ If the average of the forecast errors is negative, this implies a bias, or
that the forecasts tend to be too high.
◦ If the average is positive, the forecasts tend to be too low.
Testing for Randomness
(slide 1 of 2)
All forecasting models have the general form shown in the equation
below:

◦ The fitted value is the part calculated from past data and any other available
information.
◦ The residual is the forecast error.
◦ The fitted value should include all components of the original series that can
possibly be forecast, and the leftover residuals should be unpredictable
noise.

The simplest way to determine whether a time series of residuals is


random noise is to examine time series graphs of residuals visually—
although this is not always reliable.
Testing for Randomness
(slide 2 of 2)
Some common nonrandom patterns are shown below.
The Runs Test
The runs test is a quantitative method of testing for randomness. It is a
formal test of the null hypothesis of randomness.
◦ First, choose a base value, which could be the average value of the
series, the median value, or even some other value.
◦ Then a run is defined as a consecutive series of observations that
remain on one side of this base level.
◦ If there are too many or too few runs in the series, the null
hypothesis of randomness can be rejected.
Example 12.1:
Stereo Sales.xlsx (slide 1 of 2)
Objective: To use StatTools’s Runs Test procedure to check whether the
residuals from this simple forecasting model represent random noise.
Solution: Data file contains monthly sales for a chain of stereo retailers
from the beginning of 2009 to the end of 2012, during which there was
no upward or downward trend in sales and no clear seasonality.
A simple forecast model of sales is to use the average of the series,
182.67, as a forecast of sales for each month.
The residuals for this forecasting model are found by subtracting the
average from each observation.
Use the runs test to see whether there are too many or too few runs
around the base of 0.
Select Runs Test for Randomness from the StatTools Time Series and
Forecasting dropdown, choose Residual as the variable to analyze, and
choose Mean of Series as the cutoff value.
Mean is 182.67
Example 12.1:
Stereo Sales.xlsx (slide 2 of 2)
The resulting output is shown below:

> 0.05 => We cannot


reject randomness
Autocorrelation
Another way to check for randomness of a time series of residuals is to
examine the autocorrelations of the residuals.
◦ An autocorrelation is a type of correlation used to measure whether
values of a time series are related to their own past values.
◦ In positive autocorrelation, large observations tend to follow large
observations, and small observations tend to follow small observations.
◦ The autocorrelation of lag k is essentially the correlation between
the original series and the lag k version of the series.
◦ Lags are previous observations, removed by a certain number of periods
from the present time.
◦ To lag a time series in a spreadsheet
by one month, “push down” the series
by one row, as shown below.
Example 12.1 (Continued):
Stereo Sales.xlsx (slide 1 of 2)
Objective: To examine the autocorrelations of the residuals from the forecasting
model for evidence of nonrandomness.
Solution: Use StatTools’s Autocorrelation procedure, found on the StatTools Time
Series and Forecasting dropdown list.
◦ Specify the times series variable (Residual), the number of lags you want, and
whether you want a chart of the autocorrelations, called a correlogram.
◦ It is common practice to ask for no more lags than 25% of the number of observations.
◦ Any autocorrelation that is larger than two standard errors in magnitude is
worth your attention.
◦ One measure of the lag 1 autocorrelation is provided by the Durbin-Watson
(DW) statistic.
◦ A DW value of 2 indicates no lag 1 autocorrelation.
◦ A DW value less than 2 indicates positive autocorrelation.
◦ A DW value greater than 2 indicates negative autocorrelation.
Example 12.1 (Continued):
Stereo Sales.xlsx (slide 2 of 2)
The autocorrelations and correlogram of the residuals are
shown below.
Sales
Autocorrelation Table Data Set #1
Number of Values 48
Standard Error 0.1443
Lag #1 0.3492
Lag #2 0.0772
Lag #3 0.0814
Lag #4 -0.0095
Lag #5 -0.1353
Lag #6 0.0206
Lag 1 autocorrelation is significantly
Lag #7 -0.1494
Lag #8 -0.1492 different from 0 (5% significant level
1
Lag #9 -0.2626 (> 2 se where se = 1/ 𝑇 = 48 = 0.1443,
Lag #10 -0.1792
where T=number of observations)
Lag #11 0.0121
Lag #12 -0.0516
Regression-Based Trend
Models (Trend Projection)
Many time series follow a long-term trend except for random variation.
◦ This trend can be upward or downward.
◦ A straightforward way to model this trend is to estimate a regression
equation for Yt, using time t as the single explanatory variable.
◦ The two most frequently used trend models are the linear trend and
the exponential trend.
Linear Trend
A linear trend means that the time series variable changes by a
constant amount each time period.
The equation for the linear trend model is:
◦ The interpretation of b is that it represents the expected change in
the series from one period to the next.
◦ If b is positive, the trend is upward.
◦ If b is negative, the trend is downward.
◦ The intercept term a is less important: It literally represents the
expected value of the series at time t = 0.
A graph of the time series indicates whether a linear trend is likely to
provide a good fit.
Example 12.2:
US Population.xlsx (slide 1 of 2)

Objective: To fit a linear trend line to monthly population and examine its
residuals for randomness.
Solution: Data file contains monthly population data for the United States
from January 1952 to December 2011. During this period, the population
has increased steadily from about 156 million to about 313 million.
To estimate the trend with regression,
use a numeric time variable
representing consecutive
months 1 through 720.
Then run a simple regression
of Population versus Time.
Example 12.2:
US Population.xlsx (slide 2 of 2)

Use Excel’s® Trendline tool to superimpose a trend line on the time series graph.

Then plot the residuals.

Do these look random?


Exponential Trend
An exponential trend is appropriate when the time series changes by a constant
percentage (as opposed to a constant dollar amount) each period.
The appropriate regression equation contains a multiplicative error term ut:

This equation is not useful for estimation; for that, a linear equation is required.
◦ You can achieve linearity by taking natural logarithms of both sides of the
equation, as shown below, where a = ln(c) and et = ln(ut).

◦ The coefficient b (expressed as a percentage) is approximately the


percentage change per period. For example, if b = 0.05, then the series is
increasing by approximately 5% per period.
If a time series exhibits an exponential trend, then a plot of its logarithm should
be approximately linear.
Example 12.3:
PC Device Sales.xlsx (slide 1 of 2)

Objective: To estimate the company’s exponential growth and to see whether


it has been maintained during the entire period from 1999 until the end of
2013.
Solution: Data file contains quarterly sales data for a large PC device
manufacturer from the first quarter of 1999 through the fourth quarter of
2013.
First, estimate and interpret an exponential trend for the years 1999
through 2008.

 Use Excel’s Trendline tool, with


the Exponential option, to
superimpose an exponential
trend line and the corresponding
equation on the time series
graph through 2008.
Example 12.3:
PC Device Sales.xlsx (slide 2 of 2)

To use this equation for forecasting the future, substitute later values of Time
into the regression equation, so that each future forecast is about 6.54%
larger than the previous forecast.
Check whether the exponential growth continued beyond 2008 by creating
the Forecast column shown below (by substituting into the regression
equation for the entire period through Q4-13).
Then use StatTools to create a time series graph of the two series Sales and
Forecast, also shown below.
The Random Walk Model
The random walk model is an example of using random series as building
blocks for other time series models.
◦ In this model, the series itself is not random.
◦ However, its differences—that is, changes from one period to the next—are
random.
◦ This type of behavior is typical of stock price data and other similar data.
◦ The equation for the random walk model is shown below, where m (mean
difference) is a constant, and et is a random series (noise) with mean 0 and a
standard deviation that remains constant through time.

◦ A series that behaves according to this random walk model has random
differences, and the series tends to trend upward (if m > 0), or downward (if m <
0) by an amount m each period (Yt – Yt-1 = m + et )
◦ If you are standing in period t and want to forecast Yt+1, then a reasonable
forecast is given by the equation below:
Example 12.4:
Stock Prices.xlsx (slide 1 of 2)

Objective: To check whether the


company’s monthly closing prices
follow a random walk model with
an upward trend and to see how
future prices can be forecast.
Solution: The monthly closing
prices of the manufacturing
company’s stock from January
2006 through April 2012 are
shown to the right.
To check for the adequacy of a
random walk model, a series of
differences is required.
Calculate this series with an Excel
formula or generate it
automatically by selecting
Difference from the StatTools Data
Utilities dropdown menu. A runs test for the differences confirmed
randomness of the differences
Example 12.4:
Stock Prices.xlsx (slide 2 of 2)

Next, plot the differences, as shown below.

To forecast future closing prices, multiply the mean difference by the number
of periods ahead, and add this to the final closing price e.g. a forecast for the
Closing Price for Sep 2012 (5 months from April 2012) is:
53.947 + 0.418 (5) = 56.037
Moving Averages Forecasts
One of the simplest and the most frequently used extrapolation models is
the moving averages model.
◦ A moving average is the average of the observations in the past few
periods, where the number of terms in the average is the span.
◦ If the span is large, extreme values have relatively little effect on the
forecasts, and the resulting series of forecasts will be much smoother
than the original series.
◦ For this reason, this method is called a smoothing method.
◦ If the span is small, extreme observations have a larger effect on the
forecasts, and the forecast series will be much less smooth.
◦ Using a span requires some judgment:
◦ If you believe the ups and downs in the series are random noise, use a
relatively large span.
◦ If you believe each up and down is predictable, use a smaller span.
Example 12.5:
House Sales.xlsx (slide 1 of 3)

Objective: To see whether a moving averages model with an appropriate span


fits the housing sales data and to see how StatTools implements this method.
Solution: Data file contains monthly data on the number of new one-family
houses sold in the U.S. from January 1991 through December 2011.
Select Forecast from the StatTools Time Series and Forecasting dropdown list.
Then select the time period on the Time Scale tab, and Moving Average on
the Forecast Settings tab.
Example 12.5:
House Sales.xlsx (slide 2 of 3)

The output consists of several parts, with the summary measures MAE, RMSE,
and MAPE of the forecast errors included.
Example 12.5:
House Sales.xlsx (slide 3 of 3)

The graphs below show the behavior of the forecasts. The


first is with span 3; the second is with span 12.
Exponential Smoothing
Forecasts
Exponential smoothing bases its forecasts on a weighted average of
past observations, with more weight on the more recent observations.
There are many variations of exponential smoothing, including:
◦ Simple exponential smoothing—appropriate for a series with no
pronounced trend or seasonality
◦ Holt’s method—appropriate for a series with trend but no
seasonality
◦ Winters’ method—appropriate for a series with seasonality (and
possibly trend)
Simple Exponential Smoothing
Every exponential model has at least one smoothing constant, which is
always a number between 0 and 1.
◦ Simple exponential smoothing has a single smoothing constant denoted
by α.
The level of the series at time t (Lt) is an estimate of where the series
would be at time t if there were no random noise.
The simple exponential method is defined by the following two equations:

◦ The second equation says that the k-period-ahead forecast, Ft+k, made
of Yt+k in period t is essentially the most recently estimated level, Lt.
Example 12.5 (Continued):
House Sales.xlsx (slide 1 of 2)
Objective: To see how well a simple
exponential smoothing model, with an
appropriate smoothing constant, fits
the housing sales data, and to see how
StatTools implements this method.
Solution: Select Forecast from the
StatTools Time Series and Forecasting
dropdown list.
Then select the simple exponential
smoothing option in the Forecast
Settings tab, and choose a smoothing
constant.
The results are shown to the right.
Example 12.5 (Continued):
House Sales.xlsx (slide 2 of 2)
The graph below shows the forecast series superimposed on the original
series.
Holt’s Model for Trend
When there is a trend in the series, Holt’s method deals with it explicitly by
including a trend term, Tt, and a corresponding smoothing constant β.
◦ The interpretation of Lt is exactly as before.
◦ The interpretation of Tt is that it represents an estimate of the change
in the series from one period to the next.
The equations for Holt’s model are shown below:
Example 12.5 (Continued):
House Sales.xlsx (slide 1 of 2)
Objective: To see whether Holt’s
method, with appropriate
smoothing constants, captures
the trends in the housing sales
data better than simple
exponential smoothing (or
moving averages).
Solution: Implement Holt’s
method in StatTools almost
exactly as for simple exponential
smoothing.
The only difference is that you
now choose two smoothing
constants.
The output is very similar to the
simple exponential smoothing
output, except that there is now a
trend column.
Example 12.5 (Continued):
House Sales.xlsx (slide 2 of 2)
Now perform a second run of Holt’s method, using the Optimize Parameters
option.
The forecasts with nonoptimal smoothing constants are shown below, on
the left. The forecasts with optimal smoothing constants are shown below,
on the right.
Seasonal Models
Seasonality is the consistent month-to-month (or quarter-to-quarter) differences
that occur each year.
◦ The easiest way to check for seasonality is graphically: Look for a regular pattern of ups
and/or downs in particular months or quarters.
There are three basic methods for dealing with seasonality:
◦ Winters’ exponential smoothing model
◦ Deseasonalizing the data (then use any forecasting method to model the deseasonalized
data and finally “reseasonalize” these forecasts)
◦ Multiple regression with dummy variables for the seasons
Seasonal models are classified as additive or multiplicative.
◦ In an additive seasonal model, an appropriate seasonal index is added to a base
forecast.
◦ The indexes, one for each season, typically average to 0.
◦ In a multiplicative seasonal model, a base forecast is multiplied by an appropriate
seasonal index.
◦ These indexes, one for each season, typically average to 1.
Winters’ Exponential
Smoothing Model
Winters’ exponential smoothing model is very similar to Holt’s model, but it
also has seasonal indexes and a corresponding smoothing constant γ.
◦ This new smoothing constant controls how quickly the method reacts to observed
changes in the seasonality pattern.
◦ If the constant is small, the method reacts slowly.
◦ If it is large, the method reacts more quickly.
◦ The equations for this method are shown below:
Example 12.6:
Soft Drink Sales.xlsx (slide 1 of 2)

Objective: To see how well Winters’ method, with appropriate


smoothing constants, can forecast the company’s seasonal soft drink
sales.
Solution: Data file contains quarterly sales for a large soft drink
company from quarter 1 of 1997 through quarter 4 of 2012.
There has been an upward trend in sales during this period, and there
is also a fairly regular seasonal pattern: sales in the warmer quarters
are consistently higher than in the colder quarters.
Proceed in StatTools exactly as with the other exponential smoothing
methods, but hold out some of the data for validation.
Fill in the Forecast Settings tab, selecting Winters’ method, basing the
model on the data through Q4-2010, holding out eight quarters of
data (Q1-2011 through Q4-2012), and forecasting four quarters into
the future (all of 2013).
Example 12.6:
Soft Drink Sales.xlsx (slide 2 of 2)

Parts of the output are shown below, on the left.


The plot of the forecasts superimposed on the original series is shown below,
on the right.
Deseasonalizing:
The Ratio-to-Moving-Averages
Method
Most methods for deseasonalizing time series data are variations of the
ratio-to-moving-averages method.
◦ To deseasonalize an observation (assuming a multiplicative model of
seasonality), divide it by the appropriate seasonal index.
◦ To find the seasonal index for a particular month, divide the month’s
observation by the average of the 12 observations surrounding it.
◦ There is a minor problem with this approach: Any one month is not
in the middle of any 12-month sequence.
◦ Compromise by averaging the two possible averages. (For June, this
would be the January-to-December and December-to-November
averages.) This is called a centered average.
The usual way to combine all of the indexes for a specific month (if the
series covers several years) is to average them.
Example 12.6 (Continued):
Soft Drink Sales.xlsx (slide 1 of 2)
Objective: To use the ratio-to-moving-averages method to deseasonalize the
soft drink data and then forecast the deseasonalized data.
Solution: In StatTools, proceed as with the other exponential smoothing
methods, but check the Deseasonalize option in the Time Scale tab of the
Forecast dialog box.
Selected outputs
are shown below.
Example 12.6 (Continued):
Soft Drink Sales.xlsx (slide 2 of 2)
The deseasonalized data, with forecasts superimposed, are shown below, on
the left.
The results of reseasonalizing are shown below, on the right.
Estimating Seasonality with
Regression
A regression approach to forecasting seasonal data uses dummy variables
for the seasons.
◦ Depending on how the regression equation is written, you can create
either an additive or a multiplicative seasonal model.
◦ For example, for quarterly data, create three dummy variables for the
first three quarters (using quarter 4 as the reference quarter) and
estimate the additive equation:
◦ Then the coefficients of the dummy variables, b1, b2, and b3, indicate
how much each quarter differs from the reference quarter, and the
coefficient b represents the trend.
◦ It is also possible to estimate a multiplicative model using dummy
variables for seasonality (and possibly time for trend).
◦ An advantage of this approach is that it provides a model with
multiplicative seasonal factors and is fairly easy to interpret.
Example 12.6 (Continued):
Soft Drink Sales.xlsx (slide 1 of 2)
Objective: To use a multiplicative regression equation, with dummy variables
for seasons and a time variable for trend, to forecast soft drink sales.
Solution: The data setup is shown below, with dummy variables for three of the
four quarters and a Log(Sales) variable.
Then use multiple regression, with Log(Sales) as the dependent variable, and
Time, Q1, Q2, and Q3 as the explanatory variables.
Example 12.6 (Continued):
Soft Drink Sales.xlsx (slide 2 of 2)
The regression output is
shown on the top right.
A plot of observations
versus forecasts for this
model is shown on the
bottom right.

You might also like