Sei sulla pagina 1di 658

Business Forecasting

Using SAS : A Point-and-


Click Approach

Course Notes
For Your Information ii

Business Forecasting Using SAS: A Point-and-Click Approach Course Notes was developed by Terry
Woodfield and Bob Lucas. Additional contributions were made by Michael Leonard of SAS and David
Dickey of North Carolina State University. Editing and production support was provided by the
Curriculum Development and Support Department.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of
SAS Institute Inc. in the USA and other countries. indicates USA registration. Other brand and product
names are trademarks of their respective companies.

Business Forecasting Using SAS: A Point-and-Click Approach Course Notes


Copyright 2006 by SAS Institute Inc., Cary, NC 27513, USA. All rights reserved. Printed in the
United States of America. No part of this publication may be reproduced, stored in a retrieval system,
or transmitted, in any form or by any means, electronic, mechanical, photocopying, or otherwise, without
the prior written permission of the publisher, SAS Institute Inc.

Book code E70124, course code FETS, prepared date 29Mar06 FETS_002
For Your Information iii

Table of Contents

Course Description ...................................................................................................................... vi

Prerequisites ...............................................................................................................................vii

Chapter 1 Business Forecasting .......................................................................... 1-1

1.1 Introduction to Business Forecasting...............................................................................1-3

1.2 Introduction to Time Series Forecasting ........................................................................1-41

1.3 Measuring Forecast Accuracy........................................................................................1-71

1.4 Descriptive and Exploratory Analysis of Time Series Data...........................................1-77

1.5 Chapter Summary ........................................................................................................1-102

1.6 Solutions to Exercises ..................................................................................................1-103

Chapter 2 Simple Forecast Models ...................................................................... 2-1

2.1 Modeling Trend................................................................................................................2-3

2.2 Modeling Seasonality ....................................................................................................2-34

2.3 Using Special Variables to Model Events ......................................................................2-55

2.4 Exponential Smoothing Forecast Models ......................................................................2-75

2.5 Exponential Smoothing Models with Trend and Seasonal Components .......................2-98

2.6 Chapter Summary ........................................................................................................2-109

2.7 Solutions to Exercises .................................................................................................. 2-111

Chapter 3 Advanced Forecast Models for Stationary Time Series.................... 3-1

3.1 Introduction to Box-Jenkins Forecasting .........................................................................3-3

3.2 Autoregressive Models ..................................................................................................3-14

3.3 Moving Average Models................................................................................................3-21


iv For Your Information

3.4 Mixed Autoregressive Moving Average Models............................................................3-23

3.5 Identifying an Appropriate Autoregressive Moving Average Model.............................3-26

3.6 Estimation and Forecasting Methods.............................................................................3-61

3.7 Chapter Summary ........................................................................................................3-108

3.8 Solutions to Exercises ..................................................................................................3-109

Chapter 4 Advanced Forecast Models for Nonstationary Time Series ............. 4-1

4.1 The Use of Differencing to Model Trend and Seasonality ..............................................4-3

4.2 Trend Models .................................................................................................................4-10

4.3 Seasonal Models ............................................................................................................4-47

4.4 Chapter Summary ..........................................................................................................4-85

4.5 Solutions to Exercises ....................................................................................................4-86

Chapter 5 Forecast Models with Explanatory Variables..................................... 5-1

5.1 Ordinary Regression Models ...........................................................................................5-3

5.2 Event Models .................................................................................................................5-14

5.3 Time Series Regression Models.....................................................................................5-57

5.4 Chapter Summary ..........................................................................................................5-82

5.5 Solutions to Exercises ....................................................................................................5-83

Appendix A Basic Forecasting Using SAS Enterprise Guide (Self-Study) ......... A-1

A.1 Basic Forecasting Using SAS Enterprise Guide ............................................................. A-3

Appendix B Processing Time Series Data with SAS Enterprise Guide (Self-Study)B-1

B.1 Processing Time Stamped Transactional Data ................................................................ B-3

B.2 Transposing Data .......................................................................................................... B-23

B.3 Changing the Frequency of Time Series Data .............................................................. B-38


For Your Information v

B.4 Augmenting Data with Event Variables........................................................................ B-65

B.5 Chapter Summary ......................................................................................................... B-74

B.6 Solutions to Exercises ................................................................................................... B-75

Appendix C Processing Time Series Data with SAS Code (Self-Study).............. C-1

C.1 Processing Time Stamped Transactional Data ................................................................ C-3

C.2 Transposing Data ............................................................................................................ C-9

C.3 Changing the Frequency of Time Series Data .............................................................. C-13

C.4 Augmenting Data with Event Variables........................................................................ C-20

C.5 Chapter Summary ......................................................................................................... C-24

Appendix D Index ..................................................................................................... D-1


vi For Your Information

Course Description

This course teaches business analysts how to carry out forecasting projects using the point-and-click
interface in the Time Series Forecasting System in SAS/ETS software. SAS Enterprise Guide software is
employed for time series data processing. Course topics include exponential smoothing models,
autoregressive integrated moving average models, and dynamic regression models.

To learn more

A full curriculum of general and statistical instructor-based training is available


at any of the Institutes training facilities. Institute instructors can also provide
on-site training.
For information on other courses in the curriculum, contact the SAS Education
Division at 1-800-333-7660, or send e-mail to training@sas.com. You can also
find this information on the Web at support.sas.com/training/ as well as in the
Training Course Catalog.

For a list of other SAS books that relate to the topics covered in this
Course Notes, USA customers can contact our SAS Publishing Department at
1-800-727-3228 or send e-mail to sasbook@sas.com. Customers outside the
USA, please contact your local SAS office.
Also, see the Publications Catalog on the Web at support.sas.com/pubs for a
complete list of books and a convenient order form.
For Your Information vii

Prerequisites
Before selecting this course you should be able to perform the following tasks:

Create and access SAS data sets using the SAS windowing environment or a product such as SAS
Enterprise Guide

Use software to explore and analyze data, including the ability to create graphical displays of data

Evaluate quantitative forecasts related to a business problem based on your advanced domain
knowledge in an area such as finance, manufacturing, or retail
A typical student will have college course work in a quantitative area, such as a basic business statistics
course. Furthermore, a student should have experience using a product such as Microsoft Excel or a
similar product for data summarization and presentation.
SAS offers the following courses that may help provide some of the prerequisite knowledge and skills:
SAS Programming I: Essentials
Querying and Reporting Using SAS Enterprise Guide
Statistics I: Introduction to ANOVA, Regression, and Logistic Regression

SAS Enterprise Guide: ANOVA, Regression, and Logistic Regression


The SAS Programming I: Essentials and Statistics I: Introduction to ANOVA, Regression, and Logistic
Regression require programming in the SAS windowing environment. The SAS Enterprise Guide courses
cover similar topics, but minimal programming is required in the SAS Enterprise Guide environment.
viii For Your Information
Chapter 1 Business Forecasting

1.1 Introduction to Business Forecasting..........................................................................1-3

1.2 Introduction to Time Series Forecasting....................................................................1-41

1.3 Measuring Forecast Accuracy.....................................................................................1-71

1.4 Descriptive and Exploratory Analysis of Time Series Data ......................................1-77

1.5 Chapter Summary.......................................................................................................1-102

1.6 Solutions to Exercises ...............................................................................................1-103


1-2 Chapter 1 Business Forecasting
1.1 Introduction to Business Forecasting 1-3

1.1 Introduction to Business Forecasting

Objectives
Create forecasts for the United States domestic airline
passengers data using the Time Series Forecasting
System (TSFS) as a data exploration tool.
Discuss the importance of measuring accuracy, and
introduce accuracy measures Mean Absolute Percent
Error (MAPE) and Root Mean Square Error (RMSE).
Provide an overview of the Time Series Forecasting
System.
Describe several major business forecasting problems
and discuss the skills and tools that are required to
forecast accurately in a business setting.

This course addresses the general business forecasting problem in the context of statistical time series
analysis. A number of time series forecasting concepts can be illustrated using the airline passengers data
that is supplied by the United States Department of Transportation, Bureau of Transportation Statistics.
The data are for domestic flights in the United States.
1-4 Chapter 1 Business Forecasting

Airline Passengers 19902004

The airline data illustrate seasonality, because there are seasonal patterns with respect to when people fly.
For example, more people fly in August than in February. The data illustrate trend, because the number of
passengers is increasing from year to year. The data illustrate the effect of events, because the events of
September 11, 2001, had a significant negative impact on airline travel.
Consider the above data restricted to years 1994 through 1997. This restricted period allows you to focus
on trend and seasonality without having to worry about the effects of external events. To validate data
preparation and to formulate forecast models for a time series, a time plot of the data is produced.
1.1 Introduction to Business Forecasting 1-5

Airline Passengers 19941997

You can readily see trend and seasonality in the data as described above. A list of the four years of
passenger data follows.
1-6 Chapter 1 Business Forecasting

Airline Data Listing

The time series plot of the data is much more revealing than a table of data values.
Because trend and seasonality dominate this data set, you should be able to propose forecasts for future
time points with very little forecasting expertise. Again, trend for the airline passengers time series
implies that in general the number of passengers is increasing over time. Seasonality for the data implies
that, after accounting for trend, a value for a given month is more highly correlated with the same month
in the previous year than with any other month. For example, this means that August 1997 is more like
August 1996 than July 1997.
1.1 Introduction to Business Forecasting 1-7

Exercises

1. Provide a forecast for domestic airline passengers for the following months using only data through
December 1997.
a. January 1998 (one step ahead)
b. February 1998 (two steps ahead)
c. August 1998 (eight steps ahead)
2. What assumption did you make about trend to derive at your forecasts?
3. What assumption did you make about seasonality to derive your forecasts?
The purpose for the exercises above was to show that you probably have intuition about how to forecast
even if you lack the technical skills to forecast accurately. Fortunately, SAS software will perform the
tedious calculations to derive forecasts so that you do not have to.
1-8 Chapter 1 Business Forecasting

Forecasting the Airline Data


Date Time Method 1 Method 2 Excel TSFS
Index Forecast Forecast Forecast Forecast
Jan 1998 49 53,003,499 52,490,019 56,526,532 49,899,266

Feb 1998 50 47,174,447 50,176,653 56,741,011 48,518,747

Mar 1998 51 60,507,806 61,617,314 56,955,490 59,229,704

Apr 1998 52 55,544,638 56,842,694 57,169,969 55,845,668

May 1998 53 57,558,591 58,499,927 57,384,448 57,358,207

Jun 1998 54 60,327,251 60,961,892 57,598,927 60,310,142

Jul 1998 55 64,413,945 63,742,040 57,813,406 63,235,017

Aug 1998 56 64,087,614 64,504,980 58,027,885 64,580,097

Sep 1998 57 53,844,284 53,487,157 58,242,364 54,382,222

Oct 1998 58 56,407,889 57,117,825 58,456,843 57,799,775

Nov 1998 59 54,778,094 53,240,009 58,671,321 54,084,748

Dec 1998 60 54,428,206 56,025,882 58,885,800 56,488,484


8

In the solutions to Exercise 1 given in section 1.5, two nave methods for forecasting are proposed. These
will be named Method 1 and Method 2 respectively. In addition, the Microsoft Excel FORECAST
function is employed to forecast the number of passengers. Finally, the Time Series Forecasting System
(TSFS) is used to generate forecasts automatically. Automatic forecasts require no user input other than
the location of the data and designation of which series to forecast. The forecasts for the next 12 months
after the end of the data are given in the above table.
Even if you are not in the airline industry, you can understand why forecasts are important. If an airline
has 10% market share, it can expect to have 5,888,580 passengers in December 1998 if the Excel forecast
is used. This forecast is derived looking ahead from December 1997. If the airline had 5,380,108
passengers in December 1997, then it can expect an increase in passengers of about 9.5%. To
accommodate this projected increase, the airline may have to add personnel and aircraft. Consequently,
forecast accuracy is critical. Forecasting too high leaves empty seats. Forecasting too low sends
passengers to other airlines. Suppose management is confronted with the above table of forecasts. How
will a manager decide which forecast to use?
1.1 Introduction to Business Forecasting 1-9

Which Forecast?
An airline is planning for December 1998 in early
January 1998.

Date Method 1 Method 2 Excel TSFS


Dec 1997 53,801,076 53,801,076 53,801,076 53,801,076
Dec 1998 54,428,206 56,025,882 58,885,800 56,488,484
% Change 1.17 4.14 9.45 5.00
If the forecast is too low, the airline will send
passengers to competitors.
If the forecast is too high, the airline will have empty
seats.
Which forecast should the airline use?

Forecasting the Airline Data


Airline Passenger Forecasts for 1998

70,000,000

65,000,000

60,000,000
Passengers

55,000,000

50,000,000

45,000,000

40,000,000
N

V
N

G
L

T
P
R
AR

C
B

AY

JU
JU

NO
C
SE
JA

FE

AP

AU

DE
O
M

98
98

98
98

98
98

98

98

98

98
98

98

19
19

19
19

19
19

19

19

19

19
19

19

Date

Method 1 Method 2 Excel TSFS Actual


10

Overlaying the line plot of the forecasts with the actual 1998 values helps to determine which forecasts
are superior. You immediately observe that the Excel FORECAST function produces a simple linear
trend line to forecast the future. The Excel forecasts are rejected because they do not reflect the
seasonality in the data. For the remaining three forecasts, the plot is inadequate to select a winner.
1-10 Chapter 1 Business Forecasting

Picking a Winning Set of Forecasts


Good forecasts should
be highly correlated with the actual series values

exhibit small forecast errors

capture salient features of the original time series.

In addition, forecast quality should be based on the


business problem being addressed.

11

Pearsons correlation coefficient can be used to measure the correlation between forecast and actual
values. Recall, Pearsons correlation is given by

( x x )( y y ) 1 1
xi , y = y i .
i i
r= ,x =
( x x ) ( y y)
i
2
i
2 n n

As a measure of forecast accuracy, in the above equation, x represents the actual time series values, and y
represents the forecasts. In general, forecast values at time t are denoted by y t , and actual values are
denoted by y t . The error or residual is derived as

et = y t y t .

The average error should be near zero. If the average error is significantly different than zero, the
forecasts are judged to be biased.
1.1 Introduction to Business Forecasting 1-11

Model Diagnostic Statistics


Notation for Basic Quantities

Series Length: n

Number of Model Parameters to Estimate: k

Model Likelihood Function Evaluated at Maximum: L

Sum of Squared Errors: SSE

Predicted Target Value Yt at Time t: Yt


continued...

12
1-12 Chapter 1 Business Forecasting

Model Diagnostic Statistics


n n
R-Square:
R 2 = 1 (Yt Yt ) 2 (Y Y )
t t
2

t =1 t =1

Root Mean Squared Error:

1 n
MSE =
n k t =1
(Yt Yt ) 2 *

RMSE = MSE

*The TSFS uses divisor n rather than n-k.


continued...

13

When the forecast value is derived using a linear regression model, the square of Pearsons correlation
coefficient is equivalent to the popular R 2 (R-Square) statistic. In practice, Pearsons correlation and
average error are seldom used as primary accuracy diagnostics. These measures will be used in this work
to motivate the accuracy measures that are commonly used. R-Square is never appropriate for
evaluating time series models. Some sources redefine R-Square so that it is more appropriate for time
series modeling. The above definition can actually lead to negative values if the model is nonlinear, which
is a contradiction for a squared quantity based on non-complex numbers. The Time Series Forecasting
System provides some alternative R-Square measures.
1.1 Introduction to Business Forecasting 1-13

Model Diagnostic Statistics


Mean Absolute Percent Error:
1 n
MAPE = | Yt Yt | / Yt
n t =1

Mean Absolute Error:

1 n
MAE =
n t =1
| Yt Yt |

14

Other model diagnostic statistics are introduced later. The three primary diagnostics, RMSE, MAPE, and
MAE, have some intuitive appeal. It should be obvious that smaller values are better. If predictions are
highly correlated with actual values and errors are small, RMSE and MAE will tend to be small. MAPE is
based on relative error with respect to the actual value of the target and is only valid when a series and its
forecasts are positive.

 The above MAPE quantity is often multiplied by 100 to express it as a percentage. This practice
will be followed in these course notes. For example, if using the above formula you get an MAPE
value of 0.0211, it will be expressed as 2.11, or 2.11%.
You are now prepared to examine the forecasts for the airline passengers data in more detail. In January
1999, you can look back on 1998 and see how accurate the forecasts were.
1-14 Chapter 1 Business Forecasting

Forecasting the Airline Data


Statistic Method 1 Method 2 Excel TSFS
RMSE 1,475,303.50 1,674,853.90 4,814,807.31 1,109,956.29
MAPE 2.11 2.38 7.28 1.63
MAE 1,151,842.91 1,303,556.89 3,971,472.76 933,760.42
Ave Error -443,958.92 -996,469.43 -1,310,436.5 -415,276.58
Pearson r 0.956 0.960 0.270 0.977

15

The above statistics are based on comparing known 1998 values to forecast values. The TSFS produces
forecasts with the largest Pearsons r and the smallest average error. In addition, the three model
diagnostic statistics for TSFS forecasts are smaller than any of the corresponding statistics for the other
three forecast methods. The TSFS forecasts are also easier to obtain. Based on this retrospective study,
you should have used the TSFS forecasts in January 1998 for December 1998.

 In practice, a single accuracy diagnostic is selected before the data is obtained. This accuracy
diagnostic should be chosen based on the business problem if possible. Otherwise, it may be
chosen based on theoretical properties. Primary model selection should emphasize the selected
accuracy statistic. You can look at other statistics to see how robust model selection is with
respect to selection criteria. For example, for the airline data, the TSFS forecast model is robust
because it would have been chosen no matter which statistic you picked. It is improper to cherry
pick, a practice that involves picking a model based on how well you subjectively like the
forecasts. After you have let your biases influence your decision, you calculate all possible
accuracy statistics and choose the accuracy statistic that selects the model you like.
1.1 Introduction to Business Forecasting 1-15

Simulating a Retrospective Study


1. Divide the time series data into two segments. The
fit sample is used to derive a forecast model. The
holdout sample will be used to evaluate forecast
accuracy.
2. Derive a set of candidate models.
3. Calculate the chosen model accuracy statistic by
forecasting the holdout sample.
4. Pick the model with the best accuracy statistic.

16

Before obtaining the data, as stated above, you must select one of the accuracy statistics based on the
business problem. In marketing and inventory management, MAPE is commonly chosen. RMSE is
commonly used in all areas of business. R-Square is also very common, but as you have seen, R-Square
should never be used to evaluate forecast models.
The simulated retrospective study simulates what would have been experienced if the forecast model had
been implemented on the date of the first series value in the holdout sample. The use of a simulated
retrospective study to pick a model is known as honest assessment. Unfortunately, honest assessment is
not presented in many modern forecasting textbooks. Because many textbook data sets are small, honest
assessment is often not possible. In your work, you may discover that you are rarely able to carry out a
simulated retrospective study because of data limitations.
1-16 Chapter 1 Business Forecasting

Choosing the Holdout Sample


If possible, choose enough time points to cover a
complete seasonal period. For example, for monthly
data, hold out at least 12 observations.
The holdout sample is always at the end of the series.
If unique behavior occurs within the holdout sample,
do not use a holdout sample. Instead, base accuracy
calculations on the entire series.
If there is insufficient data to fit a model without the
holdout sample, then do not use a holdout sample.
Again, base accuracy calculations on the entire series.

17

Rules of Thumb
At least four time points are required for every
parameter to be estimated in a model.
Anything above the minimum series length can be
used to create a holdout sample.
Holdout samples should rarely contain over 25% of
the series.

18
1.1 Introduction to Business Forecasting 1-17

Examples
A series of four years of monthly data are available. A
model that contains six parameters is to be fit to the
data.
Because 48>64, you can use 48-24=24 data
points in the holdout sample.
Because 24 is 50% of 48, pick a smaller number.
Choose a holdout sample of size 12. This will
accommodate a complete year of monthly data,
and it represents 25% of the entire series.

continued...

19

Examples
Two years of weekly data are available.
The holdout sample cannot include a full year cycle
of 52 weeks because this is half of the data.
25% of 104 data points is 26. Unfortunately,
holding out 26 weeks of data means that some
weeks will be represented only one time in the fit
sample.
If the end of the data corresponds to the end of the
year, any holdout sample will remove the critical
Christmas season from the last year of data.
Decision: A holdout sample is too risky and will not
be used.
continued...

20
1-18 Chapter 1 Business Forecasting

Examples
A series contains five years of weekly sales data
ending in the last full week of August 2005. On July 1,
2005, a law takes effect that is projected to increase
sales.
There is enough data to employ a holdout sample
of 52 weeks of data.
Unfortunately, because a critical event occurs in
the last eight weeks of the series, no holdout
sample can be employed.

21

Summary of Data Used for Forecast Model


Building

Fit Sample Holdout Sample

Used to estimate model Used to evaluate model


parameters for accuracy accuracy
evaluation Simulates retrospective
Used to forecast values in study
holdout sample

Full = Fit + Holdout data is used to fit deployment model

22

For model deployment or for generating forecasts for decision making, the chosen model is refit to the
entire data set.
1.1 Introduction to Business Forecasting 1-19

Three Environments for Forecasting Using


SAS Software*
The SAS Windowing Environment
The Time Series Forecasting System
SAS Enterprise Guide

*SAS supports many environments and applications for forecasting.


For example, the SAS Forecast Server provides large-scale
forecasting support.
23

SAS supports both general business applications, such as time series forecasting, as well as specific
applications, such as supplier relationship management for manufacturing. Many of the business-specific
applications supported by SAS have a time series forecasting component. The time series concepts
learned in this course will allow you to be proficient with the time series components of business
applications supported by SAS.
1-20 Chapter 1 Business Forecasting

The SAS Windowing Environment


The SAS windowing environment is both a
programming and an interactive menu-driven
environment.
Programming (scripting) is performed using the
program editor.
A log file tracks execution with performance statistics
and warning/error messages.
An output file contains any standard output from
program execution. Standard output is formatted using
ASCII or EBCDIC, whichever is native to the operating
system.

continued...

24

The log file tracks execution of menu-driven applications as well as SAS programs.
1.1 Introduction to Business Forecasting 1-21

The SAS Windowing Environment


The Output Delivery System (ODS) allows the user to
customize output, for example, to produce HTML or
PDF output rather than ASCII output.
The Results window tracks all forms of output and
allows the user to select particular output to view.
The SAS Explorer window allows access and
management of SAS tables and catalogs, including
catalogs that contain graphics objects.
The menu bar permits access to menu-driven
applications, like the Time Series Forecasting System.

continued...

25

For a Microsoft Windows environment, the output window contains ASCII text. Any output formatted
using the Output Delivery System (ODS) must be viewed using an add-in that supports the format. SAS is
distributed with add-ins for HTML and PDF output. You can also view HTML results in a Web browser,
and Adobe Acrobat can be used to view PDF files. A variety of graphics formats are supported, such as
GIF, JPEG, and PostScript, but the graphics formats that you have access to are governed by your SAS
license. By default, SAS uses its own graphics format and stores plots and other graphics objects in a SAS
graphics catalog. You can convert any SAS graphics catalog object into a specific graphics format
provided you have licensed the drivers for that format
1-22 Chapter 1 Business Forecasting

The SAS Windowing Environment


Start Programs SAS SAS 9.1

Menu Bar

Log Window

SAS Explorer
Window Program Editor
Window

Output Window
Tab

26

The windowing environment provides separate windows for the program editor, the session log, and the
output produced during the session. By default, the contents of log and output windows are erased when
SAS terminates. You can store results permanently as text files.
1.1 Introduction to Business Forecasting 1-23

The SAS Windowing Environment

SAS Results
Viewer

SAS Results
Window

27

When a program or an application is executed, the Results window catalogs the output in a tree format. In
the above screen capture, a plot of the data is produced using an ActiveX device, which produces a JPEG
file referenced within an HTML file. The Results Viewer employs an HTML viewer to display the output.
In this course, you will use the SAS windowing environment to access the Time Series Forecasting
System (TSFS). You have already seen that the Time Series Forecasting System produces high quality
forecasts, at least compared to three other methods for forecasting.
1-24 Chapter 1 Business Forecasting

The Time Series Forecasting System (TSFS)


The TSFS is included with SAS/ETS software, but it
also requires that SAS/GRAPH software be licensed.
The TSFS is a menu-driven application produced
using the SAS Control Language (SCL), the SAS
language, and a variety of Base SAS and SAS/ETS
procedures.
Functionality of the TSFS ranges from nave automatic
model selection to advanced dynamic time series
regression models.
The TSFS is a complete forecasting solution.

28

Accessing the TSFS from the SAS Windowing


Environment
Type forecast in
the command window.

Choose Solutions
Analysis
Time Series
Forecasting System.

Invoke
dm 'forecast'; dm 'forecast';
29
from autoexec.sas.

There are several different ways to access the TSFS. You can configure your SAS setup so that the TSFS
is activated when you invoke SAS.
1.1 Introduction to Business Forecasting 1-25

The TSFS Main Menu

30

The TSFS main menu opens with a new project. The default name of the project is PROJ. If project PROJ
exists, then PROJ1 will be used. If PROJ1 exists, then PROJ2 will be used, and so on.
1-26 Chapter 1 Business Forecasting

A TSFS Project
A TSFS project is stored as a catalog entry. By default,
the SASUSER.FMSPROJ catalog is employed.

31

The project AIR9497 is stored as a catalog entry in SASUSER.FMSPROJ. This is a special catalog that is
created when SAS/ETS is installed. FMS stands for Forecast Menu System, which is another name for the
TSFS. You do not have to use the default catalog. Any SAS catalog is acceptable. You can create a new
catalog simply by entering the name in the project window. For example, if you enter the project as
FETS.MYCAT.MYPROJ in the project window, when you save the project, a catalog in the FETS library
with name MYCAT will be created, and project entry MYPROJ will be saved in the catalog.

TSFS Buttons

Plot the series

View the series

Comprehensive Modeling
and Forecasting
32
1.1 Introduction to Business Forecasting 1-27

The button that produces a plot of the series actually appears first.

The Series Selection Window

33

First you select a library by positioning the cursor over the library name and clicking the left mouse
button. Next you select a SAS data set stored in the library. If a variable named DATE is in the SAS data
set that you select, then the TSFS will try to use this variable as a SAS date or datetime variable. If the
variable DATE does not satisfy the requirements of the TSFS for a date or datetime variable, then an error
message window will announce the problem. More will be said about date variable requirements later. If
no variable named DATE exists, then the TSFS will expect you to specify a variable as a date variable, or
it will require that you create a date variable and add it to the data. The final step is to select a variable as
the time series to be plotted by clicking on the name of the variable in the Time Series Variables window.
Select Graph to produce a plot of this time series.

 The generality of SAS software has lead to a confusion of overlapping jargon to describe data. A
SAS data set is just a data table like you encounter in relational databases. A SAS table contains
rows and columns. A column represents a field in database jargon, but a field is also called a
variable in statistical data analysis jargon. A row represents a record in database jargon, or an
observation in statistical jargon.
1-28 Chapter 1 Business Forecasting

The Time Series Viewer

34

If a SAS data set with a valid date variable has already been selected, the Time Series Viewer will appear
immediately. If you want to change any of the data set specifications, click the back arrow button at the
far right of the buttons in the upper left corner. This will place you back in the Series Selection window

The Data View in the Time Series Viewer

35

If you click on the lowest button on the right, you will get a spreadsheet view of the data.
1.1 Introduction to Business Forecasting 1-29

The Viewtable

36

You can also view the data by clicking on the view the series button on the main menu. This action
produces a SAS viewtable view of the data. You can also access a viewtable for any SAS data set by
double-clicking on the data set name in the SAS Explorer..
1-30 Chapter 1 Business Forecasting

The Automatic Model Fitting Window

continued...

37

For your first experience with the TSFS, you should experiment with automatic model fitting. You access the
Automatic Model Fitting window by clicking the Fit Models Automatically button on the main menu. By
default, every numeric variable in the SAS data set except for the date variable will be forecast automatically.
The default selection criterion is RMSE. In the above window, MAPE has been selected by the user.

The Automatic Model Fitting Window


The Passengers time series has been selected.
RMSE has been selected to evaluate accuracy.

38
1.1 Introduction to Business Forecasting 1-31

In the above window, the user has clicked on the Select button to specify the PASSENGERS time
series. The user has also switched back to the default RMSE selection criterion.

Model Selection Criterion Window

All Available

Most Popular

39

The Model Selection Criterion window appears when you click on the Select button by the Selection
Criterion window. By default, MSE, RMSE, MAE, MAPE, and R-Square are available as selection
criteria. R-Square is available even though it should never be employed as the primary model selection
statistic. If you click the toggle circle next to Show All, then the complete list of selection criteria is
provided. Variations of R-Square that may be appropriate for model selection are available.
1-32 Chapter 1 Business Forecasting

Looking for the Best Forecast Model


A nuisance window prevents
forecasting unnecessarily.

As each candidate model is tried, a window appears.


40

The nuisance window appears to prevent you from forecasting a large number of numeric variables when
only a few variables represent time series to be forecast.
A set of 82 models is installed with the TSFS. Three rules are used to determine which subset of the 82
models should be used. For the airline data, the three rules determine that only 20 models need to be
examined. When you click Run in the Automatic Model Fitting window and you click OK in the
nuisance window, a series of 20 windows will appear as each model is fit to the data. On modern
computers, these windows usually appear for only a fraction of a second apiece.
1.1 Introduction to Business Forecasting 1-33

Automatic Model Fitting Results Window

Honest assessment is not employed in automatic model


fitting. The Develop Models Window must be used for
honest assessment.
The accuracy diagnostics above are calculated using the
entire data set.

41

The Automatic Model Fitting Results window provides few options. Automatic model fitting is also
available in the Develop Models window. When accessed through the Develop Models window, many
more options are available.
Even though you specified RMSE, values for all of the selection criterion are displayed. The Log Winters
MethodAdditive model exhibited the smallest RMSE of the 20 models tested. If you look in the SAS
log window, you will see several green warning messages and several red error messages. These messages
appear because some of the models were not successfully fit to the data. It is possible that if you resolved
some of these fitting failures that a better model could be found. You cannot resolve model fitting
problems with automatic forecasting. This is not a serious restriction because resolving model fitting
problems rarely results in a better model. You can attempt to overcome model fitting failures in the
Develop Models window.
1-34 Chapter 1 Business Forecasting

The Model Viewer for Forecasts


Forecasts are indicated by + and are connected.
Actual values are indicated by *.

42

If you click on the Graph button in the Automatic Model Fitting Results window, the model viewer will
appear with the forecast plot visible.

The Statistics of Fit Window in the


Model Viewer

43

If you click on the Stats button in the Automatic Model Fitting Results window, the model viewer will
appear with the statistics of fit table visible. The table can also be accessed at any time the Model Viewer
window is active by clicking on the third button from the bottom on the right side.
1.1 Introduction to Business Forecasting 1-35

Future Forecasts and 95% Prediction Intervals


in the Model Viewer

44

If you click on the second button from the bottom on the right, you get a plot of forecasts going into the
future along with 95% prediction intervals. The other buttons are discussed later.

Using SAS Enterprise Guide for Forecasting


Start Programs SAS Enterprise Guide

45

SAS Enterprise Guide is invoked as a separate application. It cannot be accessed from the SAS
windowing environment.
1-36 Chapter 1 Business Forecasting

Business Forecasting for Retail Operations


Company
Top-down Warehouse
Store

Company
Middle-out Warehouse
Store

Company
Bottom-up Warehouse
Store
46

Rolling up forecasts to an aggregate level or distributing forecasts over multiple sub-categories challenges
most forecasting applications. SAS Enterprise Guide contains tasks that facilitate forecast summarization,
but often the SAS language is required to perform tasks related to the three scenarios shown above. The
specifics of the steps depend on the business needs of the users and their data. Consequently, this topic is
not addressed in the class.
1.1 Introduction to Business Forecasting 1-37

Consumer Electronics Retail Sales Data

47

The consumer electronics data that is distributed with the course contains a selection of SKU fields and
variables that group the SKU data by department and by distribution center. The data illustrates the
difficulty in reconciling forecasts by SKU, department, and distribution center.
In this class you assume that the appropriate aggregate level has been determined. This class focuses on
obtaining the best forecast for the chosen aggregate level.
Other data processing is necessary to prepare time-stamped transaction data for forecasting in SAS,
regardless of which environment the user chooses. These tasks include
converting time-stamped transaction data to a time series
transposing a file so that the time ID is the rows and the series are the columns
augmenting the time series files with vent data.
Examples of how to perform the preprocessing of the data are given in self-study appendixes using both
SAS Enterprise Guide and SAS code
1-38 Chapter 1 Business Forecasting

Business Forecasting in Finance


Mortgage prepayments
Interest rates
Trading systems
Call centers
MarketingAdvertising and promotions

48

Realistically, mortgage bankers do not expect to get good forecasts of interest rates. Instead, they perform
analyses under different simulations to estimate the impact of different rates. Forecasting mortgage
prepayments remains a very challenging activity, and methodologies outside time series analysis are often
employed. On the other hand, marketing relies on accurate forecasts to target promotions and advertising.
In addition, staffing for call centers requires accurate forecasts.
1.1 Introduction to Business Forecasting 1-39

Business Forecasting in the Energy Industry


Peak demand and load forecasting
Causal modeling for demand
Weather
Energy efficient appliance sales
Price
Energy market forecasting
Spot prices
What Enron failed at

49

The energy industry has long relied on accurate forecasts for peak demand and for average demand.
Relatively new areas, like forecasting spot prices in real time on a short time scale, have taxed forecasting
methodologies. Enrons failure to develop adequate forecasts for market prices that could be exploited for
gain led to its downfall.
1-40 Chapter 1 Business Forecasting

Business Forecasting in Telecommunications


MarketingAdvertising and promotions
Churn
Churn rates
Individual churn: binary response modeling
(predictive modeling rather than forecasting)

50

Marketing in all industries relies on accurate forecasts. Forecasting market conditions and market growth
can be challenging. Forecasting churn rates is important to help manage churn (customer turnover).
However, predicting whether and individual will churn is a binary response problem and requires
methodologies like logistic regression which accommodates binary targets. The time series forecasting
methods used in this course require that the target variable is a continuous numeric variable.
Whatever industry you represent, the techniques covered in this course will be valuable for generating
accurate forecasts to support your enterprise.
1.2 Introduction to Time Series Forecasting 1-41

1.2 Introduction to Time Series Forecasting

Objectives
Discuss time series forecasting.
List the three elements of a time series.
Provide examples of forecasting solutions.

52

Statistical forecasting is a primary goal of statistical time series analysis. You saw that a number of time
series forecasting concepts can be illustrated using the airline passengers data that is supplied by the
United States Department of Transportation, Bureau of Transportation Statistics. Recall that the data is for
domestic flights in the United States.
1-42 Chapter 1 Business Forecasting

Airline Passengers 19902004

53

To validate data preparation and to formulate forecast models for a time series, a time plot of the data is
produced. You can readily see striking features of the above data, but examination of these features will
be postponed until a few key concepts are introduced. Consider the above data restricted to years 1994
through 1997.

Airline Passengers 19941997

54

The graph illustrates that the airline passengers' data is a statistical time series.
1.2 Introduction to Time Series Forecasting 1-43

Statistical Time Series


A statistical time series is
an indexed set of numbers.

Many business time series


are equally spaced.

A time series is equally


spaced if any two
consecutive indices have Interval=1
the same interval time
difference.

continued...

55

The techniques presented in this course require that the time series be equally spaced. If a series is not
equally spaced, it is easy to aggregate or interpolate to make it equally spaced.
Self-study appendices include demonstration of processing data for time series using either SAS
Enterprise Guide or SAS code.
1-44 Chapter 1 Business Forecasting

Statistical Time Series


A statistical time series is
an indexed set of numbers.

Many business time series


are equally spaced.

A time series is equally


spaced if any two
consecutive indices have Interval=1 month
the same interval time
difference.

56

Many software products accommodate missing values, but they do not accommodate unequally spaced
time series. In many situations, an unequally spaced time series can be transformed to an equally spaced
time series with missing values. SAS procedures perform this action as well as other useful tasks.

Equally Spaced Time Series

Equally spaced time series

Equally spaced time series


with missing values

Unequally spaced time series

57
1.2 Introduction to Time Series Forecasting 1-45

After you establish that the airline passengers time series is equally spaced, you can begin the analysis.
Any analysis of time series data requires you to identify three components: trend, seasonal, and error (also
known as irregular).

Airline Passengers 19941997: Trend?

58

For the monthly data from January 1994 to December 1997, there is a clear and compelling positive linear trend.

Airline Passengers 19941997: Seasonal?

August

February

59
1-46 Chapter 1 Business Forecasting

For the same time range, August months tend to exhibit the most passengers, and February tends to
exhibit the fewest. Adjusting for trend, values that are 12 months apart are more alike than values
differing by any other number of months. The data exhibits strong seasonal behavior with a seasonal
period of 12 months.

Time Series Trend


Trend usually refers to a deterministic function of time.
Time series can be made of deterministic and
stochastic components.
A stochastic component is subject to random variation
and can never be predicted perfectly except for
chance occurrences.
A deterministic component exhibits no random
variation and can be predicted perfectly. Common
deterministic trend functions include linear trend,
curvilinear trend, logarithmic trend, and exponential
trend.

60

 When some references and software products describe trend, careful reading shows that attention
is actually restricted to linear trend. You should understand that trend can take many forms other
than a straight line.

 A random walk with drift provides an example of a stochastic trend model. A random walk with
drift requires that the current time series value only depends on the previous time series value
plus a constant.
1.2 Introduction to Time Series Forecasting 1-47

Linear and Curvilinear Trend Functions


Linear Trend

Yt = 0 + 1t Y

Quadratic Trend

Yt = 0 + 1t + 2t 2
Y

61

Polynomials in time beyond second degree polynomials are rarely appropriate for forecasting. High
degree polynomials usually interpolate and extrapolate time series very poorly.

Notation

Yt = 0 + 1t
Time index Time index
Parameters
Time series

Alternate Notation

Yt =Y(t)
62
1-48 Chapter 1 Business Forecasting

Subscripts denote time indexes. You can find that, for description and explanation, a particular time-series
value might be described as follows:

YJUN94

Almost all mathematical calculations use a numbered integer index starting with zero or one.
Consequently, SAS date, time, and datetime values are seldom used directly in forecast calculations,
although time ID variables should use date, time, or datetime values when it is possible.

Stochastic Trend Functions: Differencing


Random Walk

Yt = Yt 1 + Et
Random Walk with Drift

Yt = + Yt 1 + Et

continued...

63
1.2 Introduction to Time Series Forecasting 1-49

Stochastic Trend Functions: Differencing


Random Walk

Yt Yt 1 = Et
Yt = Yt Yt 1 First Difference

64

A model with stochastic trend of degree k can be defined by taking k differences. In practice, k=1 is most
common. Very seldom is a k greater than 2 needed in business applications.

k Yt = SEASONALt + IRREGULARt
2Yt = Yt = (Yt Yt 1 ) = (Yt Yt 1 ) (Yt 1 Yt 2 )
k Yt
k-th difference

Given the many forms of deterministic and stochastic trend components, the forecaster must decide which
trend component best describes the target data. Because the airline data appears to exhibit linear trend,
two choices seem obvious: deterministic linear trend or stochastic first differences.
1-50 Chapter 1 Business Forecasting

Seasonality
The seasonal component of a time series represents the
effects of seasonal variation.
The foundation of seasonal variation is one or more of
the cycles produced by the motion of the celestial
bodies in the solar system, dominated by the earth
circling the sun every year. Another influential activity
is the moon circling the earth approximately every 28
days.
The most general meaning of seasonality is a
component that describes repetitive behavior at known
seasonal periods. If the seasonal period is integer S,
then seasonal factors are factors that repeat every S
units of time.

65

For example, data recorded every month often exhibits a seasonal period of twelve months because there
are twelve months in one year. Also, values twelve months apart often are more alike than, for example,
values five months apart.
You might observe a cultural or social phenomenon, such as the Christmas holiday, that causes seasonal
variation. In almost all cases, the phenomenon is tied to a solar or lunar calendar. Therefore, it is directly
connected to the motion of the earth around the sun or the moon around the earth, or both. One of the
more unusual calendar events is the Easter holiday. Easter is celebrated on the first Sunday after the first
full moon after the vernal equinox. Thus, Easter is governed by three factors: the solar calendar, the lunar
calendar, and the arbitrary practice of defining a seven-day week.
1.2 Introduction to Time Series Forecasting 1-51

Common Seasonal Components


Trigonometric functions (sine waves)
Seasonal dummy variables
Seasonal differences (Box-Jenkins modeling)

66

If the seasonal behavior of a time series resembles a sine wave, then trigonometric functions can be
employed to model seasonality. If the repetitive behavior follows no obvious mathematical functional
form, then seasonal dummy variables can be employed. The popular Box-Jenkins forecasting
methodology (Box and Jenkins 19761) proposes the use of differencing operators to model trend and
seasonality. Differencing produces a stochastic seasonal component.

1
References are given in the Chapter Summary section of each chapter.
1-52 Chapter 1 Business Forecasting

Dummy Variables
A dummy variable is an indicator variable.
To indicate a specific time point, a dummy variable
takes the value one for that time point.
At all other time points, it takes the value zero.

1 when t = Sep 2001


It =
0 otherwise

67

Inexperienced forecasters often overuse dummy variables, especially seasonal dummy variables.

Seasonal Dummy Variables


For a time series with S seasons, there will be S
dummy variables, one for each season.
If the model has a constant term, only S-1 dummy
variables are required.

continued...

68
1.2 Introduction to Time Series Forecasting 1-53

Seasonal Dummy Variables


Monthly Data: IJAN , IFEB ,, IDEC

Daily Data: ISUN , IMON ,, ISAT

Quarterly Data: IQ1 , IQ2 , IQ3 , IQ4

continued...

69

Seasonal Dummy Variables


Model with No Constant Term
I JAN = JAN , I FEB = FEB,....
Yt = JAN JAN + FEB FEB + L + DEC DEC
M = effect of month M
Model with Constant Term

Yt = CONSTANT + JAN JAN + L NOV NOV


CONSTANT + JAN = effect of JAN
M
CONSTANT + NOV = effect of NOV
CONSTANT = effect of DEC
70
1-54 Chapter 1 Business Forecasting

Stochastic Seasonal Functions:


Seasonal Differencing
For seasonal data with period S, express the current
value as a function that includes the value S time units
in the past.
Yt=Yt-S+TRENDt+IRREGULARt.
SYt=Yt Yt-S , called a difference of order S.

Examples:
Monthly: This January is a function of last January and
so on.
Daily: This Sunday is a function of last Sunday and so
on.

71

Two challenges occur for the model builder. First, you must determine whether the time series has
seasonal components. Second, you must determine the best way to model the seasonal components if they
exist. Data can have seasonal components at different periods. For example, there might be repeated
behavior every three months due to financial reporting requirements, and there also might be repeated
behavior every twelve months because of cultural and weather influences.
1.2 Introduction to Time Series Forecasting 1-55

The Universal Time Series Model


g (Yt ) = f (Tt , St , Et )

TREND ERROR (Irregular)


SEASONAL
TRANSFORMATION

72

The universal model represents an abstraction that includes most forecasting models. In the generic
universal model, the function g is a transformation function. Common transformations are log
transformations and Box-Cox transformations. The function f relates the original transformed series to the
three components: trend, seasonal, and irregular. The irregular component is also known as the error
component. Following are some common special cases of the universal model.
1-56 Chapter 1 Business Forecasting

The Additive Decomposition Model

Yt = Tt + S t + E t
TREND ERROR
SEASONAL

73

Although no transformation is indicated, the response Yt could be the transformed version of the original
response. The f function from the universal model is simply an additive function that sums the three
model components. The model components themselves can be functions of time as shown earlier.

The Multiplicative Decomposition Model

Yt = Tt S t Et
TREND ERROR
SEASONAL

74

In the multiplicative model, the f function is a simple mathematical product function.


1.2 Introduction to Time Series Forecasting 1-57

A Mixed Decomposition Model

Yt = Tt S t + Et
TREND ERROR
SEASONAL

75

These models are very general because the trend and seasonal terms can be deterministic or stochastic or
mixtures of both. The error term is almost always stochastic.

In the following chapters, different special cases of these general models will be described and fit using
the TSFS.
1-58 Chapter 1 Business Forecasting

The Irregular Component


The irregular component of a time series is what
remains when trend and seasonal effects are
removed.
The irregular component need not represent a random
sequence of uncorrelated values. However, most
models specify that the irregular component must be
stationary.
A stationary time series has a constant mean and
variance at all time points.

76

 While the error and irregular component are treated synonymously above, the usual formulation
is IRREGULAR=STATIONARY MODEL+ERROR, where error terms are identically distributed
and uncorrelated.
A stationary time series cannot have any trend or seasonal components. For example, a time series with
positive linear trend has a mean that increases with time, so it cannot be stationary.

 The definition of stationary time series employed in this course is actually the usual definition of
a weakly stationary, covariance stationary, or second order stationary time series as defined in
books on the theory of statistical time series.
A common explanation is that the irregular component represents the influence of all unobserved factors
that cannot be explained by trend or seasonal terms.

 A common decomposition mentioned in many business statistics textbooks includes a fourth


component named the cyclical component. Cyclical variation is identical to seasonal variation
except for two distinctions. First, the period of cyclical data cannot be conjectured in advance
without looking at the data. Second, the period of cyclical data need not be an integer. A cyclical
component is rare. A common example is the approximate 11-year cycle of sunspot activity. This
11-year cycle is not seasonal because no current physical theory exists to conjecture that solar
flares should follow such periodic behavior. Data analysis reveals the 11-year cycle. Furthermore,
the cycle has not been constant throughout the recorded history of sunspots. In the future,
scientists might determine some aspect of solar rotation or composition that explains the cycle, in
which case the factor would become a seasonal effect. Cyclical components are more common in
nature, for example, Cyclical fluctuations of commercial fish stocks are believed to have a
period of over two decades. (Klyashtorin 2001)
1.2 Introduction to Time Series Forecasting 1-59

Detrending the Airline Data


Two strategies are tried:
Linear trend

First differences

77

To illustrate diagnosing and modeling trend, consider the monthly airline passengers data from 1994 to
1997. You can try to determine whether a deterministic linear trend works better than a stochastic trend
based on first differences.

Detrending Using Deterministic Linear Trend

78

Linear trend is modeled using a least squares trend line fit to the data. The TSFS accommodates a simple
linear trend model.
1-60 Chapter 1 Business Forecasting

Detrending Using First Differences

79

First differences can be obtained using the DIF function in a SAS DATA step. The TSFS has options for
taking differences.
Both detrending operations remove (at least visually) the trend in the data and both preserve the
seasonality in the data. At this point, you cannot determine which strategy is best
.

Modeling Seasonality in the Airline Data


Two strategies are tried:
Seasonal dummies

Differences of order 12

80
1.2 Introduction to Time Series Forecasting 1-61

SAS programming statements were used to customize the analysis for the displays, but the TSFS supports
seasonal dummies and seasonal differencing.

Removing Seasonality Using Dummy Variables

81

Seasonal dummy coefficients can be obtained using a regression procedure. The TSFS has a seasonal
dummies option. While trend is preserved after removing the effect of seasonality with seasonal dummies,
unusual shifts occur in December 1995 and November 1996.
1-62 Chapter 1 Business Forecasting

Removing Seasonality Using Differences of


Order 12

82

Seasonal differences can be calculated using the DIF12 function in a SAS DATA step. The TSFS has a
seasonal differencing option. Seasonal differencing seems to have removed trend as well. You might even
see a slight downward trend in the above plot. Similar to seasonal dummies, seasonal differences seem to
uncover unusual shifts in January 1996 and October 1996, but this time the shifts are in a downward
direction. Another shift in January 1997 seems apparent. You can also see that differences of order 12
result in the loss of the first 12 data points.
These preliminary results are not very useful. You still do not have a favored strategy for the airline
passengers data. However, the results illustrate the nature of the various trend and seasonal components,
and either deterministic or stochastic approaches point to the existence of trend and seasonality in the
data.
The combination of linear trend and seasonal dummies produces a forecast model. This is similar to the
typical additive decomposition model presented in textbooks on business statistics. You can implement an
additive decomposition model in a spreadsheet application such as Microsoft Excel.
1.2 Introduction to Time Series Forecasting 1-63

Additive Decomposition of the


Airline Passengers Data
1
Fit a line to the
Enter data into
2 data using
a spreadsheet.
LINEST.

3 Calculate the trend


for each time point.

83

Additive Decomposition of the


Airline Passengers Data
4 Form the
residuals by
subtracting
trend from the
original data.

5 Average the
residuals by
month.

Forecast=
6 Trend+Seasonal
84
1-64 Chapter 1 Business Forecasting

In step 3, the intercept from the least squares fit produced by LINEST is stored in cell K7 and has the
value 46,017,066.76 (rounded to two decimal places). The slope is stored in cell J7 and has the value
214,478.9104. Recall that in practice, you need to withhold some of the data from model fitting to
produce an honest assessment of the model. If you hold all of the data from 1997, you get the following
trend equation:

Tt = 45634942.6 + 243126.9078t

where t is the time index stored in column A.


The calculation of the seasonal component is a simple averaging of like months. Again, you ignore the
last 12 months. The calculation in Microsoft Excel is as follows:
F2=AVERAGE(E2,E14,E26)
The calculation represents the average of all three Januaries in the data used for model fitting. These
averages are calculated for the residuals after trend is subtracted. Thus, column D contains the trend
component values for Tt , and column F contains the seasonal values for S t . The forecast equation is
Yt = Tt + S t .

The hat notation is used to signify that the value is a forecast value and not an actual value from the data.
Notice that no irregular component was used. You will discover by the end of the course that modeling
the irregular component well is often critically important for obtaining accurate forecasts.
Microsoft Excel can produce a plot of the forecasts overlaid with the original observations.

Forecast Plot
Airline Passengers 1994-1997

65000000

60000000

55000000
Passengers

50000000

45000000

40000000

35000000

30000000
19 SEP

19 SEP

19 SEP

19 SEP
19 UL

19 UL

19 UL
19 AR

19 AR

19 AR

19 AR
19 OV

19 OV

19 OV

V
19 AN

19 AN

19 AN

19 JAN
19 Y

19 Y

19 Y

19 Y
JU

NO
A

A
J

J
M
M

M
J

J
N

N
M

M
94

95

96

97
94

95

96

97
94

95

96

97
94

95

96

96

97
94

95

97
94

95

96

97
19
19

Month

Passengers Forecast

85
1.2 Introduction to Time Series Forecasting 1-65

The forecasts seem reasonable. In addition, you can use Excel functions to calculate several accuracy
statistics.

Accuracy Statistics for the Additive


Decomposition Model
MAPE: 2.1205
MSE: 785,659,606,397.14
RMSE: 886,374.42

86

Mean absolute percent error (MAPE) and root mean square error (RMSE) are two popular accuracy
statistics that were defined in the previous section. These and other accuracy measures will be formulated
and discussed in the next section.

 Often, forecast professionals scale data values so that numbers are not too large to be easily
interpreted. For example, airline passenger numbers are often represented in thousands of
passengers because the totals are in the millions. MAPE is not affected by scaling, but RMSE is
affected. While RMSE seems very large for this case, MAPE shows that many cases have a
percent error less than 2%.
One of the final activities in constructing a forecast model is to perform a complete residual analysis.
1-66 Chapter 1 Business Forecasting

Analysis of Residuals (Forecast Error)


Residuals for Additive Decomposition Model

3000000

2000000

1000000

0
1 4 7 10 13 16 19 22 25 28 31 34 37 40 43 46
-1000000

-2000000

-3000000
Time Index

87

A residual analysis includes plotting the residuals as a function of time. Residuals are only forecast errors
defined to be an observed value minus the predicted value. A good model produces residuals that
resemble white noise. A white-noise time series has a mean of zero, a constant variance, and uncorrelated
values obeying a normal bell-shaped distribution. The above residual series does not look as though the
values are uncorrelated. In particular, the last nine residuals are all less than zero.
Because this is not a course on forecasting using Microsoft Excel, you might be curious about why the
first example uses Excel. User surveys show that Excel is one of the most popular software products for
forecasting. While some view Excel as a point-and-click application, the first example shows that using
Excel for forecasting is more similar to a cut-and-paste approach. Excel does not include functions to
support most popular forecasting techniques. Because of model limitations and limitations on the number
of records that can be processed by Excel, it is not suited for the business forecasting problems addressed
in this course.
Consider using the TSFS as an alternative to the cut-and-paste approach of Microsoft Excel.
1.2 Introduction to Time Series Forecasting 1-67

Forecasting the Airline Passengers Data


Using the TSFS

Forecast Model Selected: Winters Method Additive

88

 The actual model selected used a log transformation. The TSFS allows you to customize how
automatic forecasting is performed. For this example, models with a log transformation were
excluded.
1-68 Chapter 1 Business Forecasting

Accuracy Statistics for the Winters Model


MAPE: 1.2646
MSE: 91,736,551,577.07
RMSE: 302,880.42

89

The accuracy statistics are based on forecasts that only use information through 1996. The TSFS bases
accuracy statistics on one-step ahead forecasts, meaning data up through the previous month are used to
forecast the current month. Furthermore, you must use the Develop Models window to specify a holdout
sample. Consequently, the automatic modeling results displayed for the TSFS use all data from 1994 to
1996 to fit the model and then apply the forecast equation to this data to forecast 1997.
The above statistics are significantly better than those produced by the additive decomposition model that
was derived using Microsoft Excel. The residuals for the additive Winters model are given in the plot that
follows.
1.2 Introduction to Time Series Forecasting 1-69

Analysis of Residuals (Forecast Error)

90

The variable AirPass is the variable Passengers with the last 12 months set to missing. This permits
calculation of multi-step ahead forecasts. Although the last few residuals are relatively large, the above
plot looks substantially better than the plot of residuals for the additive decomposition model. The
additive Winters model can be viewed as an enhancement to the additive decomposition model that makes
better use of the data for constructing a forecast equation.
You can see that the TSFS was designed to minimize the effort of the forecaster. All that is required is the
specification of a time series variable, a date variable, and various options related to producing forecasts.
Forecasts, summary statistics, and plots are produced automatically.

 Plots produced using ODS graphics are experimental in SAS 9.1. Many of the plots used in these
course notes are produced by the TIMESERIES procedure, a procedure in SAS/ETS software that
uses the programming features of the SAS System.
The TSFS is general enough to mimic the type of modeling you might perform in Microsoft Excel. For
example, the TSFS features many model components, including linear trend and seasonal dummies.
These features will be illustrated and explained in later chapters.
1-70 Chapter 1 Business Forecasting

Summary
The time series forecasting methods addressed in this
course require the data to be equally spaced.
Time series that are not equally spaced may be
converted to equally spaced data by aggregating to a
lower frequency or by adding missing values.
Any time series can be represented as the combined
effect of one or more of the following four components:
cyclical, seasonal, trend, stationary (irregular, error).
A primary challenge for the forecaster is the
determination of how to represent the four
components in a forecast model.
Another challenge is how to best measure forecast
accuracy.

91

Much of this course will add complexity to forecast modeling because the number of ways to model
seasonality, trend, and stationarity will increase, making it increasingly difficult to propose adequate
models without some forecasting experience. Guidelines and rules-of-thumb will be provided, but in
many cases, a novice forecaster must resort to trial and error.
1.3 Measuring Forecast Accuracy 1-71

1.3 Measuring Forecast Accuracy

Objectives
Introduce and summarize all accuracy measures
supported by the Time Series Forecasting System.
Provide intuition whenever possible to support an
accuracy measure.

93

Forecasting
If someone asks you if you can forecast something, your
answer should always be Yes.

If someone asks you if you can forecast something


accurately, you will not be able to answer until you have
established what accuracy means and until you have
performed preliminary modeling of the data.

94
1-72 Chapter 1 Business Forecasting

Liability
Will you stake your reputation on the accuracy of these
forecasts?

No, but I will stake my reputation on the methodology


that was used to generate the forecasts.

You may have no control over data accuracy and


validity.
You have no control over future events, such as
catastrophes, economic downturns, war, the integrity
of key players, the survival of key players, and so on.

95

Model Diagnostic Statistics


Notation for Basic Quantities

Series Length: n

Number of Model Parameters to Estimate: k

Model Likelihood Function Evaluated at Maximum: L

Sum of Squared Errors: SSE

Predicted Target Value Yt at Time t: Yt


continued...

96
1.3 Measuring Forecast Accuracy 1-73

Model Diagnostic Statistics


n n
R-Square: R = 1 (Yt Yt ) 2
2
(Y Y )
t t
2

t =1 t =1

Root Mean Squared Error:

1 n
MSE =
n k t =1
(Yt Yt ) 2
*

RMSE = MSE

*The TSFS uses divisor n rather than n-k.


continued...

97

R-Square compares the sum of squared errors (SSE) of the forecast model to the SSE for the forecast
model that forecasts every future value as the mean of the historic data. Consequently, if a model
produces forecasts worse than the mean, then R-Square will be negative. This seems to contradict R-
Square being a squared quantity that must be positive. Some practitioners prefer to define R-Square so
that it can never be negative.

Model Diagnostic Statistics


Mean Absolute Percent Error:

1 n
MAPE = | Yt Yt | / Yt
n t =1

Mean Absolute Error:

1 n
MAE = | Yt Yt |
n t =1

continued...

98
1-74 Chapter 1 Business Forecasting

MAPE is probably the most popular forecast accuracy measure in the business world.

Model Diagnostic Statistics


Likelihood Based Information Criteria

General Formula:

IC = Accuracy + Penalty

Akaikes A Information Criteria:


AIC = 2 log( L) + 2k

Schwarzs Bayesian Information Criteria:

SBC = 2 log( L) + k log(n)


continued...

99

AIC will permit more parameters than SBC when 2k is smaller than klog(n). This occurs for all series
with more than seven observations. Schwarz showed that AIC is based toward over-parameterization.

Model Diagnostic Statistics


Error Based Information Criteria

Akaikes A Information Criteria:

AIC = n log(SSE / n) + 2k

Schwarzs Bayesian Information Criteria:

SBC = n log(SSE / n) + k log(n)

continued...

100
1.3 Measuring Forecast Accuracy 1-75

The likelihood form of AIC and SBC require that models be hierarchically consistent before they can be
compared. The error based form of AIC and SBC allow comparison of any two models.

Model Diagnostic Statistics


Variations on R-Square

Adjusted R-Square:

(n 1)(1 R 2 )
ADJRSQ = 1
nk
Random Walk R-Square:

RWRSQ = 1
(Y Y ) 2

(Y Y ) RW
2

continued...

101

The variations of R-Square tend to produce smaller values than the original formula for R-Square. The
random walk R-Square simply compares a forecast model to the random walk forecast model.
1-76 Chapter 1 Business Forecasting

Model Diagnostic Statistics


Econometric Accuracy Statistics

Amemiyas Adjusted R-Square:

(n + k )(1 R 2 )
AADJRSQ = 1
nk
Amemiyas Prediction Criterion:

(n + k ) SSE
APC =
n( n k )

102

Amemiyas criterion are primarily used in the analysis of economic time series.
The choice of accuracy statistic for model selection may be a critical step in a given forecasting project
.
1.4 Descriptive and Exploratory Analysis of Time Series Data 1-77

1.4 Descriptive and Exploratory Analysis of Time Series


Data

Objectives
Use TSFS to produce time series plots.
Identify seasonality and trend from time series plots.
Introduce the sample autocorrelation, partial
autocorrelation, and inverse autocorrelation functions
as time series diagnostic tools.
Show how trend and seasonality are reflected in
autocorrelation plots.
Introduce the Ljung-Box test for white noise.
Introduce the Dickey-Fuller test for stationarity.
Provide examples of diagnosing trend and
seasonality.

104

Interactive Plots in the TSFS


Original series
Differenced series
Log transformed series
Diagnostic plots

105
1-78 Chapter 1 Business Forecasting

The key features that any time series may exhibit, trend and seasonality, have been presented. Now, learn
the functionality available in the TSFS that can be sued to diagnose the presence of these key features.
The functionality includes interactive graphs as well as special statistical tests specifically designed to
detect trend and seasonality in time series.

Accessing the Time Series Viewer Main


Menu

Open Time Series Viewer

106

Accessing the Time Series Viewer Develop


Models Window
Open Time Series Viewer

107
1.4 Descriptive and Exploratory Analysis of Time Series Data 1-79

Viewing the Time Series Plot

This plot indicates the presence of trend and seasonality.


108

Time Series Viewer Tool Bar

Go Back (Close)
Toggle Seasonal Difference
Toggle First Difference
Toggle Log Transform
Link/Unlink
Zoom Out (Restore)
Zoom In

109
1-80 Chapter 1 Business Forecasting

Time Series Viewer Horizontal Tool Bar

Time Series

Autocorrelations

Tests

Data Table

110

Zooming

continued...

111
1.4 Descriptive and Exploratory Analysis of Time Series Data 1-81

Zooming

112

Unlinking for Multiple Views

113
1-82 Chapter 1 Business Forecasting

Log Transformed Series

114 Evidence for a log transformation is weak.

Series After Applying First Differences

115
First differencing provides evidence of trend.
1.4 Descriptive and Exploratory Analysis of Time Series Data 1-83

Series After Applying Seasonal Differences

Differencing of order 12 is difficult to interpret


116
seasonality is confounded with trend.

Series After First and Seasonal Difference

Differencing of orders 1 and 12 resolves


117
confounding evidence of trend and seasonality.
1-84 Chapter 1 Business Forecasting

Series with First and Seasonal Differences of


Log Transformation

118 Evidence for a log transformation is still weak.

Autocorrelation Plots

119
1.4 Descriptive and Exploratory Analysis of Time Series Data 1-85

Autocorrelation Plots of Series After Seasonal


Differencing

120

The Autocorrelation Function


The autocorrelation function at lag k, ACF(k),
represents the correlation of a time series with itself
lagged by k time units.
The autocorrelation function is one of the primary tools
for diagnosing trend, seasonality, and candidate
forecast models.
A portfolio of autocorrelation function shapes may be
used to determine an approximating time series
model.

121

Autocovaraince function at lag k is given by the following equation.

k = E[(Yt )(Yt k )] = E(YtYt k ) 2


1-86 Chapter 1 Business Forecasting


The autocorrelation function at lag k is given by k = k

The sample autocorrelation function, calculated by replacing the parameters in the above equations with
estimates from the data as shown below.
nk

(y t y )( yt + k y )
rk = t =1
n
.
(y
t =1
t y) 2

The Partial Autocorrelation Function


The partial autocorrelation function at lag k, PACF(k),
represents the correlation of a time series with itself at
lag k adjusted for lags 1 through k-1.
PACF(k) is the coefficient of the k-th order
autoregressive term in an autoregressive order-k
model.
PACF(k) is calculated using a fast recursion equation.
A portfolio of partial autocorrelation function shapes
may be used to determine an approximating time
series model.

122
1.4 Descriptive and Exploratory Analysis of Time Series Data 1-87

The Inverse Autocorrelation Function


The inverse autocorrelation function at lag k, IACF(k),
is the autocorrelation function of the inverse model.
The IACF has the same interpretation as the PACF for
diagnosing time series features.
The IACF does not have an exact formula, so it can be
different for different software or different settings.
A portfolio of inverse autocorrelation function shapes
may be used to determine an approximating time
series model.

123

White Noise and Stationarity Tests

124
1-88 Chapter 1 Business Forecasting

The Ljung-Box Chi-Square Test for White Noise


A white noise time series is a Gaussian (normal,
bell-shaped) time series with mean zero and
positive fixed variance in which all observations are
independent of each other.
The Ljung-Box test may be applied to the original
series or to the residuals after fitting a model.
The null hypothesis is that the series is white noise,
and the alternative hypothesis is that one or more
autocorrelations up to lag m are not zero.

m
rk2
= n ( n + 2)
2
m , rk = ACF(k ) given = 0.
k =1 n k

125

The Dickey-Fuller Unit Root Test


The null hypothesis is that the time series is not
stationary.
The alternative hypothesis is that the time series is
stationary.
A significant value rejects the null hypothesis and
provides evidence that the time series is stationary.
The name unit root reflects the fact that a time series
with a certain characteristic polynomial having a unit
root is not stationary. The mathematical details are
beyond the scope of this course.
Test statistics are available for lags 0 through at most
5. These reflect six different approximating models.
The six tests are not independent, but they may yield
conflicting results.
126
1.4 Descriptive and Exploratory Analysis of Time Series Data 1-89

Data Table

127

Data Table After Seasonal Differences

128
1-90 Chapter 1 Business Forecasting

Interacting with the Series Plot

Click on a point.
Date and series value are displayed.

129

Interacting with Autocorrelation Plots

Click on a bar.
Lag and value are displayed.

130
1.4 Descriptive and Exploratory Analysis of Time Series Data 1-91

Interacting with White Noise Tests

Click on a bar.

A recommendation is displayed.
Lag and p-value are displayed.
131

Interacting with Stationarity Tests

Lag and p-value are displayed.


Click on a bar.

A recommendation is displayed.
132
1-92 Chapter 1 Business Forecasting

Diagnosing Trend
A time series having a trend component (deterministic or
stochastic) usually exhibits the following:
a time series plot that is trending up, down, or in a
deterministic fashion
a highly significant ACF, PACF, and IACF at lag 1
an ACF with many significant lags decaying slowly
from lag 1
an ACF with few significant values after first
differencing is applied
unit root tests that are not significant but become
significant when a first difference is applied

133

Diagnosing Seasonality
A time series with a seasonal component having period S
usually exhibits the following:
a time series plot that has repetitive behavior every S
time units
significant ACF, PACF, and IACF values at lag S
an ACF with significant values at lags that are
multiples of S
an ACF without a significant value at lag S after a
difference of order S has been applied
seasonal unit root tests that are not significant but
become significant when a difference of order S is
applied

134
1.4 Descriptive and Exploratory Analysis of Time Series Data 1-93

Sinusoidal Time Series


A time series with a sinusoidal seasonal component
having period S usually exhibits the following:
An ACF that resembles a sinusoid with decaying
amplitude. The PACF and IACF may or may not have
significant values at lag S.
An ACF without a significant value at lag S and with
few significant lags after a difference of order S has
been applied.

135

Diagnostics for a Time Series with a


Linear Trend Component

continued...

136
1-94 Chapter 1 Business Forecasting

Diagnostics for a Time Series with a


Linear Trend Component

continued...

137
After First Differencing

Diagnostics for a Time Series with a


Linear Trend Component

continued...

138
Unit Root/Stationarity Tests
1.4 Descriptive and Exploratory Analysis of Time Series Data 1-95

Diagnostics for a Time Series with a


Linear Trend Component

139
After First Differencing

Diagnostics for a Time Series with a


Stochastic Trend Component

continued...

140 A Random Walk with Drift


1-96 Chapter 1 Business Forecasting

Diagnostics for a Time Series with a


Stochastic Trend Component

continued...

141
After First Differencing

Diagnostics for a Time Series with a


Stochastic Trend Component

continued...

142
Unit Root/Stationarity Tests
1.4 Descriptive and Exploratory Analysis of Time Series Data 1-97

Diagnostics for a Time Series with a


Stochastic Trend Component

143
After First Differencing

Diagnostics for a Seasonal Time Series

continued...

144
1-98 Chapter 1 Business Forecasting

Diagnostics for a Seasonal Time Series

continued...

145
After a Difference of Order 12

Diagnostics for a Seasonal Time Series

continued...

146
Seasonal Root Tests
1.4 Descriptive and Exploratory Analysis of Time Series Data 1-99

Diagnostics for a Seasonal Time Series

147
After a Difference of Order 12

Diagnostics for a Sinusoidal Time Series

continued...

148
1-100 Chapter 1 Business Forecasting

Diagnostics for a Sinusoidal Time Series

continued...

149
After a Difference of Order 12

Diagnostics for a Sinusoidal Time Series

continued...

150
Seasonal Root Tests
1.4 Descriptive and Exploratory Analysis of Time Series Data 1-101

Diagnostics for a Sinusoidal Time Series

151
After a Difference of Order 12
1-102 Chapter 1 Business Forecasting

1.5 Chapter Summary


There are many competing strategies and methods for forecasting. The Time Series Forecasting System
(TSFS) supports most major forecasting methodologies. SAS Enterprise Guide supports the more popular
forecasting techniques. SAS Enterprise Guide is suited for time series data preparation, whereas the TSFS
provides a better modeling environment.
Time series analysis includes proposing models and testing accuracy of the models. In general, a model
will contain one or more of the four time series components: cyclical, seasonal, trend, stationary.
Accuracy statistics will help guide the forecasting professional to a good model.

For Additional Information


Armstrong, J.S., editor. 2001. Principles of Forecasting. Boston: Kluwer Academic Publishers.
Bowerman, B.L., and R.T. OConnell. 1993. Forecasting and Time Series: An Applied Approach.
Belmont, California: Duxbury Press.
Box, G.E.P., and G.M. Jenkins. 1976. Time Series Analysis: Forecasting and Control. Oakland, California:
Holden-Day.
Klyashtorin, Leonid B. 2001. Climate Change and Long-Term Fluctuations of Commercial Catches. FAO
Fisheries Technical Paper 410.
1.6 Solutions to Exercises 1-103

1.6 Solutions to Exercises


1. There are many nave approaches to forecasting when the data is as well structured as the airline
passengers data. The only wrong answer is an obviously inconsistent value. Two approaches are
offered for a solution. (1) For the target month, take the last two known values for the same month in
previous years. Calculate the percent increase from 1996 to 1997. Multiply this percent increase by
the 1997 value. (2) Use all four previous known values for the same month, calculate an average
percent increase, and use this as the multiplier for the last known value
a. (1) January 1996 value=45,722,827; January 1997=49,228,750; Percent
increase=49,228,750/45,722,827=1.077; Forecast=1.077*49,228,750=53,003,499. (2) Average
percent increase=1.066; Forecast=1.066*49,228,750=52,490,019.
b. (1) February 1996 value=47,130,093; February 1997=47,152,265; Percent
increase=47,152,265/47,130,093=1.0005; Forecast=1.0005*47,152,265=47,174,447. (2) Average
percent increase=1.064; Forecast=1.064*47,152,265=50,176,653.
c. (1) August 1996 value=59,802,408; August 1997=61,907,945; Percent
increase=61,907,945/59,802,408=1.035; Forecast=1.035*61,907,945=64,087,614. (2) Average
percent increase=1.042; Forecast=1.042*61,907,945=64,504,980.
2. Assumptions depend on individual solutions. For the above, you assume that the percent increase
from year to year will be stable, producing a stable upward trend over time. This need not be
equivalent to linear trend, but it will be very similar.
3. Assumptions depend on individual solutions. For the above, you assume that the data are seasonal and
that information from 12 months ago is more useful than data from recent months.
1-104 Chapter 1 Business Forecasting
Chapter 2 Simple Forecast Models

2.1 Modeling Trend ...............................................................................................................2-3

2.2 Modeling Seasonality...................................................................................................2-34

2.3 Using Special Variables to Model Events...................................................................2-55

2.4 Exponential Smoothing Forecast Models ..................................................................2-75

2.5 Exponential Smoothing Models with Trend and Seasonal Components ................2-98

2.6 Chapter Summary.......................................................................................................2-109

2.7 Solutions to Exercises ............................................................................................... 2-111


2-2 Chapter 2 Simple Forecast Models
2.1 Modeling Trend 2-3

2.1 Modeling Trend

Objectives
Review types of trend components.
Introduce trend components supported by the
Time Series Forecasting System (TSFS).
Review methods for diagnosing trend.
Fit various trend models to time series data.
Forecast using trend models.

Two Types of Trend


Deterministic
A mathematical function of time
Common functions are linear, quadratic,
logarithmic, and exponential
Stochastic
Future time values depend on past values plus
error
A common stochastic trend model is a random
walk with drift

4
2-4 Chapter 2 Simple Forecast Models

Deterministic Trend Supported by the TSFS


Linear
Quadratic
Cubic
Logistic
Exponential
Hyperbolic
Power Curve
Exp(A+B/Time)

Stochastic Trend Supported by TSFS


Random walk
Random walk with drift

6
2.1 Modeling Trend 2-5

Mathematical Formulas for


Deterministic Trend
Predictor Series for Trend Denoted Xt

Linear Trend
X t = t , Trend = 0 + 1t
Quadratic Trend
X t = t 2 , Trend = 0 + 1t + 2t 2
Cubic Trend
X t = t 3 , Trend = 0 + 1t + 2t 2 + 3t 3

continued...

In the TSFS, a variable called _LINEAR_ is constructed that represents the time index starting from one,
that is, _LINEAR_=1,2,3,. A variable called _QUAD_ is constructed as the square of _LINEAR_. The
variable _CUBE_ is _LINEAR_ to the third power. A quadratic trend component uses both _LINEAR_
and _QUAD_. A cubic trend model uses _LINEAR_, _QUAD_, and _CUBE_. The parameters associated
with variables _LINEAR_, _QUAD_, and _CUBE_ are labeled Linear Trend, Quadratic Trend, and Cubic
Trend, respectively.
2-6 Chapter 2 Simple Forecast Models

Mathematical Formulas for


Deterministic Trend
Predictor Series for Trend Denoted Xt

Logistic Trend
ct
X t = log , Trend = 0 + 1 X t
1 ct
Logarithmic Trend
X t = log(t ), Trend = 0 + 1 X t
Exponential Trend
X t = t , Trend = exp( 0 + 1t )
continued...

The TSFS creates variables _LOGIT_, _LOG_, and _EXP_ to construct the above trend components.
ceil (log10 (max(t )))
The scaling factor for logistic trend is c = (1 10 6 )10 .

Mathematical Formulas for


Deterministic Trend
Predictor Series for Trend Denoted Xt

Hyperbolic Trend
X t = 1 / t , Trend = 0 + 1 X t
Power Curve Trend
X t = log(t ), Trend = exp( 0 + 1 X t )
Exp(A+B/Time) Trend
X t = 1 / t , Trend = exp( 0 + 1 X t )

The TSFS creates variables _HYP_, _POW_, and _ERT_ to construct the above trend components. In all
cases, the parameter associated with a trend component is labeled with the name of the trend component.
2.1 Modeling Trend 2-7

Trend Models for the Lead Production Data

Record Layout for Annual Lead Production Data

continued...

10

Trend Models for the Lead Production Data

Cubic Spline Smooth, SM=60 continued...

11

A cubic spline smooth can be obtained using the line plot task in SAS Enterprise Guide.
2-8 Chapter 2 Simple Forecast Models

Trend Models for the Lead Production Data

Cubic Spline Smooth, SM=70 continued...

12

Trend Models for the Lead Production Data

Linear Trend, RMSE=38,028 continued...

13
2.1 Modeling Trend 2-9

Trend Models for the Lead Production Data

Quadratic Trend, RMSE=32,518 continued...

14

Trend Models for the Lead Production Data

Cubic Trend, RMSE=31,943 continued...

15
2-10 Chapter 2 Simple Forecast Models

Trend Models for the Lead Production Data

Logistic Trend, RMSE=36,615


continued...

16

Trend Models for the Lead Production Data

Logarithmic Trend, RMSE=47,293


continued...

17
2.1 Modeling Trend 2-11

Trend Models for the Lead Production Data

Exponential Trend, RMSE=33,779


continued...

18

Trend Models for the Lead Production Data

Hyperbolic Trend, RMSE=85,982


continued...

19
2-12 Chapter 2 Simple Forecast Models

Trend Models for the Lead Production Data

Power Curve Trend, RMSE=61,450


continued...

20

Trend Models for the Lead Production Data

Exp(A+B/Time) Trend, RMSE=96,487


continued...

21
2.1 Modeling Trend 2-13

Trend Models for the Lead Production Data


Trend Type RMSE Rank Comments
Linear Trend 38,028 5 Acceptable
Quadratic Trend 32,518 2 Poor forecasts
Cubic Trend 31,943 1 Poor forecasts
Logistic Trend 36,615 4 Poor forecasts
Logarithmic Trend 47,293 6 Disqualify
Exponential Trend 33,779 3 Best forecasts
Hyperbolic Trend 85,982 8 Disqualify
Power Curve Trend 61,450 7 Disqualify
Exp(A+B/Time) Trend 96,487 9 Disqualify

continued...

22

As expected, quadratic and cubic trend models do not produce good extrapolated forecasts. The
disqualified models fail a residual analysis. Residual analysis is discussed in detail later.

Trend Models for the Lead Production Data


Quadratic and cubic models extrapolate poorly.
Forecasts bottom out and then move upward a few
years beyond the end of the series.
Quadratic and cubic trend would likely be avoided for
this data because of known extrapolation problems.
While the exponential trend model seems to be the
best for the annual primary lead production series, in
general, adding components to the model can cause
other trend components to become superior for
promoting forecast accuracy.

continued...

23
2-14 Chapter 2 Simple Forecast Models

Trend Models for the Lead Production Data

continued...

24

Trend Models for the Lead Production Data

continued...

25
2.1 Modeling Trend 2-15

Trend Models for the Lead Production Data

26
2-16 Chapter 2 Simple Forecast Models

Fitting a Simple Trend Model with the TSFS

This demonstration illustrates how to fit a simple trend model using the TSFS.
The U.S. Annual Lead Production data will be used. Bring up the Time Series Forecasting System. If you
have not already done so, create a project catalog for this course by specifying catalog FETS.TSFSPROJ
with entry LEADYEAR.

The FETS.LEADYR data set is used. Left-click the Browse button next to Data Set.
2.1 Modeling Trend 2-17

Left-click the Develop Models button, and the following window opens. Use the target variable
PRIMARY.
2-18 Chapter 2 Simple Forecast Models

The Develop Models window opens. For various reasons, primarily because of behavior near the end of
the series, no holdout sample will be employed.
2.1 Modeling Trend 2-19

You can use the automatic model fitting option to get a rough idea of the accuracy that can be expected.
Left-click in the client area of the Develop Models window and select Fit Models Automatically.
2-20 Chapter 2 Simple Forecast Models

The heuristic decision rules determine which models to consider.

Five trend only models will be tried, along with the same models applied to the logarithm of the target.
The diagnostic Maybe implies try modeling both ways, assuming Yes and then assuming No. When you
click Ok, a series of ten status windows will open. On modern computers, the computations are so rapid
that the windows only appear for a fraction of a second. Following is an example of a status window.
2.1 Modeling Trend 2-21

Of the ten models that were tried, the one exhibiting the smallest RMSE is the log linear trend model.
2-22 Chapter 2 Simple Forecast Models

Systematically work through the three best models as described in the course notes: cubic trend, quadratic
trend, and exponential trend. Left-click in the client area of the Develop Models window. Select Fit
Custom Model.
2.1 Modeling Trend 2-23

The Custom Model Specification window supports a large number of forecast models, including time
series regression models.

Click the down arrow next to Trend Model, and then select Linear Trend.
2-24 Chapter 2 Simple Forecast Models

The choice appears in the Predictors area of the Custom Model Specification window.

Click OK to fit the model.


2.1 Modeling Trend 2-25

The linear trend model seems to be inferior to the model that was selected automatically. As you might
surmise, the default model selection list contains a linear trend model, so this model was rejected by
automatic model selection because it had larger RMSE than the log linear trend model.
To specify a model with quadratic trend, proceed as before, except select Trend Curve rather than
Linear Trend.

When the trend curve choices appear, first select the quadratic trend model.
2-26 Chapter 2 Simple Forecast Models

As before, the selection will appear in the area Predictors area. Proceed to select and fit the quadratic,
cubic, and exponential trend models.
The cubic trend model

followed by the exponential trend model.

After you have selected Exponential Trend, the following informational window opens.
2.1 Modeling Trend 2-27

When you have finished, the Develop Models window displays results for all models that were
successfully fit to the data.

The TSFS automatically places a check mark by the best model in the Forecast Model column. Only one
model may be checked. The checked model is used by the Produce Forecasts window. You can also
highlight a model without checking it. When a results button is selected, such as the View Model
Predictions button, results will be displayed for the model that is highlighted, not for the model that is
checked, unless they are the same model. A review of the results and action buttons may be in order.
2-28 Chapter 2 Simple Forecast Models

Results Buttons
View Model View Parameter
Predictions Estimates

View Prediction Error View Forecast


Autocorrelations Graph

View Prediction View Forecast


Error Tests Table

View Prediction View Statistics


Errors of Fit
28

Action Buttons
Edit Sort
Close
Model Model

Refit Diagnose
Model Series

Reevaluate Next
Model Viewer

Delete Edit Model


Help
Model List
29

Pressing the Sort button places the models in order from best to worst based on the selected criteria.
2.1 Modeling Trend 2-29

You have seen that the exponential trend model is superior with respect to extrapolating future values.
Thus, you should check the exponential trend model as the forecast model. You can see that Log Linear
Trend and Exponential Trend are synonyms.
2-30 Chapter 2 Simple Forecast Models

Exit the Develop Models window and select Produce Forecasts.


2.1 Modeling Trend 2-31

Default settings produce a data set with the following attributes:


1. A column containing the time ID variable
2. A column containing the target variable
3. A column containing the variable _EXP_, which is used to calculate exponential trend

4. Twelve rows appended to the end of the original values containing the forecast values for the next 12
years
When you click Run, the forecast data set is produced, and the following window opens.

The Output button, which was formerly grayed out, is now active.

Click the Output button to view the data and forecasts.


2-32 Chapter 2 Simple Forecast Models
2.1 Modeling Trend 2-33

Exercises

1. An older lead production data set appears in many time series references. This data set contains
monthly lead production values from January 1986 through September 1992. The data is stored in the
SAS data set FETS.LEADPRD. Fit and evaluate at least two trend models for this data. The two lead
production data sets are from different sources and cannot be reconciled for some years.
2-34 Chapter 2 Simple Forecast Models

2.2 Modeling Seasonality

Objectives
Review types of seasonal components.
Introduce seasonal components supported by the
Time Series Forecasting System (TSFS).
Review methods for diagnosing seasonality.
Fit various seasonal models to time series data.
Forecast using seasonal models.
Fit models that have simple trend and seasonal
components to time series data.

32

Seasonal Components Supported by the


Time Series Forecast System
Deterministic
Seasonal dummy variables
Stochastic
Differences of order S, S=seasonal period

33
2.2 Modeling Seasonality 2-35

Trigonometric Functions
Trigonometric functions are not supported as an
option in the TSFS.
They can be accommodated by creating
trigonometric variables in the modeling data set
defined into the future for forecasting purposes.
The variables are then treated as ordinary
regressors in the TSFS.

Example : X t = sin( 2 t / S )

34

Seasonal Models for the Construction Data

Record Layout for Monthly Construction Data

continued...

35
2-36 Chapter 2 Simple Forecast Models

Seasonal Models for the Construction Data

Time Series Line Plot continued...

36

The seasonal component of the data is visually compelling. The nature of trend is more difficult to
ascertain. Linear and quadratic trend should be considered. You should also see that the variation from
low to high seems larger in later years, implying nonconstant variance over time.

Seasonal Models for the Construction Data

Cubic Spline Smooth, SM=20 continued...

37
2.2 Modeling Seasonality 2-37

Seasonal Models for the Construction Data

continued...
Cubic Spline Smooth, SM=70
38

By smoothing out the seasonal factors, you can see a general upward trend in the data.

Seasonal Models for the Construction Data

Linear Trend + Sinusoid, RMSE=2,789 continued...

39

For illustration, a model with linear trend and a sinsusoid of period 12 is fit to the data using SAS
Enterprise Guide. The above plot reveals that seasonality is not modeled well by sinusoids.
2-38 Chapter 2 Simple Forecast Models

Seasonal Models for the Construction Data

Linear Trend + Seasonal Dummies, continued...


RMSE=1,194
40

Seasonal Models for the Construction Data

First Difference and Difference of Order 12, continued...


RMSE=1,933
41

The linear trend plus seasonal dummies exhibits the smallest RMSE value. The model with a sinusoid
component is rejected for obvious lack of fit.
2.2 Modeling Seasonality 2-39

Seasonal Models for the Construction Data


Model Components RMSE Rank Comments
Linear+Sinusoid 2,789 3 Disqualify
Linear+Seasonal Dummies 1,194 1 Best
1st Dif and Dif of Order 12 1,933 2 Improve Later

continued...

42

Seasonal Models for the Construction Data


The wave-like pattern of the data is not well modeled
by sinusoids.
The presence of trend may make it more difficult to
diagnose seasonality.
Forecast models for the construction data must take
into account autocorrelated errors. For this reason,
better models will be obtained later.

continued...

43

The forecasts look plausible based on a visual inspection of the historical data.
2-40 Chapter 2 Simple Forecast Models

Seasonal Models for the Construction Data

44

Prediction confidence limits remain relatively narrow because of the strong deterministic seasonal
component.
2.2 Modeling Seasonality 2-41

Fitting a Simple Seasonal Model with the TSFS

This demonstration illustrates how to fit a simple seasonal forecast model using the TSFS.
The construction data will be used. Bring up the Time Series Forecasting System. If you have not already
done so, create a project catalog for this course by specifying catalog FETS.TSFSPROJ with entry
CONSTRUCTION. Select the FETS.CONSTRUCTION data set.

Left-click the Develop Models button, and the following window opens. Use the target variable
CONTRACTS.
2-42 Chapter 2 Simple Forecast Models

The Develop Models window opens. Because of the apparent slight downward trend near the end of the
series, no holdout sample is used.

Left-click and select Fit Models from List The following window opens.
2.2 Modeling Seasonality 2-43

Select Seasonal Dummy and click OK.

The seasonal dummy model produces RMSE=2167.1. Examine the forecast plot for the model.
2-44 Chapter 2 Simple Forecast Models

Because the model does not include a trend term, it does not capture the trending behavior of the data.
There is no need to investigate this model further. Return to the Develop Models window, and select the
Linear Trend with Seasonal Terms model from the model selection list.

Inclusion of a trend term improves RMSE to 1194.1. To show how listed models can always be
constructed from one of the model windows, left-click and select Fit Custom Model.
2.2 Modeling Seasonality 2-45

Left-click the down arrow next to Seasonal Model and select Seasonal Dummy Regressors. Left-click
the down arrow next to Trend Model and select Linear Trend. Click OK.

The Model label Seasonal Dummies + Linear Trend would have been Linear Trend + Seasonal
Dummies if you had made your selection in reverse order. Click OK.
2-46 Chapter 2 Simple Forecast Models

As you can see, this latter model is equivalent to the Linear Trend with Seasonal Terms model selected
from the model selection list. Your instructor may wish to show you additional ways to obtain the same
model.
Examine the forecast plot for the seasonal model with linear trend.

While the forecasts look more reasonable than before, there still seem to be some large residuals near the
end of the data.
2.2 Modeling Seasonality 2-47

The prediction error plot also reveals an unusually long run of negative residuals at the end of the data.
The residuals also have a parabolic shape. Quadratic trend may produce better results.
Repeat the previous step, except select Trend Curve Quadratic Trend.

Click OK.
2-48 Chapter 2 Simple Forecast Models

RMSE drops to 989.2. Examine the forecast plot.

Examine the prediction error plot.


2.2 Modeling Seasonality 2-49

While results look better, you should consider a log transformation to see if this stabilizes the variance,
which appears to be increasing in time.

The results follow.


2-50 Chapter 2 Simple Forecast Models

RMSE has fallen to 950.9.

The forecasts look reasonable.


2.2 Modeling Seasonality 2-51

The residuals seem okay except for a run of seven negative values near the end.

Autocorrelation plots reveal problems with the model. The model fails to account for autocorrelation.
2-52 Chapter 2 Simple Forecast Models

The presence of autocorrelation in the residuals leads to a rejection of the null hypothesis of white noise.
2.2 Modeling Seasonality 2-53

Even though all estimates are significantly different from zero at the 5% level, problems with
autocorrelated residuals cause you to reject this model. You learn how to correct this problem in later
chapters. Without this additional methodology, you cannot find an acceptable model for this data.
2-54 Chapter 2 Simple Forecast Models

Exercises

2. Fit a seasonal model to the variable HSTARTS in the construction data set.
2.3 Using Special Variables to Model Events 2-55

2.3 Using Special Variables to Model Events

Objectives
Discuss events in time series analysis.
Introduce the three basic variables for modeling
time series data with event effects.
Show how models are specified in the
Time Series Forecasting System (TSFS)
with event terms.
Fit models to time series data that may be impacted
by events.
Make inferences and forecasts using models with
event terms.

48

Events
An event is anything that changes the underlying
process that generates time series data.
The analysis of events includes two activities:
Exploration to identify the functional form of the
effect of the event
Inference to determine whether the event has a
statistically significant effect
Other names for the analysis of events:
Intervention analysisname used by TSFS
Interrupted time series analysis

49
2-56 Chapter 2 Simple Forecast Models

Intervention Analysis
Special case of transfer function modeling in which
the predictor variable is a deterministic categorical
variable
Derived from the concept of a public policy
intervention having an effect on a socio-economic
variable
Example: Raising the minimum wage increases
the unemployment rate
Example: Implementing a severe drunk driving
law reduces automobile fatalities

50

Event/Intervention Analysis Practices


In retail sales, the term event is often employed and
includes
Promotional eventsDiscounts, sales, featured
displays, and so forth
Advertising eventsBroadcast, Internet, and print
media advertising campaigns, sponsored events,
celebrity spokespersons, and so forth
In economics and the social sciences, the term
intervention is often employed and includes
Catastrophic events
Events related to a key player (CEO,
spokesperson)imprisonment, scandal, illness or
injury, death
Public policy changes
51
2.3 Using Special Variables to Model Events 2-57

Primary Event Variables


0 for t tevent
Point/Pulse Jt =
1 for t = tevent

0 for t < tevent


Step It =
1 for t tevent

0 for t < tevent


Ramp Rt =
t tevent for t tevent
tevent

52

These three event variables, point, step, and ramp, can be used to model most event effects. A single
event variable can be employed, or two or more variables can be combined for more complex effects.
The Arizona DWI data (FETS.AZDWI) is used to illustrate intervention concepts. The data covers the
period from January 1980 to May 1984. A law was passed in Arizona to reduce drunk-driving related
fatalities, and it became effective on 1 July 1982. To get a general idea of the traffic fatalities series, SAS
Enterprise Guide is used to produce a smoothed plot of the data.
2-58 Chapter 2 Simple Forecast Models

The Arizona DWI Data (Smoothing Weight=50)

July 1982

53

The series dips to its lowest values in the vicinity of the intervention, but after the intervention date, the
series appears to gradually return to its original level.
The Intervention Specification window is selected in the Develop Models window using Fit Custom
Model Add Interventions. After one or more interventions have been specified, an intervention list
appears, and if you want to add additional intervention components, you must select Add in the
Interventions for Series window.
2.3 Using Special Variables to Model Events 2-59

The Intervention Specification Window

Event Date

Decay Pattern
Effect Variable
54

The number of lags for the Effect Time Window is discussed later.

Abrupt, Temporary Effect

Type: Point
Decay Pattern: Exp

Event
Effect 5 Time Units Later continued...

55

The Intervention Specification window reveals that the effect date is July 1982, the effect variable is a
point function, and the decay pattern is exponential decay. This combination of choices models an abrupt,
temporary effect.
2-60 Chapter 2 Simple Forecast Models

Abrupt, Temporary Effect

56

The abrupt effect is negative in that the number of traffic fatalities gets smaller.

Abrupt, Permanent Effect

Type: Step
Decay Pattern: None

Event Effect 5 Time Units Later continued...

57
2.3 Using Special Variables to Model Events 2-61

Abrupt, Permanent Effect

58

The plot shows that the mean of the series after the intervention is smaller than the mean before, but the
model ignores possible trend or decay.
To illustrate additional effects, the Seatbelt data (FETS.SEATBELT) is used. A mandatory seat belt law
was passed and became effective in January 1983. The variable of interest is the number of traffic
accident related injuries. The data range is from January 1980 to December 1985.
2-62 Chapter 2 Simple Forecast Models

Seatbelt Data (Smoothing Weight=65)


January 1983

59

A smoothing weight is selected to smooth out seasonal factors. The smoothed plot suggests a gradual
permanent effect.

Gradual, Permanent Effect

Type: Step
Decay Pattern: Exp

continued...
Event Effect 5 Time Units Later
60
2.3 Using Special Variables to Model Events 2-63

Gradual, Permanent Effect

61

The full model for this data should also include seasonal components to improve estimates related to the
intervention.

Changes in Level and Trend for Events


Y

After (average)

Before (average)

t
Event
False Inference: The event causes the result to increase
because AVERAGE(after)>AVERAGE(before).
Valid Inference: The event has no effect on the results.
62
2-64 Chapter 2 Simple Forecast Models

Changes in Level and Trend for Events


Y

t
Event

Valid Inference: The event causes a change in level.

continued...
63

Changes in Level and Trend for Events


Y

t
Event
Valid Inference: The event causes a change in the slope
of the trend line.
continued...
64
2.3 Using Special Variables to Model Events 2-65

Changes in Level and Trend for Events


Y

t
Event
Valid Inference: The event causes a change in the level
and the slope.
continued...
65

Changes in Level and Trend for Events


Y

t
Event

Step Function: Changes in level.


Ramp Function: Changes in slope. continued...

66
2-66 Chapter 2 Simple Forecast Models

Changes in Level and Trend for Events

Level
Slope

continued...

67

Changes in Level and Trend for Events

continued...
68
2.3 Using Special Variables to Model Events 2-67

Changes in Level and Trend for Events

Slope before event


continued...

69

Changes in Level and Trend for Events

Level after event


continued...

70
2-68 Chapter 2 Simple Forecast Models

Changes in Level and Trend for Events

Slope after event: sum of two slopes


continued...

71

Changes in Level and Trend for Events

72
2.3 Using Special Variables to Model Events 2-69

The Nine Individual Intervention Effects

73

Combined Effect of Two Events

01JUL1982: DWI Law Takes Effect

01JAN1982: Media Coverage Intensifies

continued...
74
2-70 Chapter 2 Simple Forecast Models

Combined Effect of Two Events

RMSE=4.341
75

Effect of Two Events: Alternate Model

01JUL1982: Point-Exp and Step Functions

01JAN1982: Step Function

continued...
76
2.3 Using Special Variables to Model Events 2-71

Effect of Two Events: Alternate Model

continued...
77
RMSE=4.159

Effect of Two Events: Alternate Model

Average of 14.65 fatalities per month prior to event 1

Event 1: Media Coverage of DWI Intensifies


continued...
Event 2: DWI Law Takes Effect
78
2-72 Chapter 2 Simple Forecast Models

Effect of Two Events: Alternate Model

Event 1 immediately reduces fatalities by 6.82 per month.

Event 1: Media Coverage of DWI Intensifies


continued...
Event 2: DWI Law Takes Effect
79

Effect of Two Events: Alternate Model

Event 2 immediately lowers fatalities by an additional 1.23.

Event 1: Media Coverage of DWI Intensifies


continued...
Event 2: DWI Law Takes Effect
80
2.3 Using Special Variables to Model Events 2-73

Effect of Two Events: Alternate Model

The overall effect is mostly temporary, with the long-term


drop expected to be approximately 1.23 fatalities/month.

Event 1: Media Coverage of DWI Intensifies


continued...
Event 2: DWI Law Takes Effect
81

Effect of Two Events: Alternate Model

The permanent 1.23 drop is tenuous at best.

Event 1: Media Coverage of DWI Intensifies


continued...
Event 2: DWI Law Takes Effect
82
2-74 Chapter 2 Simple Forecast Models

Effect of Two Events: Alternate Model


Media coverage of DWI activities, including coverage
of accidents as well as legislative activity, made
drivers more aware of DWI consequences, and many
drivers modified their behavior.
When the tough DWI law took effect, the behavior
modification increased in the driver population.
Unfortunately, the modified driver behavior appears to
be temporary.
More post-intervention data will be required to get a
better estimate of the long-term effect of the law.

83

While an adequate intervention model was obtained for the Arizona DWI data, later chapters will show
how to accommodate autocorrelated errors for similar problems.
2.4 Exponential Smoothing Forecast Models 2-75

2.4 Exponential Smoothing Forecast Models

Objectives
Describe the basic foundations of the class of
exponential smoothing models.
Introduce exponential smoothing models for time
series having a possible trend component.
Show examples of exponential smoothing forecasts,
and compare these to simple methods for modeling
trend.
Show how the TSFS accommodates exponential
smoothing models for trend.

85

The previous sections illustrated modeling trend and seasonality using linear regression models. In some
situations, the models were adequate, in others not. In some situations the residuals are not white noise.
In later chapters we will show how to augment the regression models with time series error terms to
improve the regression models. The remaining sections in this chapter introduce exponential smoothing
models that may have trend or seasonal components. Exponential smoothing models can account for
autocorrelation in the data as well as trend or seasonality. One limitation of exponential smoothing
models is that they can not account for special events. In a later chapter, techniques will be shown that
account for special events or interventions as well as autocorrelation.
2-76 Chapter 2 Simple Forecast Models

Exponential Smoothing Premise


Weighted averages of past values can produce good
forecasts of the future.
The weights should emphasize the most recent data.
Forecasting should only require a few parameters.
Forecast equations should be simple and easy to
implement.

86

Exponential smoothing models became popular after World War II. Practitioners needed accurate
forecasting techniques that minimized hand calculation. The techniques have not gone out of style even
though hand calculation is no longer an obstacle. The premises remain sound for modern business
forecasting problems.
2.4 Exponential Smoothing Forecast Models 2-77

ESM as Weighted Averages


Sample Mean Random Walk
Weights

Y8 Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y8 Y7 Y6 Y5 Y4 Y3 Y2 Y1

Weights applied to past values to predict Y9

87

If you want to express a forecast as a weighted average and follow the exponential smoothing practice of
weighting recent values higher than values farther in the past, then there are two extremes. The sample
mean gives every data point equal weighting, so it lies on the boundary of exponential smoothing models
while not actually satisfying the constraints on such models. A random walk model falls at the other
extreme, but it also fails to satisfy a mathematical constraint on the single parameter of a simple
exponential smoothing model1.

1
The omega coefficient is a single parameter exponential smoothing model that must fall exclusively between zero
and one. A random walk model is equivalent to an exponential smoothing model where omega is exactly one.
2-78 Chapter 2 Simple Forecast Models

ESM as Weighted Averages


n
Sample Mean Yn +1 = wtYt = w1Y1 + w2Y2 + L + wnYn
t =1
n
1 1 n
Weights

= Yt = Yt = Y
t =1 n n t =1
1
wt =
n
Y8 Y7 Y6 Y5 Y4 Y3 Y2 Y1
The mean is a weighted
1 8 average where all weights
Y9 = Yt are the same.
8 t =1

continued...

88

ESM as Weighted Averages


n
Random Walk
Yn +1 = wtYt = Yn
t =1

wn = 1, wt = 0 for t = 1,2, K, n 1

A random walk forecast


is a weighted average Y8 Y7 Y6 Y5 Y4 Y3 Y2 Y1
where all weights are 0
except the most recent,
which is 1. Y9 = Y8

89
2.4 Exponential Smoothing Forecast Models 2-79

The Exponential Smoothing Coefficient


Forecast Equation

Yt +1 = Yt + (1 )Yt
= Yt + (1 )[Yt 1 + (1 )Yt 1 ]
= Y + (1 )Y + (1 ) 2 Y
t t 1 t 1

= Yt + (1 )Yt 1 + (1 ) 2 [Yt 2 + (1 )Yt 2 ]


= Yt + (1 )Yt 1 + (1 ) 2 Yt 2 + (1 ) 3 Yt 3 + L

90

If the smoothing coefficient is constrained by 0 < < 1 , then the values (1 ) k get smaller as k gets
larger, producing an exponential decay for the weights in the weighted average. The name exponential
smoothing corresponds to the property of exponentially decaying weights.

Simple Exponential Smoothing


= 0 .5 = 0.25
Weights

Y8 Y7 Y6 Y5 Y4 Y3 Y8 Y7 Y6 Y5 Y4 Y3 Y2 Y1

Weights applied to past values to predict Y9


The larger the parameter, the more that
the most recent values are emphasized.

91

The smoothing weight omega () controls the rate of decay of the weights.
2-80 Chapter 2 Simple Forecast Models

Smoothing Weights
Level smoothing weight

Trend smoothing weight

Trend damping weight

The choice of Greek letter is arbitrary. The software


uses names rather than Greek symbols.

92

ESM Parameters

ESM Parameters Component


Simple Level
Double Level/Trend
Linear (Holt) , Level,Trend

Damped-Trend , , Level,Trend,Damping

93
2.4 Exponential Smoothing Forecast Models 2-81

Simple Exponential Smoothing Predictions


Y1 = S 0 = starting value,
Y2 = Y1 + (1 )Y1 = Y1 + (1 ) S 0 ,
Y = Y + (1 )Y ,
3 2 2

L
Yt +1 = Yt + (1 )Yt .
The forecast equation only requires knowledge of the
previous value, the previous forecast, and the
smoothing weight . The starting value is often taken to
be the mean of the first n observations. The TSFS uses
n=6.
94

Double Exponential Smoothing Predictions


Yt = 0 + 1t

The parameters 0 and 1 vary with respect to time.


Both parameters are derived from the data and from the
smoothing weight .

continued...

95
2-82 Chapter 2 Simple Forecast Models

Double Exponential Smoothing


St = Yt + (1 ) St 1 , Level equation

Tt = St + (1 )Tt 1 , Trend equation

Y = + (t + k ).
t +k 0t 1t
Prediction equation

96

The slope at time t is a function of the level and trend components and the smoothing weight:

1t = ( St Tt )
1-

The intercept at time t is a function of the level and trend components and the slope at time t:

0t = 2 St Tt t 1t

The TSFS does a linear regression on the first 6 observations to calculate starting values for the level and
trend components.

1
S0 = 0,0 1,0 ,

1
T0 = 0,0 2 1,0 .

2.4 Exponential Smoothing Forecast Models 2-83

Linear (Holt) Exponential Smoothing


St = Yt + (1 )( St 1 + Tt 1 ),
Tt = ( St S t 1 ) + (1 )Tt 1 ,
Yt + k = St + kTt .
Linear exponential smoothing uses an additional
smoothing weight. As with double exponential
smoothing, there is a slope/intercept formulation.
Details may be found in the online help.

97

Damped-Trend Linear Exponential Smoothing


St = Yt + (1 )( St 1 + Tt 1 ),
Tt = ( St St 1 ) + (1 )Tt 1 ,
k i
Yt + k = St + Tt .
i =1
Damped-trend linear exponential smoothing uses a
third smoothing weight. The damping weight forces the
slope to approach zero. Details may be found in the
online help.

98

Exponential smoothing trend models are primarily useful for short-term forecasting. A simple exponential
smoothing model produces forecasts that quickly converge to the mean of the series. Exponential
smoothing models with two parameters tend to forecast accurately farther into the future than models with
a single parameter. Linear (Holt) exponential smoothing models often produce forecasts that are accurate
for moderate-term forecasting. Exponential smoothing trend models are rarely accurate for long-term
forecasting.
2-84 Chapter 2 Simple Forecast Models

Exponential Smoothing Models in the TSFS

continued...

99

Exponential Smoothing Models in the TSFS

continued...

100
2.4 Exponential Smoothing Forecast Models 2-85

Exponential Smoothing Models in the TSFS

continued...

101

Exponential Smoothing Models in the TSFS

continued...

102
2-86 Chapter 2 Simple Forecast Models

Exponential Smoothing Models in the TSFS

continued...

103

Exponential Smoothing Models in the TSFS

continued...

104
2.4 Exponential Smoothing Forecast Models 2-87

Exponential Smoothing Models in the TSFS

You can control how coefficients are obtained.


Default settings are recommended for those
with no experience fitting these models.
105

Exponential Smoothing Models in the


TSFSModel Assessment
Do the prediction errors (residuals) appear
to be white noise, that is, do the prediction
errors appear to be independent and follow
a Gaussian normal distribution?
Are all estimated parameters statistically
significantly different from zero?
Do the extrapolated forecasts pass a face
validity test, that is, do the forecasts seem
reasonable based on domain expertise?

106
2-88 Chapter 2 Simple Forecast Models

Exponential Smoothing Models for the


Monthly U.S. Lead Production Data

Exponential Smoothing Models will be continued...

107 compared to the current three best models.

Exponential Smoothing Models for the


Monthly U.S. Lead Production Data

The Linear Exponential Smoothing model is


continued...
best based on RMSE.
108
2.4 Exponential Smoothing Forecast Models 2-89

Exponential Smoothing Models for the


Monthly U.S. Lead Production Data

Models are sorted from best


continued...
to worst based on RMSE.
109

Exponential Smoothing Models for the


Monthly U.S. Lead Production Data

continued...

110

The forecasts suggest a linear trend with a negative slope.


2-90 Chapter 2 Simple Forecast Models

Exponential Smoothing Models for the


Monthly U.S. Lead Production Data

continued...

111

The damped trend model produces forecasts that have a shallower linear trend than the Holt linear
exponential smoothing model.

Exponential Smoothing Models for the


Monthly U.S. Lead Production Data

continued...

112

Simple exponential smoothing always produces multiple step ahead forecasts that are flat.
2.4 Exponential Smoothing Forecast Models 2-91

Exponential Smoothing Models for the


Monthly U.S. Lead Production Data

continued...

113

Double exponential smoothing forecasts show a rather steep downward trend.


2-92 Chapter 2 Simple Forecast Models

Exponential Smoothing Models for the


Monthly U.S. Lead Production Data

continued...

114

Some might argue that a quadratic trend model produces the most reasonable forecasts given the apparent
parabolic shape of the data. On the other hand, quadratic trend produces the largest RMSE value.
The best model based on RMSE is the Holt linear exponential smoothing model. The model must be
assessed to see if it is appropriate as a forecast model.

Exponential Smoothing Models for the


Monthly U.S. Lead Production Data

continued...

115
The prediction errors appear to be random.
2.4 Exponential Smoothing Forecast Models 2-93

Exponential Smoothing Models for the


Monthly U.S. Lead Production Data

continued...

116
Autocorrelation plots are consistent with white noise.

Exponential Smoothing Models for the


Monthly U.S. Lead Production Data

continued...

117
Residuals pass tests for stationarity and no autocorrelation.
2-94 Chapter 2 Simple Forecast Models

Exponential Smoothing Models for the


Monthly U.S. Lead Production Data

The Trend Smoothing Weight is not statistically


significantly different from zero. continued...

118

 Exponential smoothing models should not be disqualified because estimates are not statistically
significantly different from zero. The test can fail for several reasons. An estimate near a zero-one
parameter boundary may produce inflated standard errors, invalidating the test. The estimates are
not scale invariant so that data with large values can produce very small estimates. Furthermore,
the distributional properties are based on the use of an equivalent ARMA statespace formulation,
whereas exponential smoothing models were originally derived without consideration of
distributional properties. In fact, early applications did not estimate parameters using valid
statistical estimation techniques, but rather imposed parameter values based on the forecast
application, tradition, or trial-and-error.

 The entry Smoothed Level corresponds to the value of St at the end of the Fit Range, which is
shown at the bottom of the window to be SEP1992 (September 1992). The entry Smoothed Trend
corresponds to the value of Tt at the end of the Fit Range. Thus, at the end of the Fit Range, the
time-dependent slope is negative.
Some of the models are disqualified because of one or more problems encountered during assessment.
2.4 Exponential Smoothing Forecast Models 2-95

Exponential Smoothing Models for the


Monthly U.S. Lead Production Data

continued...
The Double Exponential Smoothing
119 model fails a white noise test.

When significant autocorrelation is present in the residuals, evidence suggests that the model inadequately
characterizes the memory of the time series. For example, a significant autocorrelation at lag 4 suggests
that the residuals remember four time units in the past, so the model does not adequately address this
four-month memory.

Exponential Smoothing Models for the


Monthly U.S. Lead Production Data

continued...

120
2-96 Chapter 2 Simple Forecast Models

Exponential Smoothing Models for the


Monthly U.S. Lead Production Data

continued...
The Quadratic Trend model fails to
121 account for first order autocorrelation.

Exponential Smoothing Models for the


Monthly U.S. Lead Production Data

continued...
The Quadratic Trend model
122 fails the white noise test.
2.4 Exponential Smoothing Forecast Models 2-97

Exponential Smoothing Models for the


Monthly U.S. Lead Production Data

123

While quadratic trend produces visually pleasing forecasts, the model must be disqualified. In later
chapters, you will see how to enhance the quadratic trend model so that it accounts for autocorrelation.
2-98 Chapter 2 Simple Forecast Models

2.5 Exponential Smoothing Models with Trend and Seasonal


Components

Objectives
Introduce the three exponential smoothing models that
accommodate seasonality.
Show how Holt-Winters exponential smoothing models
can accommodate trend and seasonal components.
Compare exponential smoothing models to simple
models for trend and seasonality.

125

ESM for Seasonal Data


Weights


Jan04 Jan03 Jan02 Jan01 Jan00 Feb04 Feb03 Feb02 Feb01 Feb00

Weights decay with respect to the seasonal factor.

126
2.5 Exponential Smoothing Models with Trend and Seasonal Components 2-99

ESM Seasonal Factors


First seasonal factor s1 is always natural.
first season: January, Sunday, Q1

Additive model:
factors sum to 0

Multiplicative model:
factors average to 1 s1 s2 s3 s4 s5 s6 s7 s8 s9 s10 s11s12
Monthly Seasonal Factors

127

Smoothing Weights
Level smoothing weight

Trend smoothing weight

Seasonal smoothing weight

Trend damping weight

The choice of Greek letter is arbitrary. The software


uses names rather than Greek symbols.

128
2-100 Chapter 2 Simple Forecast Models

ESM Parameters

ESM Parameters
Simple
Double
Linear (Holt) ,
Damped-Trend , ,
Seasonal ,
Additive Winters , ,
Multiplicative Winters , ,
129

Seasonal Exponential Smoothing


Yt = t + s p (t ) + t

t 0

s1 s2 s3 s4 s5 s6 s7 s8 s9 s10 s11s12
Level + Seasonal

130
2.5 Exponential Smoothing Models with Trend and Seasonal Components 2-101

Winters Method Additive


Yt = t + t t + s p (t ) + t

Level+Trend + Seasonal

131

Winters Method Multiplicative


Yt = ( t + t t ) s p (t ) + t

Level+Trend Seasonal

132

The seasonal exponential smoothing models are implemented like the exponential smoothing models for
trend. There is a smoothed level and smoothed trend term. Furthermore, if the data is seasonal with a
period of S, there will be S smoothed seasonal terms. As before, these terms will be time dependent,
expressed as updating equations that depend only on the most recent data and most recent smoothing
term.
2-102 Chapter 2 Simple Forecast Models

Seasonal Exponential Smoothing Models in


the TSFS

continued...

133

Seasonal Exponential Smoothing Models in


the TSFSModel Assessment
Do the prediction errors (residuals) appear
to be white noise, that is, do the prediction
errors appear to be independent and follow
a Gaussian normal distribution?
Are all estimated parameters statistically
significantly different from zero?
Do the extrapolated forecasts pass a face
validity test, that is, do the forecasts seem
reasonable based on domain expertise?

continued...

134
2.5 Exponential Smoothing Models with Trend and Seasonal Components 2-103

Seasonal Exponential Smoothing Models in


the TSFS

Three seasonal models are fit to the construction


data. The model with smallest RMSE is checked.
The Winters-Additive model appears to be the
best forecast model based on RMSE.

continued...

135

Seasonal Exponential Smoothing Models in


the TSFSForecast Plot

continued...

136
2-104 Chapter 2 Simple Forecast Models

Seasonal Exponential Smoothing Models in


the TSFSForecast Plot

continued...

137

Seasonal Exponential Smoothing Models in


the TSFSForecast Plot

138
2.5 Exponential Smoothing Models with Trend and Seasonal Components 2-105

Seasonal Exponential Smoothing Models in


the TSFSForecast Plots
All three seasonal models produce similar forecasts.
No forecast method is obviously superior based on
these plots.
The 95% prediction confidence limits are narrow
because of the strong seasonal component.
Winters models should be more accurate if trend is
present.

continued...

139

Seasonal Exponential Smoothing Models in


the TSFSModel Assessment
Winters-Additive

Do the prediction
errors (residuals)
look random?

Are there a few


large run
sequences?
Arrows indicate
possible unusual
runs.
continued...

140
2-106 Chapter 2 Simple Forecast Models

Seasonal Exponential Smoothing Models in


the TSFSModel Assessment

The spike at lag 7 in


the ACF and at lags
5 and 7 in the PACF
suggest that the
residuals are not
white noise.

continued...

141

Seasonal Exponential Smoothing Models in


the TSFSModel Assessment

A null
hypothesis of
white noise is
rejected at the
1% level of
significance.
continued...

142
2.5 Exponential Smoothing Models with Trend and Seasonal Components 2-107

Seasonal Exponential Smoothing Models in


the TSFSModel Assessment

The p-value for the


seasonal smoothing
weight is 0.9859, so the
weight is not statistically
significantly different
from zero.

143

Winters-Additive Model Assessment


Prediction errors do not satisfy the white noise
requirement.
The seasonal smoothing weight is not statistically
significantly different from zero even though the data
is strongly seasonal.

Practical Concerns
Autocorrelated prediction errors imply that a necessary
component is missing from the model.
Statistical significance can be misleading and large
p-values for estimates are not sufficient to disqualify
a model.

144

Just like for the trend models, when a coefficient hits a boundary in the optimization process for
parameter estimation, the standard error of the estimate may be invalid. In the above example, the
seasonal smoothing weight has value 0.001, which is the default boundary in the TSFS to force the weight
to be between zero and one. Consequently, test statistics and p-values may be erroneous for boundary
situations.
2-108 Chapter 2 Simple Forecast Models

Exercises

3. Determine an appropriate exponential smoothing model for the variable HSTART in the construction
data.
2.6 Chapter Summary 2-109

2.6 Chapter Summary


The Time Series Forecasting System supports a variety of trend components.

The TSFS also supports seasonal dummy regressors and seasonal differencing to model seasonal time
series.
All time series exponential smoothing models are supported by the TSFS.

The TSFS also provides assessment tools to verify the validity of a forecast model.
2-110 Chapter 2 Simple Forecast Models

For Additional Information


Bowerman, B.L., and OConnell, R.T. (1993), Forecasting and Time Series: An Applied Approach,
Third Edition, Belmont, California: Duxbury Press.

SAS Institute Inc. (1996), Forecasting Examples for Business and Economics Using the SAS System,
Cary, NC: SAS Institute Inc.
West, S.G., McCall, M.A., Hepworth, J.T., and Reich, J.W. (1985), An Evaluation of Arizonas 1982
Drunk Driving Law: Effects on the City of Phoenix, Final report to the Morrison Institute.
Woodfield, T.J. (1987), Time Series Intervention Analysis Using SAS Software, Proceedings of the
Twelfth Annual SAS Users Group International Conference, 331-339. Cary, North Carolina:
SAS Institute Inc.
2.7 Solutions to Exercises 2-111

2.7 Solutions to Exercises


1. The following screen capture summarizes eleven trend models for the monthly lead production data,
including two models with stochastic trend.
2-112 Chapter 2 Simple Forecast Models

Following are prediction plots for the top three models based on RMSE.
2.7 Solutions to Exercises 2-113
2-114 Chapter 2 Simple Forecast Models

Cubic trend should be rejected based on the usual poor extrapolation features. The other two models can
be defended, although the quadratic trend model produces forecasts that are more visually pleasing.
Industry experts would probably pick the random walk model, which as you may recall is equivalent to a
model with first differencing and no constant term.
2.7 Solutions to Exercises 2-115

2. Following is a summary of four models fit to the housing starts variable.

The best model must be rejected for the same reasons the best model was rejected for the construction
contracts variable.
3. Following is a screen capture of the Develop Models window showing the results for all exponential
smoothing models fit to the housing starts data.
2-116 Chapter 2 Simple Forecast Models

None of the exponential smoothing models surpass the Log Seasonal Dummies + Quadratic Trend model
that was fit before. However, the seasonal models are clearly superior to the nonseasonal exponential
smoothing models. The Winters MethodAdditive is the best exponential smoothing model based on
RMSE. A forecast plot for this model follows.

Additional assessment results follow.


2.7 Solutions to Exercises 2-117
2-118 Chapter 2 Simple Forecast Models

Evidence suggests that the prediction errors behave like a white noise series.
2.7 Solutions to Exercises 2-119

The only assessment problems for the Winters Additive model are the large p-values for the trend and
seasonal smoothing weights. The Winters Additive model cannot be disqualified, unlike the Log Seasonal
Dummies + Quadratic Trend model. Therefore, you could use the Winters Additive model to forecast the
housing starts data.
2-120 Chapter 2 Simple Forecast Models
Chapter 3 Advanced Forecast
Models for Stationary Time Series

3.1 Introduction to Box-Jenkins Forecasting ....................................................................3-3

3.2 Autoregressive Models ................................................................................................3-14

3.3 Moving Average Models...............................................................................................3-21

3.4 Mixed Autoregressive Moving Average Models ........................................................3-23

3.5 Identifying an Appropriate Autoregressive Moving Average Model ........................3-26

3.6 Estimation and Forecasting Methods.........................................................................3-61

3.7 Chapter Summary.......................................................................................................3-108

3.8 Solutions to Exercises ...............................................................................................3-109


3-2 Chapter 3 Advanced Forecast Models for Stationary Time Series
3.1 Introduction to Box-Jenkins Forecasting 3-3

3.1 Introduction to Box-Jenkins Forecasting

Objectives
Define a stationary time series.
Explain autocorrelation.
Define the three autocorrelation plots available in the
TSFS.
List the three steps of the Box-Jenkins forecasting
methodology.

A Stationary Time Series


Has constant mean and variance over time
Has no strong trend component
Has no strong seasonal cycles

4
3-4 Chapter 3 Advanced Forecast Models for Stationary Time Series

The Autocorrelation Function


The autocorrelation function (ACF) measures the
dependence among observations in a time series.
The autocorrelation at lag k is the correlation of
observations k time units apart.
Time series models exploit the autocorrelation in the
series to improve estimation of model parameters and
the forecast of future values of the series.

The population autocovariance function at lag k is given by:

k = E[(Yt )(Yt k )] = E(YtYt k ) 2


The population autocorrelation function at lag k is given by:
k
k =
0

The sample autocorrelation function at lag k is given by:

nk

(y t y )( yt + k y )
rk = t =1
n
.
(yt =1
t y) 2

The sample autocorrelation function is a statistical estimate of the unknown population autocorrelation
function.
3.1 Introduction to Box-Jenkins Forecasting 3-5

Plot of Series with Population ACF(1)=0.90


Overlaid with White Noise
Series Y White Noise

While you will not be able to diagnose first-order autocorrelation simply by examining a plot of the time
series, you can see in the above plot how an autocorrelated series compares to a white noise series. Recall
that a white noise series has an autocorrelation function that is identically zero for all positive lags.

Plot of Series with Population ACF(1)= -0.90


Overlaid with White Noise
Series Y White Noise

7
3-6 Chapter 3 Advanced Forecast Models for Stationary Time Series

Comments on Autocorrelation
Series with positive autocorrelation tend to remain
above or below the mean for extended periods of time.
Series with negative autocorrelation tend to rapidly
switch between above and below the mean.
Autocorrelation is not always detectable from plots of
the data.
Plots and statistical tests are available that are
designed to detect significant autocorrelation.

Autocorrelation Plots
The autocorrelation function (ACF) plot is one
diagnostic tool available to detect the presence of
autocorrelation in data as well as to estimate the
magnitude and sign of the autocorrelation.
The partial autocorrelation function (PACF) at lag k is
the autocorrelation between observation k time units
apart adjusted for all autocorrelation for observations
less than k time units apart.
The inverse autocorrelation function (IACF) is similar
to the PACF, but is more sensitive than the PACF for
some features of autocorrelation.

You must learn a few more time series concepts before the PACF and IACF can be explicitly defined.
3.1 Introduction to Box-Jenkins Forecasting 3-7

Autocorrelation Plots for Series with


Population ACF(1)=0.90

continued...

10

Because the sample autocorrelation function estimates the true underlying autocorrelation function, the
value of ACF(1) in the above plot is near the true value of 0.9. You will learn that ACF(1)=PACF(1), so
PACF(1) is also near 0.9.

Autocorrelation Plots for Series with


Population ACF(1)=-0.90

11
3-8 Chapter 3 Advanced Forecast Models for Stationary Time Series

Plot of Series with Population ACF(1)=0.50


Overlaid with White Noise

12

As the first-order autocorrelation gets smaller, the time series more closely resembles white noise.

Autocorrelation Plots for Series with


Population ACF(1)=0.50

13

However, the values of ACF(1) and PACF(1) are statistically significantly different from zero based on
the 95% confidence regions given in the plots as red lines (shown in grayscale above). Even small ACF
values can be statistically significant if the series is of sufficient length.
3.1 Introduction to Box-Jenkins Forecasting 3-9

Plot of Series with Population ACF(1)=0.10


Overlaid with White Noise

14

The time series with ACF(1)=0.10 is almost indistinguishable from white noise.

Autocorrelation Plot for Series with Population


ACF(1)=0.10

15

Even with such a small ACF(1) value, the estimate is statistically significant.
3-10 Chapter 3 Advanced Forecast Models for Stationary Time Series

Autocorrelation Plots Summary


For the series with population autocorrelation of 0.90
or -.90, the autocorrelation plots confirmed the
autocorrelation apparent in the series plots.
For the series with population autocorrelation of 0.50,
autocorrelation was not obvious in the series plot. The
autocorrelation plots, however, gave strong evidence
of significant autocorrelation in the data.
For the series with autocorrelation of 0.10, the series
plot was indistinguishable from random noise. The
autocorrelation plots, however, gave evidence of
significant autocorrelation in the data.

16

Box-Jenkins ARMA Models


A stationary time series with an autocorrelation
function that is zero at all positive lags is a white noise
time series.
A stationary time series that has at least one nonzero
autocorrelation can be approximated by an ARMA
model.
AR: Autoregressive Time series is a function of its
own past.
MA: Moving Average Time series is a function of
past shocks (deviations, innovations, errors, and so
on).

17

Box-Jenkins modeling is so named because of the classic textbook written by Box and Jenkins in the
1970s (Time Series Analysis: Forecasting and Control). This textbook introduced ARMA models as well
as a methodology for deriving forecasts. Box and Jenkins did not invent ARMA models, but they are
responsible for making them popular.
3.1 Introduction to Box-Jenkins Forecasting 3-11

The Autoregressive Model, AR(p)


AR(1): The current value of the time series depends on the
most recent value of the series, one time unit in the past.

Yt = 0 + 1Yt 1 + t
AR(2): The current value of the time series depends on the
two most recent values of the series, one time unit in the
past and two time units in the past.

Yt = 0 + 1Yt 1 + 2Yt 2 + t

18

The Moving Average Model, MA(q)


MA(1): The current value of the time series depends on the
most recent error value, one time unit in the past.

Yt = 0 + 1 t 1 + t
MA(2): The current value of the time series depends on the
two most recent error values, one time unit in the past and
two time units in the past.

Yt = 0 + 1 t 1 + 2 t 2 + t

19
3-12 Chapter 3 Advanced Forecast Models for Stationary Time Series

The Autoregressive Moving Average Model,


ARMA(p,q)
ARMA(1,1): The current value of the time series depends on
the most recent time series value and the most recent error
value, each one time unit in the past.

Yt = 0 + 1Yt 1 + 1 t 1 + t

20

The forecaster can rely on a strong theoretical foundation for ARMA models. ARMA models can
approximate any stationary process arbitrarily closely. The challenge is to find the best approximating
model. Should you employ an AR(p) model, an MA(q) model, or an ARMA(p,q) model. This simplifies
to determining appropriate values for p and q. Just because theory guarantees the existence of an
approximating ARMA model does not guarantee that you will find the model.

Box-Jenkins Modeling Methodology


Identify Determine ARMA orders (p,q) using
ACF, PACF, and the IACF.

Estimate Fit the ARMA(p,q) model and assess


the fit of the model.

Forecast Produce forecasts using the best


ARMA model that passes assessment.

The general Box-Jenkins modeling methodology addresses


trend and seasonality as well.

21
3.1 Introduction to Box-Jenkins Forecasting 3-13

Box-Jenkins Methodology
The autocorrelation plots are key tools in the Identify
step.
Patterns in the ACF, PACF, and IACF can be used to
suggest different models to estimate. In the following
sections, patterns will be shown for specific models as
they are defined.
After a candidate set of models are identified, the
models are estimated and their fit assessed.
The best fitting models are used to generate forecasts.
The forecast of the models are assessed and the most
appropriate ones are chosen.

22

When non-stationary time series are investigated, the identify step will add another challenge: Determine
an appropriate trend and/or seasonal component for the model.
3-14 Chapter 3 Advanced Forecast Models for Stationary Time Series

3.2 Autoregressive Models

Objectives
Describe an autoregressive model of order 1, denoted
by AR(1).
Describe an AR(2) model.
Describe an AR(p) model.

24

The First-Order Autoregressive Model, AR(1)


Regression
Yt = 0 + 1Yt 1 + t Notation

Yt = 0 + 1Yt 1 + t Box-Jenkins
Notation

Yt = 1 (Yt 1 ) + t

25
3.2 Autoregressive Models 3-15

Parameterization of an AR(1) Model

Yt = 1 (Yt 1 ) + t

Yt = 0 + 1Yt 1 + t

0 = (1 1 ), = 0 /(1 1 )

26

The Second-Order Autoregressive Model,


AR(2)
Regression
Yt = 0 + 1Yt 1 + 2Yt 2 + t Notation

Yt = 0 + 1Yt 1 + 2Yt 2 + t Box-Jenkins


Notation

Yt = 1 (Yt 1 ) + 2 (Yt 2 ) + t

27
3-16 Chapter 3 Advanced Forecast Models for Stationary Time Series

Parameterization of an AR(2) Model

Yt = 1 (Yt 1 ) + 2 (Yt 2 ) + t

Yt = 0 + 1Yt 1 + 2Yt 2 + t

0 = (1 1 2 ), = 0 /(1 1 2 )

28

Autoregressive Models
A time series that is a linear function of p past values plus
error is called an autoregressive process of order p,
denoted AR(p).

Yt = 0 + 1Yt 1 + 2Yt 2 + L + pYt p + t

29

Autoregressive models are easy to work with because they so closely resemble regression models. In fact,
if you cheat and let X 1 = Yt 1 , X 2 = Yt 2 , K , X p = Yt p , then you can use a least squares regression
application to derive estimates of the autoregressive coefficients. These estimates will be inferior to the
estimates derived by the TSFS, but for long series, the values will be very close.
3.2 Autoregressive Models 3-17

Yule-Walker Equations
The Yule-Walker equations for an AR(p) model are given by:

k = 1 k 1 + 2 k 2 + L + p k p
AR(1) Model: PACF(1)=ACF(1)=1=1
1
1 = 1 0 , 1 = = 1
0
AR(2): PACF(2)=2
1 = 1 0 + 2 1 = 1 + 2 1 ,
2 = 1 1 + 2 0 = 1 1 + 2
30

For an AR(p) time series, there are p equations and p unknowns in a linear system of equations. When
you replace the population autocorrelation values in the system of equations with their estimates, the
sample ACF values, then you can solve for the coefficients. These estimates are called method of
moments estimates because they are derived using sample estimates of population moments. In time series
analysis, the estimates are referred to as Yule-Walker estimates. The TSFS does not have an option for
obtaining Yule-Walker estimates. The TSFS uses the theoretically superior maximum likelihood
estimates.
3-18 Chapter 3 Advanced Forecast Models for Stationary Time Series

The Partial Autocorrelation Function


PACF(k) measures the correlation of a time series with
itself at lag k adjusted for lags 1 through k-1.
PACF(k) is the coefficient of the kth order
autoregressive term in an autoregressive order-k
model.
PACF(k) is calculated using a recursion equation that
is based on the Yule-Walker equations, where
population autocorrelations k are replaced by sample
autocorrelations rk.

31

While the system of p linear equations produces estimates for p phi coefficients, only the highest order
coefficient is used to derive the PACF. Thus, the software assumes an AR(1) model and calculates
PACF(1) using the Yule-Walker equations. Then it assumes an AR(2) model and calculates PACF(2) as
the highest order phi coefficient, namely 2. This process continues until the specified number of PACF
values is obtained. The reasoning behind the PACF is that, for example, if PACF(4) is not statistically
significant, then the AR(4) model fit to the data is over-parameterized, and an AR(3) model may be more
appropriate.
3.2 Autoregressive Models 3-19

The Inverse Autocorrelation Function


The IACF is the autocorrelation function of the inverse
model.
The IACF has the same interpretation as the PACF,
although it is calculated differently.
IACF(k) is the inverse autocorrelation at lag k.
The IACF can identify model behavior not detected by
the PACF.

continued...

32

The Inverse Autocorrelation Function


If the Model is

Yt = 0 + 1Yt 1 + 2Yt 2 + t
the Inverse Model is

Yt = 0 + 1 t 1 + 2 t 2 +

33

An ARMA time series has an ACF and PACF that are completely determined by the coefficients of the
ARMA model. These are different than the sample ACF and PACF values calculated from the data. You
can think of the sample ACF as a nonparametric estimate of the population autocorrelation function, and
the ACF determined by an estimated ARMA model as a parametric estimate of the population
autocorrelation function.
3-20 Chapter 3 Advanced Forecast Models for Stationary Time Series

The IACF is calculated in three steps.


1. Choose a high order AR model to approximate the series. (By default, an AR(24) model is chosen.)
2. Fit the AR model to the data using the Yule-Walker equations.
3. Calculate the ACF from the estimated parameters of the AR model, except use an MA model instead
of the AR model, and let the estimated phi values become the theta values in the moving average
model. This estimated ACF derived using an approximating AR model inverted to an MA model
becomes the IACF.
The ACF and PACF are uniquely determined by the data and should agree across software products. On
the other hand, because the IACF depends on which AR model is used, different software may employ
different default settings, which may lead to substantially different IACF values. You will encounter
unusual IACF plots that provide substantially different results than the PACF plots. The likely explanation
is that the AR model used does not approximate the true model very well.

 SAS/IML software provides function ARMACOV that produces the autocovariance function for a
given ARMA model.
3.3 Moving Average Models 3-21

3.3 Moving Average Models

Objectives
Describe a moving average model of order 1, denoted
by MA(1).
Describe an MA(2) model.
Describe an MA(q) model.

35

The First-Order Moving Average Model, MA(1)

Yt = 0 + t 1 t 1 Box-Jenkins
Notation

= 0 Mean=Constant=Intercept

36
3-22 Chapter 3 Advanced Forecast Models for Stationary Time Series

The Second-Order Moving Average Model,


MA(2)

Yt = 0 + t 1 t 1 2 t 2 Box-Jenkins
Notation

= 0 Mean=Constant=Intercept

37

Moving Average Models


A time series that is a linear function of q past errors is called
a moving average process of order q, denoted MA(q).

Yt = 0 + t 1 t 1 2 t 2 L q t q

38

While AR, MA, and ARMA models are all universal approximators, MA models are rarely used to derive
statistics, primarily because there is no counterpart to the Yule-Walker equations for MA models.
3.4 Mixed Autoregressive Moving Average Models 3-23

3.4 Mixed Autoregressive Moving Average Models

Objectives
Describe an autoregressive moving average model
with autoregressive order 1 and moving average order
1, denoted by ARMA(1,1).
Describe an ARMA(1,2) model.
Describe an ARMA(2,1)model.
Describe an ARMA(p,q) model.

40

The ARMA(1,1) Model

Yt = 1 (Yt 1 ) + t 1 t 1

Alternate Parameterization:

Yt = 0 + 1Yt 1 + t 1 t 1
0 = (1 1 )

41
3-24 Chapter 3 Advanced Forecast Models for Stationary Time Series

The ARMA(1,2) Model

Yt = 1 (Yt 1 ) + t 1 t 1 2 t 2

Alternate Parameterization:

Yt = 0 + 1Yt 1 + t 1 t 1 2 t 2
0 = (1 1 )

42

The ARMA(2,1) Model

Yt = 1 (Yt 1 ) + 2 (Yt 2 ) + t 1 t 1

Alternate Parameterization:

Yt = 0 + 1Yt 1 + 1Yt 1 + t 1 t 1
0 = (1 1 2 )

43
3.4 Mixed Autoregressive Moving Average Models 3-25

Autoregressive Moving Average Models


A time series that is a linear function of p past values plus a
linear combination of q past errors is called an
autoregressive moving average process of order (p,q),
denoted ARMA(p,q).

Yt = 0 + 1Yt 1 + 2Yt 2 + L + pYt p +


t 1 t 1 2 t 2 L q t q

44

Because AR models are universal approximators, and because it is easy to fit an AR model to data, you
may question why you even need to consider MA and ARMA models. Box and Jenkins show that an
ARMA model almost always has fewer parameters than the corresponding approximating AR model.
Parsimony is an important concept in Box-Jenkins time series analysis.
3-26 Chapter 3 Advanced Forecast Models for Stationary Time Series

3.5 Identifying an Appropriate Autoregressive Moving


Average Model

Objectives
Describe the general ACF, PACF, and IACF patterns
of an AR(p) process.
Describe the general ACF, PACF, and IACF patterns
of an MA(q) process.
Describe the general ACF, PACF, and IACF patterns
of a mixed ARMA(p,q) process.
Summarize a step-by-step approach for identifying a
candidate set of ARMA(p,q) models and assess their
fit.

46

The Box-Jenkins identify step utilizes the ACF, PACF, and IACF to suggest ARMA models for the data.

Box-Jenkins Modeling Methodology


Identify Determine ARMA orders (p,q) using
ACF, PACF, and the IACF.

Estimate Fit the ARMA(p,q) model and assess


the fit of the model.

Forecast Produce forecasts using the best


ARMA model that passes assessment.

The general Box-Jenkins modeling methodology addresses


trend and seasonality as well.
47
3.5 Identifying an Appropriate Autoregressive Moving Average Model 3-27

Identifying an AR(p) Model


The PACF and IACF are important in identifying the
order, p, of an AR model.
The highest lag of the PACF values or IACF values
that are significantly different from zero suggest the
appropriate value of p.
The significant lags are called spikes.

48

Autocorrelation Plots for an AR(1) Time Series

49

The PACF has only one significant value, and it occurs at lag 1. The IACF also has only one significant
value at lag 1. The ACF has several significant values, and the ACF exhibits exponential decay.
3-28 Chapter 3 Advanced Forecast Models for Stationary Time Series

Autocorrelation Plots for an AR(2) Time Series

50

The PACF has only two significant values, and they occur at lags 1 and 2. The IACF also has only two
significant values at lags 1 and 2. The ACF has several significant values, and the ACF exhibits
exponential decay, but the decay is slower than you observed for the AR(1) time series.

Autocorrelation Plots for an AR(3)

51

The PACF has only three significant values, and they occur at lags 1, 2, and 3. The general pattern for the
sample autocorrelation functions are given in the next two slides.
3.5 Identifying an Appropriate Autoregressive Moving Average Model 3-29

Portfolio of Shapes AR(p) Model


ACF PACF/IACF

... ...

1 2 3 p 1 2 3 p

Exponential Decay Drops to 0 after lag p

continued...

52

Portfolio of Shapes AR(p) Model


ACF PACF/IACF

... ...

1 2 3 p 1 2 3 p

Exponential Decay Drops to 0 after lag p

53

The autocorrelation functions shown in the slides are population functions. Dropping to zero for
population values is related to becoming insignificant for sample values. Calculated values of the ACF,
PACF, and IACF will often be near zero for higher lags.
3-30 Chapter 3 Advanced Forecast Models for Stationary Time Series

Identifying Autoregressive Models

From the TSFS main menu, select Manage Projects.

In the Manage Forecasting Project window, change the name of the project to
SASUSER.FMSPROJ.CH4.

Close the window by selecting the in the upper-right corner. The TSFS main menu appears.
3.5 Identifying an Appropriate Autoregressive Moving Average Model 3-31

Select the Browse button next to the Data Set field. The Data Set Selection window appears.

Select the FETS library and the AR1 data set.

Note that the Time ID and the Interval are filled in.
Select OK to return to the TSFS main menu.
3-32 Chapter 3 Advanced Forecast Models for Stationary Time Series

Select the View Series Graphically button, , below the Create button. The Series Selection
window opens.

Select Y as the series to identify. Select the Graph button. A graph of the series appears.
3.5 Identifying an Appropriate Autoregressive Moving Average Model 3-33

Select the Autocorrelation button, . The autocorrelation plots display.


3-34 Chapter 3 Advanced Forecast Models for Stationary Time Series

The significant spikes at lag 1 in the PACF and IACF suggest that the series is AR(1). The spikes are
significant because they extend beyond the 95 percent confidence bounds, the red lines. The exponential
decay in the ACF is also consistent with an AR(1) process.

Select the back arrow . The Series Selection window appears. Select the AR2 data set and the Y
series.

Select the Graph button. A warning window appears.

Select OK. A graph of the series appears.


3.5 Identifying an Appropriate Autoregressive Moving Average Model 3-35

Select the Autocorrelations button. The autocorrelation plots appear.


3-36 Chapter 3 Advanced Forecast Models for Stationary Time Series

The first two spikes in the PACF and IACF are significantly different than zero, which suggests an AR(2)
process. The exponential decay in the ACF is consistent with an AR(2) process.
Go back to the TSFS main menu by selecting the back arrow and then closing the Series Selection
window.
3.5 Identifying an Appropriate Autoregressive Moving Average Model 3-37

Identifying an MA(q) Model


The ACF is important in identifying the order, q, of an
MA model.
The highest lag of the ACF values that is significantly
different from zero suggests the appropriate value of
q.
The significant lags are called spikes.
The roles of the ACF, PACF, and IACF switch for
identifying an AR model versus an MA model.

60

Autocorrelation Plots for an MA(1)

61

The ACF has only one significant value and it occurs at lag 1. The PACF and IACF have several
significant values, and these functions exhibit exponential decay.
3-38 Chapter 3 Advanced Forecast Models for Stationary Time Series

Autocorrelation Plots for an MA(2)

62

The ACF has only two significant values, and they occur at lags 1 and 2. The PACF and IACF exhibit
exponential decay.

Autocorrelation Plots for an MA(3)

63

The ACF has only three significant values, and they occur at lags 1, 2, and 3. The general patterns for the
sample autocorrelation functions are given in the next two slides.
3.5 Identifying an Appropriate Autoregressive Moving Average Model 3-39

Portfolio of Shapes MA(q) Model


ACF PACF/IACF

... ...

1 2 3 q 1 2 3 q

Drops to 0 after lag q Exponential Decay

continued...

64

Portfolio of Shapes MA(q) Model


ACF PACF/IACF

... ...

1 2 3 q 1 2 3 q

Drops to 0 after lag q Exponential Decay

65
3-40 Chapter 3 Advanced Forecast Models for Stationary Time Series

Identifying Moving Average Models

Select the Browse button next to the Data Set field.

Select the MA1 data set.

Select OK.
3.5 Identifying an Appropriate Autoregressive Moving Average Model 3-41

Select the View Series Graphically button. Select the Y series.

Select the Graph button. Select OK when the warning window appears.
3-42 Chapter 3 Advanced Forecast Models for Stationary Time Series

Select the Autocorrelations button. The following window appears.


3.5 Identifying an Appropriate Autoregressive Moving Average Model 3-43

The lag 1 spike in the ACF plot is significantly different from zero, while all others are not significant.
This pattern in the ACF indicates an MA(1) process. The exponential decay in both the PACF and IACF
is also consistent with an MA(1) process.
Select the back arrow to return to the Series Selection window. Select the MA2 data set and the Y series.
3-44 Chapter 3 Advanced Forecast Models for Stationary Time Series

Select the Graph button. The series plot appears.

Select the Autocorrelations button. Select OK when the warning window appears. The autocorrelation
plots appear.
3.5 Identifying an Appropriate Autoregressive Moving Average Model 3-45

The two significant spikes in the ACF are indicative of an MA(2) process. The exponential decay in the
PACF and IACF is consistent with an MA(2) process.
Select the back arrow to return to the series selection window. Select Close to return to the TSFS main
menu.
3-46 Chapter 3 Advanced Forecast Models for Stationary Time Series

Identifying an ARMA(p,q) Model


The ACF values are a combination of the MA
component and the AR component.
The PACF and IACF values are a combination of the
AR component and the MA component.
A step-by-step approach for considering reasonable
combination values for p and q will be outlined below.

67

Autocorrelation Plots for an ARMA(1,1)

68
3.5 Identifying an Appropriate Autoregressive Moving Average Model 3-47

Comments on Patterns for ARMA(1,1)


The first spike in the ACF plots is a combination of the
autocorrelation from the MA(1) term and exponential
decay from the AR(1) term.
The first spike in the PACF and IACF are a
combination of the AR(1) term and exponential decay
from the MA(1) term.
The higher-order spikes in the ACF are from
exponential decay from the AR(1) term.
The higher-order spikes in the PACF and IACF are
exponential decay from the MA(1) term.

69

Autocorrelation Plots for an ARMA(2,1)

70
3-48 Chapter 3 Advanced Forecast Models for Stationary Time Series

Comments on Patterns for ARMA(1,2)


The first two spikes in the ACF plots is a combination
of the autocorrelation from the MA(2) terms and
exponential decay from the AR(1) term.
The first spike in the PACF and IACF is a combination
of the AR(1) terms and exponential decay from the
MA(2) terms.
The higher-order spikes in the ACF are from
exponential decay from the AR(1) term.
The higher-order spikes in the PACF and IACF are
exponential decay from the MA(2) terms.

71

Autocorrelation Plots for an ARMA(1,2)

72
3.5 Identifying an Appropriate Autoregressive Moving Average Model 3-49

Comments on Patterns for ARMA(2,1)


The first spike in the ACF plots is a combination of the
autocorrelation from the MA(1) term and exponential
decay from the AR(2) terms.
The first two spikes in the PACF and IACF are a
combination of the AR(2) terms and exponential decay
from the MA(1) term.
The higher-order spikes in the ACF are from
exponential decay from the AR(2) terms.
The higher-order spikes in the PACF and IACF are
exponential decay from the MA(1) term.

73

ARMA(p,q) Model Selection in a Modern


Computing Environment
Appropriate for small and medium sized data sets.
Requires consistent use of appropriate fit statistics.
Assumes that no strong trend or seasonality are
in the series.

continued...

74
3-50 Chapter 3 Advanced Forecast Models for Stationary Time Series

ARMA(p,q) Model Selection in a Modern


Computing Environment
1 Assumes series is stationary.

2 Find q such that ACF(q) falls outside


confidence limits and ACF(k) falls inside
confidence limits for all k>q.

3 Find p such that PACF(p) falls outside


confidence limits and PACF(k) falls inside
confidence limits for all k>p.

continued...
75

ARMA(p,q) Model Selection in a Modern


Computing Environment
4 Determine all ordered pairs (j,k) such that
0jp and 0kq.

5 For each ordered pair (j,k) found in step 4,


fit an ARMA(j,k) model.

6 For all of the models fit in step 5, select


the model with the smallest values of
RMSE on the holdout sample or AIC or
SBC on the fit sample.

76
3.5 Identifying an Appropriate Autoregressive Moving Average Model 3-51

Identfying ARMA(p,q) Models

At the end of the previous demonstration, you returned to the TSFS Main Menu. It should appear as
below.

Select the Browse button beside the Data Set field. Select the GROCERIES data set.
3-52 Chapter 3 Advanced Forecast Models for Stationary Time Series

Notice that the time ID, DATE, is recognized with an interval of WEEK. These grocery series are weekly
data.
Select OK.

Select the View Series Graphically button, . Your window should appear as below.
3.5 Identifying an Appropriate Autoregressive Moving Average Model 3-53

Note that there are three series, different grocery items. The series variable names are SKU numbers.
The SAS labels identify which brand and product belong to the SKU number.
Select the toothpaste series.

Select the Graph button. A plot of the toothpaste series appears.


3-54 Chapter 3 Advanced Forecast Models for Stationary Time Series

There does not appear to be any strong trend or seasonality in the plot of the data.

Select the Autocorrelations button, . The following window appears.


3.5 Identifying an Appropriate Autoregressive Moving Average Model 3-55

Is this an MA(1) process or an AR(2) process? Using the guidelines provided prior to this demonstration,
the ACF suggest that the order of the MA component, q, is less than or equal to 1. The PACF suggest that
the order of the AR component, p, should be less than or equal to 1. The IACF suggest that p should be at
most 2. Consequently, you should fit ARMA(p,q) models with (p,q) = {(0,0) (0,1) (1,0) (1,1) (2,0) (2,1)}.
Proceed to identifying the peanut butter series. Select the back arrow and select the peanut butter series.

Select the Graph button.


3-56 Chapter 3 Advanced Forecast Models for Stationary Time Series

The series graph does not suggest any strong trend or seasonality.
Select the Autocorrelations button from the Time Series Viewer window.

The ACF suggest q of at most 1. The PACF suggest a p of at most one. The IACF suggest a p of at most
3. Consequently you should fit ARMA(p,q) models with (p,q) = {(0,0) (0,1) (0,2) (0,3) (1,0) (1,1) (1,2)
(1,3)}.
3.5 Identifying an Appropriate Autoregressive Moving Average Model 3-57

 The sine-wave pattern in the IACF may suggest a subset AR model with p=(1,3), versus a model
with p=(1,2,3). Fitting subset models in the TSFS will be discussed in a later chapter. The sine-
wave pattern may also arise from exponential decay from a second order MA model. With these
additional considerations, the list above is expanded by include (p,q) = {(2,0) (2,1) (2,2) (2,3)}.
Proceed to identifying the jelly series by selecting the back arrow and then selecting the jelly series in the
Series Selection window.

Select the Graph button.


3-58 Chapter 3 Advanced Forecast Models for Stationary Time Series

The series plot does not suggest strong trend or seasonality. Select the Autocorrelations button.

These plots suggest q of at most 1 and p of at most 2. Consequently, you should fit ARMA(p,q) models
with (p,q)={(0,0) (1,0) (2,0) (0,1) (1,1) (2,1)}.
3.5 Identifying an Appropriate Autoregressive Moving Average Model 3-59

Summary of Identification Demonstration


Toothpaste series
ACF implies q<=1, PACF suggest p<=1, IACF
suggest p<=2
Peanut butter series
ACF implies q<=1 PACF and IACF p<=1, IACF
suggest either p<=3, p=(1,3) or q=2 because of
sine-wave decay pattern.
Jelly series
ACF implies q<=1, PACF and IACF imply p<=2

78
3-60 Chapter 3 Advanced Forecast Models for Stationary Time Series

Exercises

1. The monthly lead production data stored in FETS.LEADPRD may be generated by a stationary
process. Identify an appropriate ARMA model for the monthly lead production data.
2. The monthly steel shipments data stored in FETS.STEEL may be generated by a stationary process.
Identify an appropriate ARMA model for this data.
3.6 Estimation and Forecasting Methods 3-61

3.6 Estimation and Forecasting Methods

Objectives
Estimate the candidate models identified in the
previous section.
Compare models using several fit statistics.
Choose the best model.
Generate forecast with the chosen model.
Write down the chosen model using the parameter
estimates produced by the TSFS.

81
3-62 Chapter 3 Advanced Forecast Models for Stationary Time Series

Estimating ARMA(p,q) Models

Recall that when you did the identifying demonstration for the toothpaste series, you concluded that
ARMA(p,q) models with (p,q) = {(0,0) (0,1) (1,0) (1,1) (2,0) (2,1)}should be considered. To fit these
models, you need to return to the TSFS main menu by selecting the back arrow and closing the Series
Selection window.

Select the Develop Models button.


3.6 Estimation and Forecasting Methods 3-63

Note that the jelly series is currently selected because it was the last series that was identified. To fit
models to the toothpaste series, several details are needed. First, select the toothpaste series by selecting
the Browse button next to the Series field.

Select OK.
Confirm that the evaluation criterion is the default, Root Mean Square Error, because you will use a
holdout sample to evaluate the models.
3-64 Chapter 3 Advanced Forecast Models for Stationary Time Series

How big of a holdout sample should you use? A rule-of-thumb is 25 percent. You can see from the Data
Range that there is one year of weekly data, 52 weeks, so a holdout sample of 13 weeks will be used.
Also note that the Fit Range and Evaluation Range are identical, indicating that no holdout sample is
specified
To specify the holdout sample, select the Set Ranges button.
3.6 Estimation and Forecasting Methods 3-65

Change the hold-out sample to 13 by typing in 13 in place of the 0 or by selecting 13 from the drop-down
window from the arrow next to the 0.

Note that the dates change for the Period of Fit and Period of Evaluation, reflecting the 13-week holdout
sample.
Select OK.
3-66 Chapter 3 Advanced Forecast Models for Stationary Time Series

The Develop Models window is now configured as desired.


To fit an ARIMA model, left-click in the white space of the Develop Models window and a pop-up
window will appear.

Select Fit ARIMA Model,,,. ARMA models are a special case of ARIMA models with d=0. ARIMA
models are discussed later in the course.
3.6 Estimation and Forecasting Methods 3-67

The ARIMA Model Specifications window appears. To fit an ARMA(0,1) change the value of Moving
Average to q=1.

Note the model name of MA(1) is created. Select OK. An ARMA(0,1) model is also denoted by an
MA(1).
3-68 Chapter 3 Advanced Forecast Models for Stationary Time Series

The MA(1) model was fit with an RMSE of 4.46 on the holdout sample.
Now fit an ARMA(1,0) by specifying p=1 in the ARIMA.

Select OK. The Develop Models windows reappears now and contains the AR(1) model.

Now fit the other models identified previously, ARMA(1,1), ARMA(2,0), and ARMA(2,1).
3.6 Estimation and Forecasting Methods 3-69

Based on the RMSE on the holdout sample, the MA(1) model is the best.
To examine the MA(1) model more fully, select the model by left-clicking on it.

Now select the View Selected Model Graphically button, , below the Browse button.
3-70 Chapter 3 Advanced Forecast Models for Stationary Time Series

A plot of the predicted values of the models and the original data is displayed.

Select the Prediction Errors button, . A plot of the residuals is displayed.


3.6 Estimation and Forecasting Methods 3-71

Select the Prediction Errors Autocorrelation button, .


3-72 Chapter 3 Advanced Forecast Models for Stationary Time Series

The autocorrelation plots of the residuals are displayed. Note that none of the spikes are significantly
different from zero. These plots confirm that the model explains all the significant autocorrelation that
was in the original data.

Select the Prediction Error test button, .


3.6 Estimation and Forecasting Methods 3-73

The white noise tests indicate that there is no significant autocorrelation in the residuals. The use of the
Unit Root test is discussed later in the course.

Select the Parameter Estimates button, .


3-74 Chapter 3 Advanced Forecast Models for Stationary Time Series

A table of the parameter estimates is displayed. The intercept is the mean, Mu, of the series. Note that
both parameters are significantly different from zero. Writing down the equation for the models using the
parameter estimates table is illustrated later in the course.

Select the Statistics of Fit button, .


3.6 Estimation and Forecasting Methods 3-75

To view the forecast for the MA(1) model, select the Forecast Graph button, .
Select the one step ahead forecast.
3-76 Chapter 3 Advanced Forecast Models for Stationary Time Series

A plot of the fitted model, the data, and the forecast and their 95 percent confidence bounds is displayed.
The one step ahead forecast is 220.24, slightly larger than the estimated mean of 218.78. The forecast for
two or more steps ahead are equal to the series mean of 217.18. In general, for an MA(q) model, the
forecast more than q time units into the future will be equal to the estimated mean of the series.

To view the forecast data set, select the Forecast Table button, .
3.6 Estimation and Forecasting Methods 3-77

To proceed to fitting models on the peanut butter series, select the back arrow. Select the Browse button
next to the Series field. Select the peanut butter series.
3-78 Chapter 3 Advanced Forecast Models for Stationary Time Series

Select OK.
3.6 Estimation and Forecasting Methods 3-79

Set the hold sample to 13 by selecting the Set Ranges button and changing the holdout sample to 13.
3-80 Chapter 3 Advanced Forecast Models for Stationary Time Series

Recall that during the identify phase you decided that ARMA(p,q) models with (p,q) = {(0,0) (0,1) (0,2)
(0,3) (1,0) (1,1) (1,2) (1,3)} should be fit. Fit these seven models and compare their RMSEs.
When attempting to fit the ARIMA(2,1) model, the following error notice appears.

There is not sufficient data to fit the specified model. The inability to fit some models that may seem like
good candidates is often a practical constraint for models to consider. The ARMA(1,3) model was also
not able to be estimated.
3.6 Estimation and Forecasting Methods 3-81

The results for the five models that were fit are displayed below.

The MA(1) model is best as measured by its RMSE on the holdout sample.
Recall that models that include two MA terms should be considered because of the sine-wave pattern
observed in the IACF. Try fitting an MA(2) model.
3-82 Chapter 3 Advanced Forecast Models for Stationary Time Series

The MA(2) model has the lowest RMSE.


It is often convenient to order the models by the displayed fit statistic. To do this, select the Sort Models
button, , from the top toolbar.
3.6 Estimation and Forecasting Methods 3-83

The models are listed from best to worst by their RMSEs on the holdout sample.
Evaluate the MA(2) models by examining the diagnostics graphs and statistics as done for the toothpaste
series. Compare the MA(2) models with the others of your choice.
Proceed to fitting the candidate models on the jelly series. Recall from the identify phase that you
determined that ARMA(p,q) models with (p,q)={(0,0) (1,0) (2,0) (0,1) (1,1) (2,1)} should be fit.

Select the Browse button beside the Series field. Select the jelly series.
3-84 Chapter 3 Advanced Forecast Models for Stationary Time Series

Select OK.
Specify a holdout sample of 13 as shown above. When completed, the window should appear as below.
3.6 Estimation and Forecasting Methods 3-85

Fit the candidate models. When completed the window should appear as below.

None of the candidate models that included an MA term could be fit.


The AR(2) model is the best as measured by RMSE on the holdout sample.
Evaluate the models by examining the diagnostics as shown before.
Below is the Forecast Plot for the AR(2) model.
3-86 Chapter 3 Advanced Forecast Models for Stationary Time Series

Notice that the behavior of a pure AR model forecast is different than the behavior of a pure MA model.
The forecast for a model with AR terms will, in general, not equal the mean of the series. The forecast,
however, will approach the series mean the further into the future the forecasts are produced.
Compare the forecast tables values with the series mean of 375.7. Select the Forecast Table button.
3.6 Estimation and Forecasting Methods 3-87
3-88 Chapter 3 Advanced Forecast Models for Stationary Time Series

Summary of Estimation Demonstration


Toothpaste series:
MA(1) model was best as measured by RMSE=4.46
on the holdout sample.
Peanut butter series:
MA(2) model was best as measured by RMSE=14.4
on the holdout sample.
Jelly series:
AR(2) model best as measured by RMSE=10.7 on the
holdout sample. Models with MA terms would not fit.

continued...

83

Summary of Estimation Demonstration


Toothpaste series: MA(1) model with holdout
Yt = 219 + t + 0.555 t 1
Peanut butter series: MA(2) model with holdout
Yt = 453 + t 0.566t 1 + 0.497t 2
Jelly series: AR(2) model with holdout

Yt 376 = 0.849(Yt 1 376)


0.518(Yt 2 376) + t
84
3.6 Estimation and Forecasting Methods 3-89

Produce Forecast Steps


Refit the best model on the entire data set.
Verify that the model parameters and forecast have
not changed substantially.
Check the box under the Forecast Model column in
the Develop Models window.
Open the Produce Forecast window, name the
forecast data set, and select the data set format and
forecast horizon.

85

Summary of Estimation Demonstration


Toothpaste series: MA(1) model on full data
Yt = 219 + t + 0.600 t 1
Peanut butter series: MA(2) model on full data
Yt = 454 + t 0.582 t 1 + 0.459 t 2
Jelly series: AR(2) model on full data

Yt 376 = 0.770(Yt 1 376)


0.525(Yt 2 376) + t

86
3-90 Chapter 3 Advanced Forecast Models for Stationary Time Series

Generate Forecast for the Grocery Series

After you have decided on the best function form of a forecast model using a holdout sample, it is
common practice to re-estimate the best model using the entire data set.
Return to the Develop Models window for the jelly series.

To use the entire data set to re-estimate the AR(2) model, the holdout sample size must be reset to 0.
Select the Set Ranges button and change the holdout sample from 13 to 0.
3.6 Estimation and Forecasting Methods 3-91

Select OK to return to the Develop Models window.


3-92 Chapter 3 Advanced Forecast Models for Stationary Time Series

To avoid changing the results of the model fit with the holdout sample, first duplicate the model.
With the AR(2) selected as shown above, right-click in the white space and the following window
appears. Select Duplicate Model.

There are now two models labeled AR(2).

Next, right-click to bring up the pop-up menu and select Edit Model.

The following window opens.


3.6 Estimation and Forecasting Methods 3-93

So that you can distinguish between the AR(2) models fit with and without the holdout sample, add Full
Data to the Model label.

Select OK and the model will be refit.


3-94 Chapter 3 Advanced Forecast Models for Stationary Time Series

The RMSE for the full-data model is smallest of the three. This is expected but will not always be the
case. Because the Full Data model RMSE is calculated on the same data set that was used to fit the model,
you would expect the RMSE to be smaller.
Note that the box under the Forecast Model is checked for the Full Data model. This indicates that when
forecasts are produced later in this demonstration, this is the model that will be used. Often, you will need
to manually check which model you want to use as the forecast model.
The Full Data model should be evaluated to ensure that its parameter estimates, residual diagnostics, and
forecast are consistent with the model fit with the holdout sample.
Select the View Selected Model Graphically button. A plot of the model and data appears.
3.6 Estimation and Forecasting Methods 3-95

The fit of the models is not noticeably different from the holdout sample model.
Select the Parameter Estimates button.

The parameter estimates have not changed substantially from the holdout sample model. The other
diagnostics information or the forecast have not changed substantially either. Consequently, the hold
sample model and the full data model are consistent, giving increased confidence that this model will
produce an accurate forecast.
3-96 Chapter 3 Advanced Forecast Models for Stationary Time Series

To refit the best model to toothpaste and peanut butter series on the full data, the above steps will need to
be performed for each series.
Select the Browse button and then select the toothpaste series.

Select OK and the Develop Models window appears.

Change the holdout sample to 0 using the Set Ranges button. Duplicate the MA(1) model. Edit the
MA(1) model by adding Full Data to the model label. When completed, the Develop Models window
appears, as below.
3.6 Estimation and Forecasting Methods 3-97

Note that the Full Data model is checked, so it will be used to produce the forecast later in the
demonstration.
Evaluation of the toothpaste holdout sample and full data models shows that they are consistent, giving
confidence in the chosen forecast model.
Repeat the above steps for the peanut butter series. When completed, the Develop Models window
appears, as below.

Note that the Full Data model is selected as the Forecast Model.
Evaluation of the peanut butter holdout sample and full data models shows that they are consistent, giving
confidence in the chosen forecast model.
Now that the final forecast models have been developed and assessed, they can be used to produce
forecast and the forecast saved in a data set.
To produce the forecast, return to the TSFS main menu by selecting the back arrow and closing the
Develop Models window.
3-98 Chapter 3 Advanced Forecast Models for Stationary Time Series

Select the Produce Forecasts button.

The Produce Forecasts window appears.


Note that the defaults are to forecast all series in the data set, save the forecast the SAS data set
work.forecast, use the simple format, and forecast 12 time periods in to the future.
3.6 Estimation and Forecasting Methods 3-99

If you want to only forecast a subset of the series, select the Select button next to the Series field,
and a window appears that allows you to selecting any subsets that are wanted. In this demonstration you
will forecast all three series. You will use the Interleaved output data set format, name the data set
work.Interleaved, and forecast only four weeks. If you want to save the forecast in a permanent
data set, you would need to change the work library to another library, for example FETS.

To change the format of the data set, select the arrow beside Format.

A pop-up menu appears with three choices. Select Interleaved. Change the name of the data set to
work.Interleaved. Change the Horizon to 4. When completed, the window should appear as
below.
3-100 Chapter 3 Advanced Forecast Models for Stationary Time Series

Select Run. A Note window will appear .

Select OK. The Output button will become ungrayed, which indicates that the data set is constructed and
available for view.
Select the Output button. A viewtable of the work.Interleaved data set will appear.

Note that there are multiple rows per date. The Type of Observation column indicates what information is
contained on that row. There is a separate column for each series forecast.
Scroll to the bottom of the table. The last four dates contain the forecast values and their upper and lower
95 percent confidence bounds for the four-week forecast horizon.
3.6 Estimation and Forecasting Methods 3-101

The other formats are illustrated in following slides.


3-102 Chapter 3 Advanced Forecast Models for Stationary Time Series

Forecast Data Sets: Simple Format

88

Forecast Data Sets: Interleaved Format

89
3.6 Estimation and Forecasting Methods 3-103

Forecast Data Sets: Concatenated Format

90

The Backshift Operator


The backshift operator Bk shifts a time series by k time
units.

Shift 1 time unit BYt = Yt 1


Shift 2 time units B2Yt = Yt 2

Shift k time units BkYt = Yt k

Backshift operator notation is a convenient way to write


ARMA models.

91
3-104 Chapter 3 Advanced Forecast Models for Stationary Time Series

An AR(1) Model Using Backshift Notation

Yt = 1 (Yt 1 ) + t

Yt 1 (Yt 1 ) = t

(1 1B)(Yt ) = t

92

An MA(1) Model Using Backshift Notation

Yt = t 1 t 1

Yt = (1 1B) t

93
3.6 Estimation and Forecasting Methods 3-105

An ARMA(1,1) Model Using Backshift Notation

(1 1B)(Yt ) =
(11B)t

94

An ARMA(p,q) Model Using Backshift Notation

(1 1 B... p B p )(Yt )
= (1 1 B... q B q ) t

95
3-106 Chapter 3 Advanced Forecast Models for Stationary Time Series

Peanut Butter ARMA(0,2) Model Using


Backshift Notation

Yt = 453.9 + t 0.5823 t 1 + 0.4586 t 2

Yt 453.9 = (1 0.5823B + 0.4586 B 2 ) t

96
3.6 Estimation and Forecasting Methods 3-107

Exercises

3. Estimate the parameters of an AR(1) model for the monthly lead production data. Express the model
using standard notation and using backshift notation.
4. Use the AR(1) model estimated in Exercise 3 to forecast the monthly lead production data 12 months
into the future.
3-108 Chapter 3 Advanced Forecast Models for Stationary Time Series

3.7 Chapter Summary


Box-Jenkins modeling methodology provides a framework for deriving good forecast models. The Box-
Jenkins ARMA models for stationary time series are backed by a powerful theory that guarantees the
existence of a good approximating model for any stationary series. The practical problem is how to
identify the orders of an ARMA model that best approximates the data.
Diagnostic functions provide strategies for determining orders p and q for an ARMA(p,q) model. The
autocorrelation function (ACF), partial autocorrelation function (PACF), and inverse autocorrelation
function (IACF) exhibit certain properties for various models. Experienced forecasters learn how to use
these functions to identify ARMA models. When ambiguities occur, a well-defined trial-and-error process
applied to a reduced set of models often leads to a good approximating ARMA model.
After a model has been identified, the parameters are estimated, and forecast equations are derived to
predict future values of the series. The Time Series Forecasting System (TSFS) supports the requirements
of Box-Jenkins time series methodology.

For Additional Information


Box, G.E.P., and Jenkins, G.M. (1976). Time Series Analysis: Forecasting and Control. Oakland,
California: Holden-Day.
Hamilton, James D. (1994). Time Series Analysis. Princeton, New Jersey: Princeton University Press.
3.8 Solutions to Exercises 3-109

3.8 Solutions to Exercises


1. Based on examination of the sample ACF, PACF, and IACF functions, an AR(1) model may be
appropriate for the monthly lead production data.
2. Based on examination of the ACF, PACF, and IACF, an AR(2) or an AR(3) model may be appropriate
for the steel shipment data. However, significant autocorrelation values at lag 12 suggest that the data
may have a seasonal component.
3. The estimated parameters are given in the following table.

The estimated model is

Yt 34231 = 0.62845(Yt 1 34231) + t .

The value labeled intercept in the table is actually the estimated mean. The actual intercept is

0 = (1 1 ) = 34231(1 0.62845) = 12718.5 .


Using backshift notation, the model is

(1 0.62845B)Yt = 12718.5 + t .
3-110 Chapter 3 Advanced Forecast Models for Stationary Time Series

4. The forecasts from the above model are given in the following table.
Chapter 4 Advanced Forecast
Models for Nonstationary Time Series

4.1 The Use of Differencing to Model Trend and Seasonality ..........................................4-3

4.2 Trend Models ................................................................................................................4-10

4.3 Seasonal Models ..........................................................................................................4-47

4.4 Chapter Summary.........................................................................................................4-85

4.5 Solutions to Exercises .................................................................................................4-86


4-2 Chapter 4 Advanced Forecast Models for Nonstationary Time Series
4.1 The Use of Differencing to Model Trend and Seasonality 4-3

4.1 The Use of Differencing to Model Trend and Seasonality

Objectives
Review stochastic trend and seasonal components.
Show how the TSFS supports differencing for
modeling trend and seasonality.

Modeling Nonstationary Time Series


Diagnose trend and seasonality.
Determine appropriate trend and/or seasonal
components to use for modeling.
Obtain the residuals (prediction errors) after applying
the trend and/or seasonal components.
Verify that the residuals appear to be stationary.
Use the methods of the previous chapter to determine
an appropriate ARMA model for the residual series.
Combine all model components to produce forecasts.

continued...

4
4-4 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

Modeling Nonstationary Time Series


Box-Jenkins time series models always use an ARMA
error component.
Box and Jenkins emphasize differencing to achieve
stationarity, but Box-Jenkins models accommodate
deterministic or stochastic trend and seasonal
components.
Correct specification of the ARMA structure of the
model can dramatically increase forecast accuracy.

Stochastic Trend Functions: Differencing


Random Walk:

Yt = Yt 1 + t
Random Walk with Drift:

Yt = + Yt 1 + t

continued...

6
4.1 The Use of Differencing to Model Trend and Seasonality 4-5

Stochastic Trend Functions: Differencing


Random Walk:

Yt Yt 1 = t
Yt = Yt Yt 1 First Difference

General Model with Stochastic Trend:

k Yt = SEASONALt + IRREGULARt
2Yt = Yt = (Yt Yt 1 ) = (Yt Yt 1 ) (Yt 1 Yt 2 )
k Yt k-th Difference

The order of a nonseasonal difference is rarely more than 2 and usually no more than 1.

Differencing Notation
Yt Yt 1 = t
Yt = t First Difference

(1 B)Yt = t Backshift Notation

k Yt = t k-th Difference

(1 B ) k Yt = t Backshift Notation

For a seasonal difference, k is rarely more than 1.


4-6 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

First Differences Turn Linear Trends into


Horizontal Lines
Yt-Yt-1=rise=rise/run=slope
Y rise

run=1

=Slope

1 2 3 4 5

9
t

Stochastic Seasonal Functions: Seasonal


Differencing
For seasonal data with period S, express the current
value as a function that includes the value S time units
in the past.
Yt=Yt-S+TRENDt+IRREGULARt.
SYt=Yt Yt-S , called a difference of order S.

Examples:
Monthly: This January is a function of last January and
so on.
Daily: This Sunday is a function of last Sunday and so
on.

10
4.1 The Use of Differencing to Model Trend and Seasonality 4-7

Differencing Notation
Yt Yt s = t
sYt = t Seasonal Difference

(1 B s )Yt = t Backshift Notation

ksYt = t k-th Seasonal Difference

(1 B s ) k Yt = t Backshift Notation

11

Differences of Order 12 Turn Sinusoids into


Horizontal Lines
Y2 Y26
Y14

Y3 Y15 Y27

12=0

12
4-8 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

Periodic Differences Turn Periodic Data into


Horizontal Lines
Yt Yt+k Yt+2k

k=0

13

Differencing Notation for Trend and


Seasonality
(1 B s )(1 B )Yt = t Backshift Notation

(1 B B s + B s +1 )Yt = t Polynomial Multiplication


Yt Yt 1 Yt s + Yt s 1 = t
Apply Backshift Operator

Yt = Yt 1 + Yt s Yt s 1 + t Model

Yt = Yt 1 + Yt s Yt s 1 Forecast Equation

14

The TSFS accommodates differencing in a number of ways. You can interactively investigate the use of
differencing by using the delta buttons in the time series diagnostic plots.
4.1 The Use of Differencing to Model Trend and Seasonality 4-9

Interactive Trend and Seasonal Differencing in


the TSFS
Difference Toggle: Off

Seasonal Difference Toggle: Off

continued...
15

Interactive Trend and Seasonal Differencing in


the TSFS
Difference Toggle: Off

Seasonal Difference Toggle: On

16

These diagnostics will be illustrated with a full Box-Jenkins analysis of time series data.
4-10 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

4.2 Trend Models

Objectives
Show how differencing and ARMA stationary models
can be combined to create ARIMA models for time
series with trend.
Show how an ARMA stationary component can be
combined with deterministic trend components.
Illustrate how the TSFS can be used to fit advanced
models with trend components.

18

The Box-Jenkins Trend Model


ARIMA=AutoRegressive Integrated Moving Average
Discrete Function: Difference
Continuous Function: Derivative
To undo a difference or derivative, you integrate, so an
ARMA model for a difference must be integrated to get
forecasts for the original data.

19
4.2 Trend Models 4-11

The Box-Jenkins Trend Model


ARIMA(p,d,q)
(1 1 B L p B p )(1 B) d Yt = 0 + (1 1 B L q B q ) t

ARIMA(2,1,1)

(1 1 B 2 B 2 )(1 B)Yt = 0 + (1 1 B) t

ARIMA(2,1,1)

Zt 1Zt 1 2 Zt 2 = 0 + t 1 t 1 ARMA(2,1) Component


Zt = Yt Yt 1 Difference Component

20

Box-Jenkins Methodology for the Trend Model


Identify

Yt Stationary?No

Zt = Yt Yt 1 Stationary?YesDiagnose d=1, p=1,


and q=1
Estimate
Estimate Using
Z t 1Z t 1 = 0 + t 1 t 1 Maximum Likelihood

Forecast

Zt = 0 +1Zt 1 1at 1, at = Yt Yt , Infinite Memory


Forecast Equations
Y = Y + Z
t t 1 t
21

In words, the infinite memory forecast for time t is the value of the series at time t-1 plus the predicted
difference between the series at time t and time t-1. The TSFS uses infinite memory forecast that are
much more complicated to calculate mathematically, however, they are known to be more accurate.
Newton, H.J., and Pagano, M. (1983).
4-12 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

Finite Memory Forecast Equation used by the TSFS.

Zt + h = 0 + h ,1Z n + h ,2 Z n 1 + L + h ,n Z1
Yt + h = Yt + h 1 + Zt + h
The weights are different for every different value of h. The calculation of the weights is usually
performed as a series of matrix calculations that involve the estimated parameters of the model. The
actual formulation is beyond the scope of the course. Consequently, attempting to duplicate the forecast
produced by the TSFS using the model and estimate parameters will not produce forecast that agree with
those produced by the TSFS.

Box-Jenkins Forecasting
The TSFS uses maximum likelihood estimation and
finite memory forecasting.
Finite memory forecasting uses the estimated model
to derive weights to be applied to the entire series, not
just the last max(p,q) values.
Infinite memory and finite memory forecasts tend to be
very similar, especially for long series.
Infinite memory forecasts are easily coded in a
spreadsheet application.
Finite memory forecasts are difficult to code in a
spreadsheet application.

22
4.2 Trend Models 4-13

Box-Jenkins Methodology for Time Series with


Trend
Identify step: determine (p,d,q) for an ARIMA(p,d,q)
model.
The value d=1 is analogous, but not equivalent to,
linear trend.
The value d=2 is analogous, but not equivalent to,
quadratic trend.
It is rare for d to be larger than 2.

23

Using the TSFS to Detect Trend


Difference Toggle: Off

continued...
24

As you have seen, the plot of the monthly lead production data appears to exhibit a quadratic trend, which
would suggest d=2. The difference toggle button only allows you to investigate d=1.
4-14 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

Using the TSFS to Detect Trend


Difference Toggle: On

continued...
25

After left-clicking on the difference button, first differencing is applied. This action appears to flatten out
the series.

Using the TSFS to Detect Trend


Difference Toggle: Off

continued...
26

Recall that a time series with a strong trend component will exhibit a slowly decaying ACF with many
significant lags. The ACF for the original series decays rapidly, but ACF(1) is relatively large compared to
other values.
4.2 Trend Models 4-15

Using the TSFS to Detect Trend


Difference Toggle: On

continued...
27

After applying first differences, ACF(1) is still significantly different than zero, but much smaller than
before.

Using the TSFS to Detect Trend


Difference Toggle: Off

continued...
28

The lag 5 Dickey-Fuller unit root test indicates that a first difference is appropriate. Other lag values of
the unit root test imply that no differencing is required.
4-16 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

Using the TSFS to Detect Trend


Difference Toggle: On

29

Applying first differencing produces results that indicate d is at most 1, because no trend remains after
differencing.
The identify step suggests the following candidate models: ARIMA(0,1,0), ARIMA(1,0,0),
ARIMA(0,0,1), ARIMA(1,0,1), ARIMA(1,1,0), ARIMA(0,1,1), and ARIMA(1,1,1). The following
demonstration steps through the modeling process.
4.2 Trend Models 4-17

Box-Jenkins Modeling of the Monthly Lead Production Data

Bring up the monthly lead production project.

The Develop Models window should resemble the following.


4-18 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

Left-click in the client area and select Fit ARIMA Model.

The ARIMA Model Specification window has input windows for you to specify (p,d,q) for an
ARIMA(p,d,q) model. Specifying p=1, d=0, and q=0 produces an AR(1)=ARIMA(1,0,0) model.
4.2 Trend Models 4-19

You can edit the model label as indicated above.

The results verify that your ARIMA(1,0,0) model is identical to the AR(1) model that was fit before.
4-20 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

In the above screen capture, you see that an MA(1)=ARIMA(0,0,1) model has been specified.

A random walk with drift is equivalent to an ARIMA(0,1,0) model with an intercept term.
You can systematically specify all of the models suggested by the diagnostic plots.
4.2 Trend Models 4-21

Unfortunately, the parameters of an ARIMA(1,1,1) model cannot be estimated with the TSFS. The log file
entry below indicates why.

Instability implies a near singularity, which would be the case if the MA estimate is near one. Iterations
tend to push estimates toward an unstable region. You could try to fit this model by using PROC ARIMA
and tweaking the model-fitting options. However, fitting problems are often caused because the model is
not appropriate for the data.
4-22 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

After all of the models that can be fit are produced, the results for RMSE appear in the Develop Models
window. If you click the sort icon, results are given from best to worst.

RMSE favors the stationary ARIMA(1,0,1) model.


4.2 Trend Models 4-23

MAPE agrees with RMSE for the best model, but it reorders some of the other models. For example, the
ARIMA(0,0,1) model drops from fifth place to ninth place.

The SBC reorders results as well and selects the AR(1)=ARIMA(1,0,0) model as the best. Thus, the
choice of best model is not robust and depends on the accuracy criterion you select. Because RMSE was
chosen for this project, you can start by examining the ARIMA(1,0,1) model.
4-24 Chapter 4 Advanced Forecast Models for Nonstationary Time Series
4.2 Trend Models 4-25

The residual plot looks acceptable, except that the last six prediction errors are negative.

The prediction errors exhibit no significant autocorrelation or partial autocorrelation values.


4-26 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

A null hypothesis of white noise is accepted for all displayed lags. Only lag 4 of the unit root test chart
suggests that a null hypothesis of a unit root cannot be rejected at the 1% level of significance.

The parameter estimate for the MA lag 1 term is not statistically significantly different from zero. This
fact alone is not sufficient to reject a model.
4.2 Trend Models 4-27

The statistics of fit are more easily interpreted in comparison with another model. MAPE can be
interpreted directly: the forecasts average a 9.9% error.
4-28 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

Because an ARIMA(1,0,1) model is a stationary model, forecasts converge to the series mean. With
respect to domain knowledge or face validity, you would have a difficult time selling this model if you
cannot explain why you are forecasting an upward trend for the next 12 months when you have just seen a
downward trend for the last six months.
The AR(1) model can be thought of as a backward elimination version of the ARIMA(1,0,1) model,
because the MA term was not significant.

Parameter estimates are significant.


4.2 Trend Models 4-29

Forecasts are similar to those for the ARIMA(1,0,1) model.


You should investigate the nonstationary models that are proposed and compare them to the stationary
models. The ARIMA(1,1,0) model uses a first difference and fits an AR(1) model to the residuals.
4-30 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

The residuals look a little better than those for the ARIMA(1,0,1) model.
4.2 Trend Models 4-31

The residuals appear to be uncorrelated.


4-32 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

The residuals pass white noise tests and unit root tests.

The AR(1) coefficient is significant at the 5% level, but not the 1% level. Significance of the intercept is
not important.
4.2 Trend Models 4-33

The forecasts pass a face validity test. In the absence of domain knowledge or without using leading
indicators, it is reasonable to expect the forecasts to continue a downward trend. However, you can see
that the trend has a shallower slope than the decline associated with the last few data points.
Because Box-Jenkins models are not forced to use differencing, you can try deterministic trend
components. The plot of the original data has a slight quadratic appearance, so a quadratic trend term is
warranted.
4-34 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

The autocorrelation plots for the residuals from the quadratic trend suggest an AR(1) model, although
ARMA(1,1) and MA(1) models should also be considered.
4.2 Trend Models 4-35

There is strong evidence that the prediction errors are stationary, but not uncorrelated.
4-36 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

The windows above and the one below show how to duplicate and edit a model.
4.2 Trend Models 4-37
4-38 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

The quadratic trend model is edited to add an AR(1) error component. The above smaller window opens
after selecting Set beside the Error Model field.

The model is labeled Quadratic Trend + AR(1). Select OK to fit the model.
4.2 Trend Models 4-39

The model seems to be competitive. Sort by RMSE.

The Quadratic Trend + AR(1) model (QTAR1) is the third best fitting model and the best fitting
nonstationary model among those that were tried.
4-40 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

Using MAPE, the QTAR1 is the best overall model.

SBC penalizes the QTAR1 model for having so many parameters, and under SBC the QTAR1 model is
ranked ninth.
4.2 Trend Models 4-41

A complete residual analysis uncovers no obvious problems.


4-42 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

There is a slightly significant result at lag 6, but no additional evidence supports there being any
correlation among the residuals.
4.2 Trend Models 4-43

The white noise tests and the unit root tests suggest that the residuals are white noise.

The quadratic trend term is not significant, but this does not disqualify the model.
4-44 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

You have seen the statistics of fit for several models and observed how the QTAR1 model is competitive
for all but SBC.

The QTAR1 model passes face validity just like the ARIMA(1,1,0) model. The forecasts continue the
downward trend seen at the end of the series.
4.2 Trend Models 4-45

The analysis of the monthly lead production data produces several models that cannot be disqualified.
With respect to face validity, the two nonstationary models, ARIMA(1,0,1) and QTAR1, seem most
reasonable. You may need additional help to decide which model to employ. In the absence of domain
knowledge, the QTAR1 model is best whether you use RMSE or MAPE. SBC picks the ARIMA(1,1,0)
model.
4-46 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

Exercises

1. Find an acceptable forecast model for the annual lead production data stored in FETS.LEADYR. Use
the SBC criterion to determine the best fitting model.
4.3 Seasonal Models 4-47

4.3 Seasonal Models

Objectives
Show how differencing and ARMA stationary models
can be combined to create ARIMA models for time
series with seasonality.
Show how an ARMA stationary component can be
combined with deterministic seasonal components.
Describe how to combine the trend and seasonal
components with an ARMA stationary component to
model data with trend and seasonality.
Illustrate how the TSFS can be used to fit advanced
models with trend and seasonal components.

33

The Box-Jenkins Seasonal Model


ARIMA(p,d,q)(P,D,Q)S
The p, d, and q are the orders of the nonseasonal terms
of the model.
P is the order of the seasonal autoregressive terms.
Q is the order of the seasonal moving average terms.
D is the order of the seasonal difference.
S the length of the seasonal period.

ARIMA(0,0,0)(1,1,1)12

(1 1 B12 )(1 B12 )Yt = 0 + (1 1 B12 ) t


continued...

34
4-48 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

The Box-Jenkins Seasonal Model


ARIMA(1,1,1)(1,1,1)12

(1 1 B1 )(1 1 B12 )(1 B12 )(1 B1 )Yt


= 0 + (1 1 B1 )(1 1 B12 ) t
or equivalently

Z t 1Z t 1 1Z t 12 + 11Z t 13
= 0 + t 1 t 1 + 11 t 13
where
Z t = Yt Yt 1 Yt 12 + Yt 13
35

The general equation for the ARIMA(p,d,q)(P,D,Q)s is given by

(1 1,1 B L 1, p B p )(1 2,1 B s 2,2 B 2 s L 2, P B Ps )(1 B ) d (1 B s ) D Yt


= 0 + (1 1,1 B L 1,q B q )(1 2,1 B s L 2,Q B Qs ) t

This equation uses two subscripts to distinguish between the nonseasonal and seasonal terms. The first
subscript denotes the factor. The first subscript=1 denotes the first factor, the nonseasonal component. The
first subscript = 2 denotes the second factor, the seasonal component. The second subscript denotes the
order of the lag term related to the coefficient. The slide above uses upper case to denote the seasonal
coefficients versus lower case for the nonseasonal component.

The ARIMA(p,d,q)(P,D,Q)s is sometimes written in shorthand notation as

( B ) ( B ) (1 B ) d (1 B s ) D Y t = 0 + ( B ) ( B ) t
where the lower case factors represent the nonseasonal components and the uppercase factors represent
the seasonal components.
4.3 Seasonal Models 4-49

Box-Jenkins Methodology for the Seasonal


Model
Identify

Determine (p,d,q)(P,D,Q)

Estimate

Estimate Using Maximum Likelihood

Forecast

Forecast Using Infinite Memory Forecasting


36

Using the TSFS to Detect Trend and


Seasonality
Difference Toggle: Off

Seasonal Difference Toggle: Off

continued...
37
4-50 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

Using the TSFS to Detect Trend and


Seasonality
Difference Toggle: On

Seasonal Difference Toggle: Off

continued...
38

Using the TSFS to Detect Trend and


Seasonality
Difference Toggle: On

Seasonal Difference Toggle: On

continued...
39
4.3 Seasonal Models 4-51

Using the TSFS to Detect Trend and


Seasonality
Difference Toggle: Off

Seasonal Difference Toggle: On

40
4-52 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

Forecasting the Airline Passengers Data, 1994-1998


.
A new project is created in the TSFS to analyze the airline data.

Click on Develop Models and the following window appears.


4.3 Seasonal Models 4-53

Passengers is the target series to forecast.

Click the Set Ranges button that is next to the Evaluation Range field.
4-54 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

The airline data is 48 months in length, and the trend and seasonal components seem consistent
throughout the time range. Therefore, a holdout sample of 12 months is employed for model assessment.

Typing or selecting 12 months in the Hold-out Sample input window is sufficient to hold out the 1998
data.
4.3 Seasonal Models 4-55

You have already examined the time series plot of the Passengers data to make your decision about a
holdout sample. You revisit the plot to begin to assess what kind of model components will be used.

The time series exhibit a positive linear trend and a seasonal cycle of 12 months.
4-56 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

The autocorrelation plots suggest a periodicity of 12, because spikes appear at lag 12 for all three plots.
However, the presence of trend and seasonality combined may make it difficult to assess each component
individually. As suggested before, the first difference and seasonal difference toggle buttons are
employed.
4.3 Seasonal Models 4-57

Evidence of a seasonal component with a 12-month period becomes stronger in the ACF plot when first
differencing is used to remove the trend effect.

When trend and seasonality are accounted for by differencing, the autocorrelation plots suggest an MA(1)
model for the irregular or error component. An AR(2) model is also implied. Using the strategy developed
before for diagnosing ARMA models, you should investigate the following models for the irregular
component: AR(2), MA(1), AR(1), ARMA(2,1), ARMA(1,1). If differencing is employed to model trend
and seasonality, the following models should be investigated: ARIMA(0,1,0)(0,1,0)12,
ARIMA(2,1,0)(0,1,0)12, ARIMA(0,1,1)(0,1,0)12, ARIMA(1,1,0)(0,1,0)12, ARIMA(2,1,1)(0,1,0)12, and
ARIMA(1,1,1)(0,1,0)12. You should also consider variations with and without an intercept term. A log
transformation may also be warranted.
4-58 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

When you turn off the first difference, you seem to be left with uncorrelated errors. However, the unit root
tests shown later will suggest that trend is still present in the error component.

The original time series is clearly not white noise, and the unit root tests indicate the presence of trend and
seasonal components.
4.3 Seasonal Models 4-59

Applying a first difference alone is insufficient to produce a white noise error term.

After applying a first difference and a seasonal difference, the unit root tests suggest that the error
component is stationary, but the white noise tests clearly indicate the presence of autocorrelation.
4-60 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

As shown above, the unit root tests indicate the presence of trend when only a seasonal difference is
applied.
Using the default RMSE criterion, have the TSFS select a model automatically from the default list of 82
models.

The heuristic diagnostics determine that trend and seasonal components are necessary, and that a log
transformation may be warranted.
4.3 Seasonal Models 4-61

The best model based on RMSE is the Log Winters additive model. Change the selection criteria to
MAPE, and request another automatic model selection.
4-62 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

The best model chosen from the list of 82 models based on MAPE is the Winters multiplicative model.

Finally, change the selection criterion to SBC. This criterion will be used for the remainder of the
analysis.
4.3 Seasonal Models 4-63

The best model based on SBC is the log ARIMA(0,1,1)(1,0,0)12 without an intercept term. If you examine
the estimates associated with this model, you will see that the AR lag 12 coefficient is 0.95145, which is
almost one. A value of one would imply seasonal differencing. Because the list of 82 models does not
include the models suggested above, further investigation is warranted. First, sort the results by SBC
value.

You can systematically fit the proposed models using the Fit ARIMA Model option.
4-64 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

The ARIMA Model Specification window appears.


4.3 Seasonal Models 4-65

You can begin by specifying a model that is equivalent to activating both delta toggle buttons.

The model that consists only of a first difference and a difference of order 12 has a lower SBC value than
the three models already selected.
4-66 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

The autocorrelation plots are identical to those seen before when both difference buttons were chosen.

The white noise tests and unit root tests are the same as before. Consequently, the proposed candidate
models have not changed. You can systematically create each model using the Fit ARIMA Model
option.
4.3 Seasonal Models 4-67

The model list, sorted by SBC value, is given above. Some models could not be fit to the data, as the
following screen captures suggest.
4-68 Chapter 4 Advanced Forecast Models for Nonstationary Time Series
4.3 Seasonal Models 4-69

While any one of the above models may be appropriate, the TSFS does not permit adjustment of
optimization options to try to achieve a successful fit. You can solve the model fitting problem
programmatically by using PROC ARIMA in a SAS program.
You can investigate the leading contenders, but it is rarely necessary to perform a complete residual
analysis of all models that are tried.

The best model based on SBC produces residuals that appear to be random except for a run of negative
values near the beginning. Runs near the beginning of a series may be caused by start-up values and are
usually unimportant.
4-70 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

Only the PACF(12) value is significant. This could be a spurious result.

The white noise tests imply uncorrelated residuals. Unit root tests indicate stationarity, at least at the 5%
level of significance.
4.3 Seasonal Models 4-71

The lone MA(1) coefficient estimated from the data is highly significant.

MAPE indicates an average error of about 1.80%. The evaluation range reminds you that the coefficient
was estimated using the entire time series, not just the first 36 months.
4-72 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

The forecasts pass face validity checking. The presence of trend and seasonality produces tight 95%
prediction limits.

Zooming in on the extrapolated predictions allows you to get a better view of the results.
4.3 Seasonal Models 4-73

The next best model based on SBC is the same as the best model, except there is no log transformation. A
residual analysis fails to disqualify this model as well.
4-74 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

Residuals appear to be from a white noise process.

The MA(1) parameter estimate is highly significant.


4.3 Seasonal Models 4-75

MAPE is about 1.86%.

The extrapolated forecasts pass visual inspection.


You have already seen that the ARIMA(0,1,0)(0,1,0)12 model is disqualified because the residuals are
clearly not white noise. The plots are reproduced here for completeness.
4-76 Chapter 4 Advanced Forecast Models for Nonstationary Time Series
4.3 Seasonal Models 4-77

The model that finishes with the fourth best SBC value fails inspection and is disqualified, as the
following plots reveal.
4-78 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

Evidence suggests that the residuals are not white noise. Because none of the white noise test results are
highly significant, you may accept this model if no better model can be found.

The AR(1) parameter estimate is significant at the 5% level, but not at the 1% level. This fact alone is
insufficient to disqualify the model.
4.3 Seasonal Models 4-79

The last two windows reveal no obvious problems with the model. The forecasts pass visual inspection as
being reasonable. The primary reason for disqualifying this model is that some of the white noise tests
reject the null hypothesis of white noise at the 5% level of significance.
The TSFS provides a tool for comparing model accuracy diagnostics head-to-head. Select Tools
Compare Models.
4-80 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

The following window appears with the first two models pre-selected.

Model 1 is best based on all six displayed criteria. Of course, model selection is not based on polling
criteria. If everything else is similar, you have already determined that SBC will be used to select the best
model. The value of this model comparison is to show that choice of model is robust against selection of
accuracy criterion.
4.3 Seasonal Models 4-81

Comparing the best model to the fourth best model produces the same results. Because you have already
disqualified model 2 listed above, this display is for illustration only.
Ensure that the Forecast Model check box has selected the best model based on SBC. Then exit the
Develop Models window and select Produce Forecasts. The Produce Forecasts window appears.

Specify the format Concatenated, and make sure that a horizon of 12 months is chosen. Select Run. The
following window appears to ensure that you have selected the correct number of series to forecast.
4-82 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

Select OK.

Select Output.
4.3 Seasonal Models 4-83

A viewtable appears to display the forecast data. This data is stored in a temporary SAS table named
WORK.FORECAST. If you are satisfied with the results, you can add the table to a database, export it to a
spreadsheet, or perform any number of other tasks supported by SAS data engines.
4-84 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

Exercises

2. Continue the analysis of the Department of Transportation Airline Data, 1994-1998. Investigate
alternatives to differencing to model trend and seasonality. In particular, investigate the use of
seasonal dummy variables to model seasonality. Use SBC as the model selection criterion.
4.4 Chapter Summary 4-85

4.4 Chapter Summary


Box-Jenkins time series analysis promotes the use of differencing to model trend and seasonality. The
general Box-Jenkins ARIMA(p,d,q)(P,D,Q)s model can be employed to forecast nonstationary time series
using stochastic trend and seasonal components.
The Box-Jenkins methodology developed in a previous chapter is expanded to include identification of
first difference order d and seasonal orders (P,D,Q). The estimation and forecasting steps include a step to
convert a series to stationarity, estimate the stationary component, and then integrate back to the original
series.
Despite the emphasis on differencing, the methodology accommodates deterministic trend and seasonal
components as well as stochastic ones.

For Additional Information


Akaike, H. (1974), A New Look at the Statistical Model Identification, IEEE Transaction on Automatic
Control, AC-19, 716-723.
Bowerman, B.L., and OConnell, R.T. (1993), Forecasting and Time Series: An Applied Approach, Third
Edition, Belmont, California: Duxbury Press.
Box, G.E.P., and Jenkins, G.M. (1976), Time Series Analysis: Forecasting and Control, Revised Edition,
San Francisco: Holden-Day.
Brocklebank, J.C., and Dickey, D.A. (2003), SAS System for Forecasting Time Series, Second Edition,
Cary, North Carolina: SAS Institute Inc.
Chatfield, C. (1980), Inverse Autocorrelations, JRSS A, A142, 363-377.
Chatfield, C., and Prothero, D.L. (1973), "Box-Jenkins Seasonal Forecasting: Problems in a Case Study,"
JRSS A, 136, 295-336.
Dickey, D.A., and Fuller, W.A. (1979), Distribution of the Estimators for Autoregressive Time Series
with a Unit Root, JASA, 74, 427-431.
Jones, R.H. (1980), Maximum Likelihood Fitting of ARMA Models to Time Series with Missing
Observations, Technometrics, 22, 389-396.
Newton, H.J., and Pagano, M. (1983), The Finite Memory Prediction of Covariance Stationary Time
Series, SIAM Journal of Scientific and Statistical Computing, 4, 330-339.
Schwarz, G. (1978), Estimating the Dimension of a Model, Annals of Statistics, 6, 461-464.
4-86 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

4.5 Solutions to Exercises


1. The annual lead production project was created previously.

Five deterministic trend models were fit to the series. You can investigate Box-Jenkins trend models
in several ways. In the following, SBC was selected as the accuracy criterion, and automatic model
fitting was selected to get a candidate first model.
4.5 Solutions to Exercises 4-87

The heuristic diagnostics indicate that trend is present in the series.


4-88 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

The log random walk with drift model is superior to the deterministic trend models based on SBC.

An autocorrelation plot of residuals suggests an AR(1) model, and MA(1) model, or an ARMA(1,1)
model for the residual series.
4.5 Solutions to Exercises 4-89

The white noise tests and unit root tests support adding a stationary ARMA model.

You can use the duplicate feature to make it easier to modify an existing model.
4-90 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

Select Edit Model to modify the duplicated model.

Your solution can add models in any order, but in this solution, an AR(1) error term is tried first.
4.5 Solutions to Exercises 4-91

Based on SBC, this is the best model so far. A residual analysis will provide evidence to keep or
disqualify the model.
4-92 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

The residual plot seems okay.

The autocorrelations indicate uncorrelated residuals.


4.5 Solutions to Exercises 4-93

The residuals appear to be white noise.

The AR(1) parameter estimate is significant at the 5% level but not at the 1% level.
4-94 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

An MAPE value of about 8.07% seems satisfactory. Other measures mean nothing without a
comparison model.

The forecasts look reasonable.


4.5 Solutions to Exercises 4-95

The log IAR(1,1) model was renamed Log ARIMA(1,1,0) in the above window to be consistent with
the course notation. You can see from the above sorted table that the Log ARIMA(0,1,1) model has
the smallest SBC value. This model passes a residual analysis. The only possible source of
disqualification is one of the unit root tests given in the following plot.

Because there is no other evidence of nonstationarity in the residuals, the above lag 2 result is
classified as spurious.
Some models could not be fit to the data, as the following window indicates.
4-96 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

The Log ARIMA(0,1,1) model is selected as the forecast model based on its SBC value.
2. At the end of the section, the develop models window for this problem appeared as below.

To add deterministic terms, use the Fit ARIMA Model option, and select the Add button to add
deterministic components.
4.5 Solutions to Exercises 4-97

In the above window, a linear trend and seasonal dummy regressors have been added.

The SBC value does not look promising, but modeling the stationary error term may improve
accuracy.
4-98 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

Analysis of residuals suggests the following error models: AR(1), MA(1), ARMA(1,1).

The unit root tests suggest that the residuals are not stationary. You should try the above models
before deciding whether additional trend components should be added.
4.5 Solutions to Exercises 4-99

The AR(1) error model is tried first.

The residuals for this model look okay.


4-100 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

The above plot and the following plot provide evidence that the residuals are white noise.
4.5 Solutions to Exercises 4-101

Even though p-values are not published for this model, you can see that some of the t-statistics are
less than 2, which provides a rough approximation that the estimates are not significant at the 5%
level.
4-102 Chapter 4 Advanced Forecast Models for Nonstationary Time Series

The forecasts seem reasonable.

The final model display shows that the models with deterministic trend and seasonal components are
not very competitive. You can try combinations of deterministic and stochastic components to see if
you can find a better model.
4.5 Solutions to Exercises 4-103

Head-to-head comparisons show that the model with stochastic trend and seasonality is uniformly
superior to the model with deterministic trend and seasonality based on the six accuracy measures
selected.
4-104 Chapter 4 Advanced Forecast Models for Nonstationary Time Series
Chapter 5 Forecast Models with
Explanatory Variables

5.1 Ordinary Regression Models.........................................................................................5-3

5.2 Event Models ................................................................................................................5-14

5.3 Time Series Regression Models..................................................................................5-57

5.4 Chapter Summary.........................................................................................................5-82

5.5 Solutions to Exercises .................................................................................................5-83


5-2 Chapter 5 Forecast Models with Explanatory Variables
5.1 Ordinary Regression Models 5-3

5.1 Ordinary Regression Models

Objectives
Explain multiple linear regression models.
Examine linear regression assumptions.
Explain the relationship between ordinary multiple
linear regression models and time series regression
models.

A brief review of ordinary multiple regression will help frame the discussion of time series regression.

Multiple Linear Regression with Two Variables


Y = 0 + 1 X 1 + 2 X 2 +
Y is the response or dependent variable.
X 1 and X 2 are input or predictor variables.

is the error term.

0 , 1 and 2 are parameters.


0 is the intercept or constant term.
1 and 2 are partial regression coefficients.
4
5-4 Chapter 5 Forecast Models with Explanatory Variables

Multiple Linear Regression


Assumptions
The predictor variables are known and measured
without error.
The functional relationship between inputs and target
is linear.
The error term represents a set of random variables
that are independent and identically distributed with a
Gaussian normal distribution having mean 0 and
variance 2.

Violation of Model Assumptions


Normalityaffects standard errors, and might or might
not affect the parameter estimates
Constant Variancedoes not affect the parameter
estimates, but the standard errors are compromised
Independent observationsdo not affect the
parameter estimates, but the standard errors are
compromised
Linearityindicates a misspecified model, and
therefore the results are not meaningful

If standard errors are improperly estimated, then inferences may be invalid.


5.1 Ordinary Regression Models 5-5

Picturing the Model No Relationship


Y

* * *

*
*
0 *
* *
*
* X1

X2

Picturing the Model A Linear Relationship


Y
*
* * *
* * *
* *
* *

*
*
* **
* X1

X2

For two inputs, the regression surface is a plane. In more than three dimensions, the surface is known as a
hyperplane.
5-6 Chapter 5 Forecast Models with Explanatory Variables

The Multiple Linear Regression Model


In general, you model the dependent variable Y as a
linear function of k independent variables (the Xs) as

Y = 0 + 1 X 1 + ... + k X k +
The relationship is linear in the parameters.
Transformations of target and inputs are supported by the
model. For example,

log(Y ) = 0 + 1 X1 + 2 X12 + 3 log( X 2 ) +

continued...

When inputs are allowed to enter through polynomials or transcendental functions, the regression surface
is more complex than a simple hyperplane. Thus, regression models can be quite flexible.

The Multiple Linear Regression Model


Partial t - tests

Null Hypothesis : i = 0
Alternative Hypothesis : i 0
Test Statistic : t = / s ( )
i i

continued...

10

While this course primarily focuses on prediction, regression models are often used to make inferences
about causal relationships.
5.1 Ordinary Regression Models 5-7

The Multiple Linear Regression Model


Identification
Determine what inputs are correlated with the target.

An input can be correlated with the target and be


redundant.
An input can be correlated with the target through a
relationship with one or more other inputs.
Determine an appropriate relationship between inputs
and target.
Estimation
Least Squares Maximum Likelihood

Forecasting
Infinite memory finite memory because the model
has no memory of the past.
continued...
11

As you transition to time series regression, you should translate the regression methodology to the Box-
Jenkins framework.

The Multiple Linear Regression Model


Problems and Diagnostics
Identification
Variable selection

Forward selection
Stepwise selection
Others
Estimation
Multicollinearity: eigenvalues of XX, VIF

Influential observations: studentized residuals,


DFFITS, DFBETAS, Cooks D, leave-one-out statistics
Autocorrelation: Durbin-Watson

Nonconstant variance: diagnostic plots

12
5-8 Chapter 5 Forecast Models with Explanatory Variables

From Ordinary Regression to Time Series


Regression
The time series regression model is an extension of the
ordinary regression model in which
variables are observed in time

autocorrelation is allowed

the target variable can be influenced by past values of


inputs.

13

Time Series Regression Terminology


Ordinary regressor
An input variable that only has a concurrent influence
on the target variable: X at time t is correlated with Y
at time t, X at times before t is uncorrelated with Y at
time t.
Dynamic regressor
An input variable that influences the target variable at
current and past values: X at times t, t-1, t-2, ,
influences Y at time t.
Transfer Function
A function that provides the mathematical relationship
between a dynamic regressor and the target variable.

14
5.1 Ordinary Regression Models 5-9

Time Series Regression


Multiple Regression
Y = 0 + 1 X 1 + ... + k X k +
Time Series Regression with Ordinary Regressors
Yt = 0 + 1 X 1t + ... + k X kt + t
Time Series Regression with Dynamic Regressors
Yt = 0 + 10 X 1,t + 11 X 1,t 1 + L + 1m1 X 1,t m1
+ 20 X 2,t + 2,t X 2,t 1 + L + 2 m2 X 2,t m2
+L
+ k 0 X k ,t + k1 X k ,t 1 + L + kmk X k ,t mk + t
15

The dynamic regressors above are portrayed as simple coefficients applied to shifted inputs. A more
general rational function approach will be employed to reduce model degrees of freedom.

Coefficients Transfer Functions


Ordinary Regression Time Series Regression

( B)
X 1,t 1 Yt X 1,t Yt
( B)

Transfer Functions

16
5-10 Chapter 5 Forecast Models with Explanatory Variables

The General Rational Transfer Function


( B)
X i ,t i Yt ,
i ( B)
i ( B) = i 0 i1 B L im B m , i
i

i ( B) = 1 i1 B L ih B h i
i

i ( B )
= i 0 i1 B i 2 B 2 L ik B k L
i ( B)

Truncation Point i,k+1 < Tolerance


continued...

17

The General Rational Transfer Function


Motivation
The ratio of the numerator and denominator
polynomials is an infinite order polynomial that
accommodates a finite order approximation.
A ratio of polynomials will require fewer parameters to
model the input than a pure numerator polynomial
alone (k>>h+m+1).
The length of time series in the dynamic regression
problem prevents estimating many parameters.
The rational transfer function helps solve the problem
of limited data.

18
5.1 Ordinary Regression Models 5-11

The Time Series Regression Error Term


The error term is a stationary Gaussian process.
The distribution of the error term is approximated by
an ARMA(p,q) model.
Proper specification of the error model is necessary to
obtain the most accurate forecasts.

19

While much emphasis has been placed on stationary ARMA models, you saw that stationary ARMA
models typically have short memory and produce forecasts that converge to the series mean. Time series
regression models can have long memory to produce accurate forecasts farther into the future, and this
can be achieved with short memory error components.

Types of RegressorsMeasurement Scale


Binary (dummy) variables
Take the value zero or one

Can be used to quantify nominal data

Categorical variables
Nominal scaled nonquantitative categories

Ordinal scaled variables may be treated as categorical

Must be coded into a quantitative input, usually using


a form of dummy coding for each level (less one if a
constant term is used in the model)
Quantitative variables
Interval or ratio scaled

Can be transformed
continued...

20
5-12 Chapter 5 Forecast Models with Explanatory Variables

Types of RegressorsRandomness
Deterministic
Controlled by experimenter, or

Can be perfectly predicted without error

Stochastic
Governed by unknown probability distributions

Cannot be perfectly predicted

continued...

21

Types of Regressors
Deterministic examples
Dummy coding for holiday events

Settings on a machine, for example, electric current,


temperature, and pressure on production equipment
Intervention weights, for example, saturation for
legislation that is phased in uniformly by month over a
year: 1/12, 2/12, 3/12,,12/12.
Advertising expenditures
(These may be treated as stochastic when decisions
are influenced by stochastic factors, such as market
share, promotions by competitors, and so on.)

continued...

22
5.1 Ordinary Regression Models 5-13

Types of Regressors
Stochastic examples
Ambient outside air temperature

Competitor sales

Interest rates

Consumer price index

Unemployment rate

Rate per 1000 households of television viewership

Stock market indices

23

In the next few sections, the extensions discussed in this section are expanded and illustrated by models
fit to data using the TSFS.
5-14 Chapter 5 Forecast Models with Explanatory Variables

5.2 Event Models

Objectives
Review events and event modeling.
Review types of event (intervention) effects.
Show how to use the TSFS for event modeling.

25

The event models discussed in this section extend those discussed before by (1) adding stationary ARMA
error components and (2) adding mathematics to support the rational transfer functions illustrated before
by TSFS options rather than formulas.
5.2 Event Models 5-15

The following slides review the previous material on events.

Events
An event is anything that changes the underlying
process that generates time series data.
The analysis of events includes two activities:
Exploration to identify the functional form of the
effect of the event
Inference to determine if the event has a
statistically significant effect
Other names for the analysis of events:
Intervention analysisname used by TSFS
Interrupted time series analysis

26

Primary Event Variables


0 for t tevent
Point/Pulse Jt =
1 for t = tevent

0 for t < tevent


Step It =
1 for t tevent

0 for t < tevent


Ramp Rt =
t tevent for t tevent
tevent

27
5-16 Chapter 5 Forecast Models with Explanatory Variables

Abrupt, Temporary Effect

Type: Point
Decay Pattern: Exp

Event
Effect 5 Time Units Later continued...
28

You can now frame the discussion of intervention effects in terms of the general Box-Jenkins regression
model.

Regression Model for an Abrupt, Temporary


Effect
( B)
Yt = 0 + J t + Zt Dynamic Regression Model
( B)
( B) Z t = ( B) t ARMA(p,q) Error Term

continued...

29
5.2 Event Models 5-17

The General Rational Transfer Function


( B)
X i ,t i Yt ,
i ( B)
i ( B) = i 0 i1 B L im B m , i
i

i ( B) = 1 i1 B L ih B h i
i

i ( B )
= i 0 i1 B i 2 B 2 L ik B k L
i ( B)

Truncation Point i,k+1 < Tolerance

30

Abrupt, Temporary Effect Example Transfer


Function
( B) 1 Numerator Order = 0
=
( B ) 1 0 .4 B Denominator Order = 1
= 1 + 0.4 B + 0.16 B 2 + 0.064 B 3 + 0.0256 B 4 + 0.01024 B 5 + 0.004096 B 6 + L

Truncate for Tolerance = 0.01

continued...

31
5-18 Chapter 5 Forecast Models with Explanatory Variables

Abrupt, Temporary Effect Example Transfer


Function
Time Since Event Effect of Event
k Weights -1 0 1 2 3 4 5 6 at Time t:
0 1.00000 0 1 0 0 0 0 0 0 kJt
1 0.40000 0 0 1 0 0 0 0 0 -1 0.00000
2 0.16000 0 0 0 1 0 0 0 0 0 1.00000
3 0.06400 0 0 0 0 1 0 0 0 1 0.40000
4 0.02560 0 0 0 0 0 1 0 0 2 0.16000
5 0.01024 0 0 0 0 0 0 1 0 3 0.06400
Value of Point 4 0.02560
Function Jt 5 0.01024
6 0.00000
continued...
32

Abrupt, Temporary Effect Example Transfer


Function

Event

Effect 5 Time Units Later

continued...

33
5.2 Event Models 5-19

Abrupt, Temporary Effect Example Transfer


Function
Result:

Six coefficients at the cost of two estimated parameters!

0 = 1, 1 = 0.4

34

Abrupt, Permanent Effect

Type: Step
Decay Pattern: None

Event Effect 5 Time Units Later continued...


35
5-20 Chapter 5 Forecast Models with Explanatory Variables

Regression Model for an Abrupt, Permanent


Effect
Yt = 0 + 0 I t + Z t Ordinary Regression Model

( B) Z t = ( B) t ARMA(p,q) Error Term

36

The abrupt, permanent effect requires no discussion because the transfer function is a simple coefficient.

Gradual, Permanent Effect

Type: Step
Decay Pattern: Exp

continued...
Event Effect 5 Time Units Later
37
5.2 Event Models 5-21

Regression Model for a Gradual, Permanent


Effect
( B)
Yt = 0 + It + Zt Dynamic Regression Model
( B)
( B) Z t = ( B ) t ARMA(p,q) Error Term

continued...

38

Gradual, Permanent Effect Example Transfer


Function
Time Since Event Effect of Event
k Weights -1 0 1 2 3 4 5 6 at Time t:
0 1.00000 0 1 1 1 1 1 1 1 kIt
1 0.40000 0 0 1 1 1 1 1 1 -1 0.00000
2 0.16000 0 0 0 1 1 1 1 1 0 1.00000
3 0.06400 0 0 0 0 1 1 1 1 1 1.40000
4 0.02560 0 0 0 0 0 1 1 1 2 1.56000
5 0.01024 0 0 0 0 0 0 1 1 3 1.62400
Value of Step 4 1.64960
Function It 5 1.65984
6 1.65984
continued...
39
5-22 Chapter 5 Forecast Models with Explanatory Variables

Gradual, Permanent Effect Example Transfer


Function

40

Custom Model Specification

Add Interventions
41

Interventions may be added through the Custom Model Specification window. If seasonal AR or MA
terms are required, the ARIMA Model Specification window must be used. The ARIMA Model
Specification window is the most general model formulation window in the TSFS.
5.2 Event Models 5-23

Intervention Specification Window

42

The Nine Individual Intervention Effects

43

A detailed analysis of the airline passengers data will help illustrate many of these concepts.
5-24 Chapter 5 Forecast Models with Explanatory Variables

Intervention Analysis of the Airline Data

A new project is created named FETS.TSFSPROJ.AIRLINE.

The airline passengers data stored in FETS.DOTAIRTS will be used. Select Develop Models.
5.2 Event Models 5-25

The target variable is PASSENGERS.

No holdout sample will be used. Examine the series plot.


5-26 Chapter 5 Forecast Models with Explanatory Variables

The dramatic change in the series beginning in September 2001 is obvious.

You can use Fit Custom Model or Fit ARIMA Model to derive a dynamic regression model for the
data. The Fit ARIMA Model is slightly more general in that it will allow you to fit a full Box-Jenkins
seasonal component with AR and MA seasonal terms.
5.2 Event Models 5-27

You must select appropriate trend and seasonal components before exploring the intervention effect.

Initially, linear trend and seasonal differences will be used to model trend and seasonality.
5-28 Chapter 5 Forecast Models with Explanatory Variables

You next must select Add Interventions to specify an intervention effect.

The intervention date is September 2001.


5.2 Event Models 5-29

Next, specify the type of intervention.

Type Point and decay pattern Exp (exponential) are equivalent to an abrupt temporary effect.
5-30 Chapter 5 Forecast Models with Explanatory Variables

Select OK to add the intervention term to the model.

Select OK to fit the model.


5.2 Event Models 5-31

The model RMSE is displayed.

A residual analysis is performed to suggest an appropriate ARMA(p,q) error model.


5-32 Chapter 5 Forecast Models with Explanatory Variables

You will learn that a large residual for December 2003 is always present. In fact, an outlier analysis using
the OUTLIER statement in the SAS/ETS ARIMA procedure suggests that the value for December 2003 is
an outlier for the passengers time series.

The autocorrelation plots suggest the following candidate models: AR(1), MA(2), ARMA(1,1),
ARMA(1,2).
5.2 Event Models 5-33

Diagnostic plots indicate that the residuals are stationary, but not white noise.

The parameter estimates are not very meaningful at this point, but you should observe an interesting
phenomenon. Obviously, for most of the time series, the trend is positive, yet the estimated slope is
negative. This is a common occurrence when you mix seasonal differencing with a parametric trend
component. Seasonal differencing tends to wash out the original trend effect in the sense that the above
slope coefficient does not really measure the actual slope. To illustrate this, consider the estimates when
seasonal dummies are used instead of seasonal differencing.
5-34 Chapter 5 Forecast Models with Explanatory Variables

When seasonal dummies are employed, the linear trend slope coefficient is closer to what you visually
estimate the slope to be. Overall, passenger counts are increasing by about 183,677 every month.

You can duplicate and then edit the model to save model specification time.
5.2 Event Models 5-35

Add an error model to the original model. Initially, try an AR(1) model.
5-36 Chapter 5 Forecast Models with Explanatory Variables

Select OK.

The RMSE value improves by about 15%.


5.2 Event Models 5-37

A residual analysis will help diagnose the adequacy of the intervention model with an AR(1) error
component.

Except for the outlying December 2003 value, the residuals appear to be random.
5-38 Chapter 5 Forecast Models with Explanatory Variables

The significant spike at lag 12 is probably spurious due to the use of seasonal differencing. However, you
may wish to investigate adding a stationary lag 12 AR term.

Diagnostic plots suggest that the residuals are white noise.


5.2 Event Models 5-39

All estimates are significant at the 1% level.


5-40 Chapter 5 Forecast Models with Explanatory Variables

Linear trend is replaced by first differences.

RMSE is better, using linear trend rather than first differences.


5.2 Event Models 5-41

A somewhat exhaustive analysis reveals 11 candidate models. The best model as judged by RMSE
exhibits several shortcomings.

In particular, both moving average estimates are not significant. If you examined SBC values, you would
see that SBC rates this model poorly compared to the other candidate models. You would normally not
disqualify a model because some estimates are not significant, but disqualification seems warranted in
this case.
5-42 Chapter 5 Forecast Models with Explanatory Variables

The lag 16 Ljung-Box test implies that the residuals are not white noise. This result is likely a spurious
one.

An alternative to the abrupt temporary effect is a gradual permanent effect.


5.2 Event Models 5-43
5-44 Chapter 5 Forecast Models with Explanatory Variables

If the gradual permanent effect seems justified, you must determine the appropriate ARMA(p,q) error
model.

Diagnostics imply that ordinary and seasonal AR factors should be considered.


5.2 Event Models 5-45

Select Fit ARIMA Model to employ the ARIMA Model Specification window to add a seasonal AR
term.
5-46 Chapter 5 Forecast Models with Explanatory Variables

The ARIMA Model Specification window also provides the same features as the Custom Model
Specification window for adding predictors.

The completed model specification includes the ordinary and seasonal AR terms.

The gradual permanent effect model is competitive, although visual inspection of the time series seems to
imply an abrupt effect, whether temporary or permanent.
5.2 Event Models 5-47

Replacing the linear trend with a first difference increases RMSE.

A simple step function is used to model an abrupt, permanent effect.


5-48 Chapter 5 Forecast Models with Explanatory Variables

If you attempt to combine the gradual effect and the abrupt effect, you will impose a near singularity,
which is analogous to multicollinearity in ordinary regression.

Instead, a ramp function can be employed to investigate if the intervention not only has an abrupt impact
but also has a permanent impact on the trend in the series.
5.2 Event Models 5-49

Adding a ramp to the gradual, permanent intervention term results in a model that cannot be fit by the
TSFS. On the other hand, adding a ramp to the abrupt, temporary effect produces the best model so far.
5-50 Chapter 5 Forecast Models with Explanatory Variables

If the above selected model passes inspection, you might conclude that the terrorist attacks had an
immediate impact on airline passenger counts and a permanent impact on the slope of the trend line.
5.2 Event Models 5-51

The model appears to fit the data well.

Residuals show no obvious patterns.


5-52 Chapter 5 Forecast Models with Explanatory Variables

Diagnostic plots suggest that residuals are white noise.


5.2 Event Models 5-53

The overall slope coefficient is not significant. All other estimates are highly significant, except for the
constant term, which is significant at the 5% level. Nonetheless, the negative slope makes it difficult to
adequately assess the impact of the attack. While the statistics of fit below suggest that this is a
competitive model, for the purposes of inference and assessment, one more model is tried.

To conclude the analysis, replace the seasonal differencing with seasonal dummies.
5-54 Chapter 5 Forecast Models with Explanatory Variables

A few additional models are also exhibited in the above screen capture, but the best model so far is the
model with parametric trend and seasonal terms. This model suggests that the terrorist attacks had an
overall permanent negative impact on airline travel as exhibited by the combination of the abrupt,
temporary impact term and the ramp term.
5.2 Event Models 5-55

The increase of 182,938 passengers per month before the intervention becomes a loss of 294,618
passengers per month after the intervention, although this must also be combined with the return to
normalcy evidenced by the abrupt, temporary effect term.
These results should be viewed as tentative. The addition of one or two more years of data will provide
more conclusive evidence of a permanent effect if it exists.
5-56 Chapter 5 Forecast Models with Explanatory Variables

Exercises

1. Perform a residual analysis of the best airline data model to determine if the model should be used or
disqualified.
5.3 Time Series Regression Models 5-57

5.3 Time Series Regression Models

Objectives
Present the general dynamic regression model.
Give common simple examples of dynamic regression
models.
Illustrate how to use the TSFS to diagnose and fit time
series regression models.

47

Box-Jenkins Time Series Regression Model


D(B)Ds (B s ) f ( yt )
N ki i (B)s,i (Bs ) (B)s (Bs )
s
= + B D ( B) D ( B ) f ( x ) +
i=1 i s,i i (B) s,i (Bs ) i i,t (B)s (B s ) t

Theoretical ARIMAX Model

48
5-58 Chapter 5 Forecast Models with Explanatory Variables

This most general expression of the ARIMAX models may look intimidating; however, information on
most of its factors is in previous chapters.

Box-Jenkins Model Components


Trend

D(B)Ds (B s ) f ( yt )
N k (B)s,i (Bs ) (B)s (Bs )
= + B i D ( B) D ( B s ) i f (x ) +
i=1 i s,i i (B) s,i (B ) i i,t (B)s (B s ) t
s

Theoretical ARIMAX Model

continued...

49

Using differencing to model trend is presented in Chapter 2 and in Chapter 4.

Box-Jenkins Model Components


Seasonal

D(B)Ds (B s ) f ( yt )
N ki i (B)s,i (Bs ) (B)s (Bs )
s
= + B D ( B) D ( B ) f ( x ) +
i=1 i s,i i (B) s,i (Bs ) i i,t (B)s (B s ) t

Theoretical ARIMAX Model

continued...

50
5.3 Time Series Regression Models 5-59

Seasonal differences to model seasonal models is discussed in Chapter 2 and chapter 4. Including
seasonal ARMA terms is discussed in Chapter 4.

Box-Jenkins Model Components


Stationary

D(B)Ds (B s ) f ( yt )
N k (B)s,i (Bs ) (B)s (Bs )
= + B i D ( B) D ( B s ) i f (x ) +
i=1 i s,i i (B) s,i (B ) i i,t (B)s (B s ) t
s

Theoretical ARIMAX Model

continued...

51

Nonseasonal ARMA terms are discussed in Chapter 3. Seasonal ARMA terms may also be considered
part of the stationarity component of the general ARIMAX model.

Box-Jenkins Model Components


Input Variables

D(B)Ds (B s ) f ( yt )
N ki i (B)s,i (Bs ) (B)s (Bs )
s
= + B D ( B) D ( B ) f ( x ) +
i=1 i s,i i (B) s,i (Bs ) i i,t (B)s (B s ) t

Theoretical ARIMAX Model

52
5-60 Chapter 5 Forecast Models with Explanatory Variables

The earlier discussion of interventions includes information on special cases of the transfer function.
Below, a discussion of the general application of the transfer functions for dynamic regressors is included.
Recall that the transfer function can be truncated numerically by ignoring terms with coefficients that are
close to zero.

i ( B)
,
i ( B)
i ( B) = i 0 i1 B L im B m , i
i

i ( B) = i 0 i1 B L ih B h
i
i

i ( B)
= i 0 i1 B i 2 B 2 L ik B k L
i ( B)

Truncation Point i,k+1 < Tolerance

A discussion of some common simple transfer functions using the notation of the ARIMAX model
follows.
All the models shown below must be defined through the Custom Models Specification window.

Common Transfer Functions

continued...

53

Ordinary regressors can be defined in the Custom Models Specification window by adding regressors or
dynamic regressors. Adding regressors and dynamic regressors is demonstrated later.
5.3 Time Series Regression Models 5-61

Common Transfer Functions


Ordinary Regression with one lag term:
(B) = 0 + B1 , (B) = 1
Yt = 0 + 0 X t + 1 X t 1 + Z t
where Zt is an ARMA error term.

continued...

54

Common Transfer Functions


Defining an Ordinary Regression with one lag term

continued...

55

An ordinary regression with one lag term must be defined by adding dynamic regressors in the Custom
Models Specification window. Note that Input Transformations: Lagging Periods = 0, the Numerator
Factors: Simple Order = 1, and the Denominator Factors: Simple Order = 0. All seasonal factors = 0.
5-62 Chapter 5 Forecast Models with Explanatory Variables

Common Transfer Functions

continued...

56

Common Transfer Functions


Shifted Regression with one lag term :
(B) = 1B + 2 B2 , (B) = 1
Yt = 0 + 1 X t 1 + 2 X t 2 + Z t
where Z t is an ARMA error term.

continued...

57
5.3 Time Series Regression Models 5-63

Common Transfer Functions


Defining a Shifted Regression with one lag term

continued...

58

A shifted regression with one lag term must be defined by adding dynamic regressors in the Custom
Models Specification window. Note that Input Transformations: Lagging Periods = 1, the Numerator
Factors: Simple Order = 1 and the Denominator Factors: Simple Order = 0. All seasonal factors = 0.
5-64 Chapter 5 Forecast Models with Explanatory Variables

Common Transfer Functions


Infinite Past Regression(1):
( B ) = 0 ( B ) = 1 1 B
Yt = 0 + {0 /(1 1 B )} X t + Z t
where Zt is an ARMA error term

continued...

59

Common Transfer Functions


Defining an Infinite Past Regression(1)

60
5.3 Time Series Regression Models 5-65

An infinite past regression must be defined by adding dynamic regressors in the Custom Models
Specification window. Note that Input Transformations: Lagging Periods = 0, the Numerator Factors:
Simple Order = 0 and the Denominator Factors: Simple Order = 1. All seasonal factors = 0.
Notice that the Dynamic Regression Specification window also permits defining both simple and seasonal
differences for the input, and season numerator and denominator terms. Consequently, all the components
of the general form of the transfer function illustrated in previous slides can be defined through the
interface.
The challenge to the forecaster is to identify which transfer functions to estimate and evaluate.

Box-Jenkins Methodology for Dynamic


Regression
Identify Step
Determine which input variables to include in the
model.
Determine the numerator and denominator order of
the transfer function for each input variable.
Determine trend and seasonality.

Determine the ARMA(p,q) error model.

61
5-66 Chapter 5 Forecast Models with Explanatory Variables

Special Considerations for Stochastic Inputs


Trend and seasonal components are removed before
investigating the dynamic relationship between the input
and target.
After removing trend and seasonal effects, each input
can be evaluated with respect to the target variable
using a cross-correlation plot.
Additionally, a pre-whitening filter should be applied to
the input and target before calculating cross-correlations.
Pre-whitening is beyond the scope of this course. The
cross-correlation function is not provided by the TSFS.

62

The Cross-Correlation Function


CCF(k) is the cross-correlation of target Y with input X at
lag k.
The response variable is always listed first.

A significant value at lag k implies that Yt and Xt-k are


correlated.

continued...

63
5.3 Time Series Regression Models 5-67

The Cross-Correlation Function

significant

-1 1
Two standard errors

continued...

64

The Cross-Correlation Function

continued...
65

In the above cross-correlation plot, evidence suggests a dynamic relationship between Y and X with
significant correlations at lags 0, 1, 2, 5, 6, 7, and 8. The above plot also reveals a proximity effect, that is,
a strong significant value at lag 0 produces spurious significant values at lags 1 and 2.
5-68 Chapter 5 Forecast Models with Explanatory Variables

Significant values at negative lags may be aliases of the significant values at positive lags. In the context
of cross-correlations, an aliasing occurs when a significant value at lag k produces a spurious significant
value in the vicinity of lag k or a multiple of k.

The Cross-Correlation Function

66

The above plot provides evidence of a relationship between Y and X with significant correlations at lags 5
and 6. The value at lag 24 is spurious. Significant values at negative lags 7, 8, and 9 are aliases of the
significant values at positive lags. The significant values at negative lags are spurious.
The cross-correlation plots were obtained from the TIMESERIES procedure in SAS/ETS software. The
ARIMA procedure also produces cross-correlation plots. The TSFS does not have a cross-correlation
option. If the two series Y and X are not properly pre-whitened, the cross-correlation plot may be
misleading.
Because these advanced methods for identifying potential transfer functions are not available in the TSFS,
the TSFS user will need to use business knowledge and trial and error to identify a suitable transfer
function.
5.3 Time Series Regression Models 5-69

Dynamic Regression Using the TSFS


Derive a univariate forecast model for each stochastic
input variable.
Derive a univariate forecast model for the target
variable, focusing on obtaining appropriate trend and
seasonal factors.
Derive a dynamic regression model for the target and
each stochastic input separately to diagnose the form
of the transfer function.
Derive a full dynamic regression model using all inputs
that are correlated with the target.
Diagnose an ARMA(p,q) model for the stationary error
component.

67
5-70 Chapter 5 Forecast Models with Explanatory Variables

Evaluating Advertising Effectiveness

An Internet start-up company provides financial and brokerage services to customers. A customer sets up
an account with an initial deposit of $1,000, and then the company provides services via the Internet or by
phone. Services include a variety of banking and investment options, such as automatic debits for paying
bills, on-demand transaction and tax information, automatic money market investing for positive
balances, and online brokerage services for investing in stocks and mutual funds.
The full data contains extensive breakdowns of advertising dollars. For example, for print media
advertising, dollar amounts are recorded for each individual newspaper or magazine in which ads were
placed. This illustrates a common situation where there are almost as many variables as there are
observations. Another problem results from some accounts being tabulated monthly, while others are
tabulated weekly. Many advertising accounts are dominated by zeroes, meaning that no advertising
dollars were spent on the account for several months in a row.
The response variable is the total sales amount for all customers. This amount reflects revenue generated
by account activity, such as deposits, investments, withdrawals, and so on. Finally, data are obtained from
a data vendor that tabulates total sales amounts for a subset of the companies engaged in this type of
Internet business. The vendor claims to adjust the data so that a company with a traditional bricks-and-
mortar bank operation combined with an Internet operation has sales amounts only for the Internet
component of the business. While you may suspect the validity of the vendors claim, your main concern
is that the vendor data be consistent over time.
Many of the time consuming and tedious steps of the analysis will be excluded. Some actions include
aggregating data to the same time unit and deriving candidate predictor variables. The demonstration
commences after the data has been processed into a form suitable for final modeling.
The predictor variables are shown here:

Predictor Variable Description


DirectMail Weekly direct mail advertising (x$1000)
Internet Weekly Internet advertising (x$1000)
PrintMedia Weekly print media advertising (x$1000)
SalesRatio Ratio of competitor sales to total known sales
TVRadio Weekly TV/radio advertising (x$1000)

The target variable is SalesAmount, which is total sales in thousands of dollars. An additional variable
used in deriving SalesRatio is CompeteSales, which is the vendor-supplied value of sales for
competing companies in the Internet domain. The data set that contains these variables is SALEDATA,
which has 88 weekly observations from the week of 28 September 1997 to the week of 30 May 1999.
5.3 Time Series Regression Models 5-71

Preliminary analysis implies that the influence of all input variables is aligned with the target series,
except DirectMail, which appears to be a leading indicator of SalesAmount by two weeks. A
custom model with regressors Internet, PrintMedia, TVRadio, and SalesRatio, and dynamic
regressor DirectMail shifted two weeks is fit to the first 68 observations using the TSFS.

The analysis was performed for data stored in a library named TSFLIB. For this course, the data is stored
in FETS.SALEDATA. In the Develop Models window, select Fit Custom Model for variable
SalesAmount.

Add regressors as described above.


5-72 Chapter 5 Forecast Models with Explanatory Variables

Add dynamic regressor DirectMail with a shift (lagging period) of two weeks.

You are now ready to fit the model.


5.3 Time Series Regression Models 5-73

Select OK.

Because of the number of inputs, the model title is truncated. You may wish to modify the title if you plan
to fit several models in which the truncated titles will be the same.
Click on the model and select the residual plot.
5-74 Chapter 5 Forecast Models with Explanatory Variables

The residuals do not appear to be white noise. View the autocorrelations by selecting .
This opens the residual correlation plot window. The natural periodicity of 52 weeks makes for a cluttered
plot.
5.3 Time Series Regression Models 5-75

Nonetheless, the plots are consistent with an AR(6) error term. Fit the same model, except add an AR(6)
error component.

Select OK. After the model is fit, select the residual plot as before.

The residuals look even less like white noise. The correlation plots also suggest that the model is not
adequate.
5-76 Chapter 5 Forecast Models with Explanatory Variables

The modeling process requires trial and error that includes analysis of a number of candidate models.
Industry knowledge suggests SalesRatio as a derived input variable, and at some point in the analysis,
industry knowledge combined with data analysis leads to the conjecture that the sales ratio should be a
leading indicator of at least one week.
Fit the same model as before, without the AR(6) error component, but shift sales ratio by one week.
5.3 Time Series Regression Models 5-77

Notice that the model titles have been modified from those supplied by the TSFS. The residuals for the
new model do not appear to be white noise.

The correlation plots imply an AR(3) or an AR(6) error component.

Select an AR(6) error component and modify the model title to distinguish models.
5-78 Chapter 5 Forecast Models with Explanatory Variables

Select OK.

The latest model produces a significant drop in RMSE. Excluding the first few residuals, which are
impacted by starting values, the residual plot looks like white noise.
5.3 Time Series Regression Models 5-79

The correlation plots also imply white noise.

The parameter estimates reveal that the selected AR order of 6 may be too high.
5-80 Chapter 5 Forecast Models with Explanatory Variables

Fit a new model that is the same as the last model, except use an AR(5) error component.

The estimates for this new model follow.


5.3 Time Series Regression Models 5-81

All estimates are significant at the 5% level of significance, and all but one are significant at the 1% level.
Residual plots indicate white noise residuals. While this may not be the optimal model, evidence suggests
that the model is adequate for forecasting.
For this problem, the business intelligence is that Internet and direct-mail advertising have the biggest
impact on sales. The business professional can perform a what-if analysis using the forecast models with
various values for advertising expenses. However, keep in mind that extrapolation beyond the data may
be dangerous. For example, if $500,000 is the most that has been spent for Internet advertising, it would
be foolish to expect that spending $50,000,000 on Internet advertising will increase sales by $5 billion.
5-82 Chapter 5 Forecast Models with Explanatory Variables

5.4 Chapter Summary


Time series regression analysis is an extension of ordinary regression analysis. Time series regression is
known as dynamic regression when one or more of the input variables is correlated with the target
variable at non-concurrent time lags.
Time series regression inherits the usual regression challenges: input variable selection, multicollinearity,
and influential observations. However, time series regression solves the problem of autocorrelated errors.
The partial correlation coefficient that expresses how an input variable influences the target in ordinary
regression becomes a set of coefficients that comprise the transfer function in time series regression. The
rational transfer function devised by Box, Jenkins, and Tiao permits estimation of complex relationships
with relatively few parameters to accommodate the limited data that often restricts time series regression
model fitting.
Event models use transfer functions applied to point or step function variables. The use of point, step, and
ramp variables combined with rational transfer functions provides a rich set of event effects.
Dynamic regression adds additional challenges to variable selection in regression. An input may be
uncorrelated with the target variable concurrently in time, but the input may be strongly correlated with
the target when it is shifted by one or more time units. Consequently, variable selection includes
additional steps because of the addition of the time dimension. The TSFS can be employed to examine the
target related to each input to help diagnose the form of the transfer function.

For Additional Information


Box, G.E.P., and Jenkins, G.M. (1976), Time Series Analysis: Forecasting and Control, Revised Edition,
San Francisco: Holden-Day.
Box, G.E.P., and Tiao, G.C. (1975), Intervention Analysis with Applications to Economic and
Environmental Problems, JASA, 70, 70-79.
Brocklebank, J.C., and Dickey, D.A. (2003), SAS System for Forecasting Time Series, Second Edition,
Cary, North Carolina: SAS Institute Inc.
Cook, R.D., and Weisberg, S. (1999), Applied Regression Including Computing and Graphics, New York:
John Wiley & Sons, Inc.
Diggle, P.J. (1990), Time Series: A Biostatistical Introduction, Oxford: Clarendon Press.
Judge, G.G., Griffiths, W.E., Hill, R.C., Ltkepohl, and Lee, T.C. (1985), The Theory and Practice of
Econometrics, Second Edition, New York: John Wiley & Sons, Inc.
West, S.G., McCall, M.A., Hepworth, J.T., and Reich, J.W. (1985), An Evaluation of Arizonas 1982
Drunk Driving Law: Effects on the City of Phoenix, Final report to the Morrison Institute.
Woodfield, T.J. (1987), Time Series Intervention Analysis Using SAS Software, Proceedings of the
Twelfth Annual SAS Users Group International Conference, 331-339. Cary, North Carolina: SAS
Institute Inc.
5.5 Solutions to Exercises 5-83

5.5 Solutions to Exercises


1. The following plots summarize the residual analysis of the model with linear trend, seasonal
dummies, ramp intervention effect, abrupt, permanent intervention effect, and ordinary and seasonal
AR components.
5-84 Chapter 5 Forecast Models with Explanatory Variables

The diagnostic plots show potential deviations from white noise, but these could easily be spurious.
The seasonal AR estimate and the November seasonal dummy coefficient are not significantly
different than zero. These facts are inadequate to disqualify the model.
Appendix A Basic Forecasting Using
SAS Enterprise Guide (Self-Study)

A.1 Basic Forecasting Using SAS Enterprise Guide ........................................................ A-3


A-2 Appendix A Basic Forecasting Using SAS Enterprise Guide (Self-Study)
A.1 Basic Forecasting Using SAS Enterprise Guide A-3

A.1 Basic Forecasting Using SAS Enterprise Guide

The SAS Enterprise Guide User Interface


Menu Bar

Project Window

Task Window
2

The SAS Enterprise Guide interface has the look and feel of a Microsoft Windows application. Initial
releases were available only for the Microsoft Windows operating system. SAS Enterprise Guide provides
a cornerstone for SAS Business Intelligence software.
A-4 Appendix A Basic Forecasting Using SAS Enterprise Guide (Self-Study)

Selected Tasks

continued...

SAS Enterprise Guide is packaged with a variety of tasks for data preparation and analysis.

Selected Tasks

4
A.1 Basic Forecasting Using SAS Enterprise Guide A-5

SAS Enterprise Guide is often the application of choice for querying a database. SAS Enterprise Guide
works with data access engines supported by SAS. SAS has access engines for Oracle, Sybase, and many
other databases, as well as engines that take advantage of OLE and ODBC.

Importing Data

continued...

To illustrate data access features, SAS Enterprise Guide will be used to import a CSV (comma-separated
values) file.

Importing Data

continued...

6
A-6 Appendix A Basic Forecasting Using SAS Enterprise Guide (Self-Study)

The course folder contains a file named dot9497.csv.

Importing Data

continued...

The first record of the file has column names separated by columns. All other records have data values
separated by commas. You will import the entire file.
Click in the box to the left of Preview Window to get a preview of the SAS code that is generated to read
the data.
A.1 Basic Forecasting Using SAS Enterprise Guide A-7

Importing Data

continued...

If you understand SAS programming, you can review the code and see the consequences of the choices
that you make.

Importing Data

continued...

You can see that the Text Format window guesses that the data is stored in a comma-delimited format.
A-8 Appendix A Basic Forecasting Using SAS Enterprise Guide (Self-Study)

Importing Data

continued...

10

The Column Options section allows you to control how individual fields are processed.

Importing Data

continued...

11

Because date values are stored in an unusual format, namely YYYYMON, the date field will be
discarded. In a moment you will see the consequences of leaving the date field as a character field.
A.1 Basic Forecasting Using SAS Enterprise Guide A-9

Importing Data

continued...

12

A temporary SAS data table is created by default. You can override this option and specify a permanent
location for the SAS data table.

Importing Data

13

The Process Flow reveals the actions that have been completed so far. A CSV file has been processed by
the Import Data task, producing the temporary file WORK.IMPW5848.
A-10 Appendix A Basic Forecasting Using SAS Enterprise Guide (Self-Study)

You can open the data table for viewing. You can see that the Date variable was dropped.

Saving the Project


File Save Project As.

continued...

15

You should save your project regularly so that your work will not be lost if there is a catastrophic system
failure.

Saving the Project

16
A.1 Basic Forecasting Using SAS Enterprise Guide A-11

As you will see in the next section, time series forecasting applications require the existence of a time ID
variable in the project data.

Preparing the Data

continued...

17

In the Time Series section of the Task List, the task Prepare Time Series Data can be used to properly pre-
process the data table so that it can be used with forecasting applications.

Preparing the Data

Create Date
variable that
is monthly
beginning
with 1/1/1994

continued...

18
A-12 Appendix A Basic Forecasting Using SAS Enterprise Guide (Self-Study)

The task allows you to create a time ID variable. For the dot9497 data, a time ID is created that is
monthly, beginning with the month of January 1994.

Preparing the Data

Passengers
is the variable
to forecast.

continued...

19

The task also allows you to specify the variables that are to be forecast.

Preparing the Data

20

The final data set has a field for date and a field for passengers. All other fields have been discarded.
A.1 Basic Forecasting Using SAS Enterprise Guide A-13

Plotting the Data

continued...

21

A simple line plot can be produced by SAS Enterprise Guide using a simple graphics task. This step is
unnecessary because forecasting tasks produce plots of the time series. However, when you use SAS
Enterprise Guide for data preparation and the TSFS for forecasting, you may choose to produce a plot
with SAS Enterprise Guide to verify that the data was processed correctly.

Plotting the Data

continued...

22

A series of windows allow you to customize your plot.


A-14 Appendix A Basic Forecasting Using SAS Enterprise Guide (Self-Study)

Plotting the Data

continued...

23

Some practitioners choose to produce a scatter plot of the data. SAS Enterprise Guide provides several
options.

Plotting the Data

continued...

24

The plot exhibits features mentioned previously.


A.1 Basic Forecasting Using SAS Enterprise Guide A-15

Plotting the Data

Why you should use SAS datetime values!!! continued...

25

If you keep the date variable found in the original CSV file, it is stored as a character variable. A line plot
will connect the dots in the order they appear in the data table. The data are sorted in date order, which is
different than ASCII sort order used for the horizontal axis. When you get the graffiti plot above, you will
know that a mistake has been made.

Plotting the Data

Why you should use SAS datetime values!!!


26
A-16 Appendix A Basic Forecasting Using SAS Enterprise Guide (Self-Study)

A common practice is to sort the data by the date variable to ensure proper plotting and modeling.
Unfortunately, sorting by a character variable produces an ASCII sort sequence, which provides a bogus
representation of the data. You should always ensure that the date variable is a numeric SAS date or
datetime variable.

Basic Forecasting with SAS Enterprise Guide

Advanced Forecasting
Forecasting with Inputs
Automatic Forecasting
(using default settings)

continued...

27

SAS Enterprise Guide supports several forecasting tasks. You select Basic Forecasting because it is
somewhat similar to automatic forecasting in the TSFS.
A.1 Basic Forecasting Using SAS Enterprise Guide A-17

Basic Forecasting with SAS Enterprise Guide

continued...

28

The Basic Forecasting task will take advantage of the fact that you have already prepared the data for
forecasting. The time ID is Date and the forecast variable is Passengers.

Basic Forecasting with SAS Enterprise Guide

continued...

29

A nave user is wise to use default values, especially for methodological choices. Stepwise autoregression
with a linear trend term is the default setting.
A-18 Appendix A Basic Forecasting Using SAS Enterprise Guide (Self-Study)

Basic Forecasting with SAS Enterprise Guide

continued...

30

Several plots are selected to help evaluate the forecasts.

Basic Forecasting with SAS Enterprise Guide

continued...

31

Forecasts and parameter estimates (model coefficients) are stored in two separate tables.
A.1 Basic Forecasting Using SAS Enterprise Guide A-19

Basic Forecasting with SAS Enterprise Guide

continued...

32

You can customize the output, but default settings are used in this analysis.

Basic Forecasting with SAS Enterprise Guide

Forecast Table

Model Coefficients
Table

HTML Output

continued...

33

The Process Flow shows the tasks and results. You can click on any results object and open it for viewing.
A-20 Appendix A Basic Forecasting Using SAS Enterprise Guide (Self-Study)

Basic Forecasting with SAS Enterprise Guide


HTML Output Display of Model Coefficients

continued...

34

The HTML results display model coefficients and accuracy statistics. The above table is clipped to fit on
the slide.

Basic Forecasting with SAS Enterprise Guide


Improve plots by limiting data to display.

35
continued...

The data is limited to the last 24 months plus the forecasts to help enhance the forecast plot for
interpretation.
A.1 Basic Forecasting Using SAS Enterprise Guide A-21

Basic Forecasting with SAS Enterprise Guide

continued...

36

To the left of the dashed vertical line the forecasts are plotted with a solid blue line, and the actual values
are plotted with a dashed black line. The future forecasts to the right of the dashed vertical line are in
blue, and the 95% prediction intervals are in red.

Basic Forecasting with SAS Enterprise Guide

continued...

37

The residuals are examined for model irregularities.


A-22 Appendix A Basic Forecasting Using SAS Enterprise Guide (Self-Study)

Basic Forecasting with SAS Enterprise Guide

Accuracy Statistics
continued...

38

Scrolling the HTML output reveals the accuracy statistics. These are calculated for the entire data set and
do not use a holdout sample.

Basic Forecasting with SAS Enterprise Guide


Project View

continued...

39

The Project view provides a tree diagram of the tasks and results.
A.1 Basic Forecasting Using SAS Enterprise Guide A-23

Basic Forecasting with SAS Enterprise Guide


You can view the script or program code that produced
the results. This code can be used to create a script for
batch generation of forecasts using a batch program or a
stored process.

continued...

40

Included in the results is a Code object that contains a script for generating the plots, estimates, and
forecasts.

Basic Forecasting with SAS Enterprise Guide


A portion of the code shows that the SAS/ETS procedure
FORECAST is used to fit a model and produce forecasts.

continued...

41

Stepwise autoregression is supported by PROC FORECAST in SAS/ETS software.


A-24 Appendix A Basic Forecasting Using SAS Enterprise Guide (Self-Study)

Basic Forecasting with SAS Enterprise Guide


PROC FORECAST
produces an
interleaved
forecast table.

continued...

42

PROC FORECAST produces interleaved output. Interleaved output contains multiple rows per date, with
each row representing a specific quantity such as actual value, forecast value, standard error of forecast,
and so on.

Basic Forecasting with SAS Enterprise Guide


The _LEAD_
column indicates
how many months
into the future the
forecast applies.

43

Future forecasts have a lead specifier. If lead=5, then the forecast uses data up to five months ago.
A.1 Basic Forecasting Using SAS Enterprise Guide A-25

The Time Series Forecasting System versus


SAS Enterprise Guide
Method or Feature TSFS EG
Basic Regression Yes Yes
Exponential Smoothing Yes Yes*
Stepwise Autoregression No Yes
Regression with Autocorrelated Errors Yes Yes
Box-Jenkins ARIMA Modeling Yes Yes
Box-Jenkins-Tiao Dynamic Regression Yes No
Box-Tiao Intervention Modeling Yes No
Automatic Model Selection Yes No
Interactive Model Diagnosis Yes No
Interactive Model Comparison Yes No
Customizable Yes No

44
*SAS Enterprise Guide requires user specification of weights.

The time series features of SAS Enterprise Guide are limited because SAS Enterprise Guide was designed
as a simple all-purpose data preparation and analysis application. On the other hand, the TSFS was
designed specifically for forecasting. Because the TSFS has minimal data preparation features, SAS
Enterprise Guide is often employed for data preparation and the TSFS is used for model building.
A-26 Appendix A Basic Forecasting Using SAS Enterprise Guide (Self-Study)

Business Forecasting with the TSFS and


SAS Enterprise Guide
SAS Enterprise Guide provides a user friendly
platform for data preparation and basic exploratory
analysis.
The TSFS provides a comprehensive set of simple
and advanced forecasting techniques.
SAS Enterprise Guide advanced techniques require
greater expertise from the user than the TSFS.
The TSFS is specifically designed for forecasting,
whereas SAS Enterprise Guide is designed for data
processing, reporting, and general statistical analysis.

45

While SAS Enterprise Guide may seem to be more user friendly than the TSFS, it is actually more
difficult to use for advanced forecasting. SAS Enterprise Guide is task based, which usually means that a
menu is provided with a list of available tasks, but little guidance is provided for task selection. On the
other hand, the TSFS is designed for time series analysis as it is practiced, making it easy to explore
different models rapidly so that forecast project time is minimized.
Both SAS Enterprise Guide and the TSFS are well suited for business forecasting. Appendixes B and C
contain some examples of forecasting in select business areas.
Appendix B Processing Time Series
Data with SAS Enterprise Guide
(Self-Study)

B.1 Processing Time Stamped Transactional Data ........................................................... B-3

B.2 Transposing Data......................................................................................................... B-23

B.3 Changing the Frequency of Time Series Data .......................................................... B-38

B.4 Augmenting Data with Event Variables ..................................................................... B-65

B.5 Chapter Summary........................................................................................................ B-74

B.6 Solutions to Exercises ................................................................................................ B-75


B-2 Appendix B Processing Time Series Data with SAS Enterprise Guide (Self-Study)
B.1 Processing Time Stamped Transactional Data B-3

B.1 Processing Time Stamped Transactional Data

Objectives
Process time stamped transactional data into equally
spaced time series data.
Convert transactional data stored as rows into time
series data stored as columns.
Combine multiple time series observed at different
frequencies into one time series data table.
Convert equally spaced time series data from one
frequency to another.
Work with SAS date, time, and datetime values,
formats, informats, and functions.

Opening a SAS Data Table in SAS Enterprise


Guide

Add a SAS table to the project.


Add a data table to the
project using a SAS data
access engine.
continued...

4
B-4 Appendix B Processing Time Series Data with SAS Enterprise Guide (Self-Study)

Opening a SAS Data Table in SAS Enterprise


Guide
Add Items to Project Open From My Computer

continued...

Opening a SAS Data Table in SAS Enterprise


Guide

6
B.1 Processing Time Stamped Transactional Data B-5

Preparing Transactional Data for Forecasting


Using the Summary Statistics Task

The Summary Statistics task


provides one method for
aggregating transactions.

Task Roles for Variables

continued...
8
B-6 Appendix B Processing Time Series Data with SAS Enterprise Guide (Self-Study)

Task Roles for Variables

The average
price is
calculated
by the
formatted
value of
DATE.

continued...

Task Roles for Variables


Number of seconds
SAS Datetime since midnight,
value January 1, 1960

SAS Time value Number of seconds


since midnight

Number of days since


January 1, 1960
SAS Date value

10
B.1 Processing Time Stamped Transactional Data B-7

Variable Properties

continued...

11

Variable PropertiesDate Display Formats

Properties associated with a variable include the continued...


SAS display format.
12
B-8 Appendix B Processing Time Series Data with SAS Enterprise Guide (Self-Study)

Variable PropertiesDate Display Formats

YYMMDD9.0 YYMMDD7.0 YYMMDD10.0


99-01-01 990101 1999-01-01

13

Date Display Formats


Date DATE9.0 YYMMDD7.0 YYMMDD10.0
Dec 1, 1999 01DEC1999 991201 1999-12-01
Jan 1, 2000 01JAN2000 000101 2000-01-01
Jan 23, 2000 23JAN2000 000123 2000-01-23
Feb 1, 2000 01FEB2000 000201 2000-02-01

01DEC1999 000101 1999-12-01

Sort 01FEB2000 000123 2000-01-01


Order 01JAN2000 000201 2000-01-23
23JAN2000 991201 2000-02-01
continued...
14
B.1 Processing Time Stamped Transactional Data B-9

Date Display Formats


Date DATE9.0 YYMMDD7.0 YYMMDD10.0
Dec 1, 1999 01DEC1999 991201 1999-12-01
Jan 1, 2000 01JAN2000 000101 2000-01-01
Jan 23, 2000 23JAN2000 000123 2000-01-23
Feb 1, 2000 01FEB2000 000201 2000-02-01
01DEC1999 000101 1999-12-01

Sort 01FEB2000 000123 2000-01-01


Order 01JAN2000 000201 2000-01-23
23JAN2000 991201 2000-02-01
continued...
15

Date Display Formats

Many date display


formats are supported.

continued...

16
B-10 Appendix B Processing Time Series Data with SAS Enterprise Guide (Self-Study)

Date Display Formats

Many general display formats are supported.

17

Task Roles for Variables

Size represents
the number of
transactions at
a given time
and price.

18
B.1 Processing Time Stamped Transactional Data B-11

Basic Statistics

Certain basic
descriptive
statistics
are checked
by default.

continued...

19

Basic Statistics

The average, total, and


maximum prices are
requested.

20

Because the DATE variable is formatted using a daily format, average daily prices are calculated.
B-12 Appendix B Processing Time Series Data with SAS Enterprise Guide (Self-Study)

Percentiles

No percentiles
are checked.

21

Additional Statistics

No additional
statistics are
required.

22
B.1 Processing Time Stamped Transactional Data B-13

Plots

Visual representations
of the data are available.

23

Results

By default, statistics
are displayed but
not stored permanently
in a data table.

continued...

24
B-14 Appendix B Processing Time Series Data with SAS Enterprise Guide (Self-Study)

Results

You want statistics to


be stored permanently
in a data table so that
the table can be used
to derive forecast
equations.

continued...

25

Results

The data table is adequate, but two columns are


unnecessary, and one column is poorly named.

26
B.1 Processing Time Stamped Transactional Data B-15

Modifying the Results Table

You must first toggle the


read-only status to put the
data table in update mode.

continued...

27

Modifying the Results Table

In read-only mode, you can view properties,


but you cannot edit them. Update mode
permits you to modify column properties.
continued...

28
B-16 Appendix B Processing Time Series Data with SAS Enterprise Guide (Self-Study)

Modifying the Results Table

Before changes

continued...

29

Modifying the Results Table

and after

continued...

30
B.1 Processing Time Stamped Transactional Data B-17

Modifying the Results Table

continued...

31

Modifying the Results Table

The final table contains equally


spaced time series data, but only if a
transaction exists for every weekday.

32
B-18 Appendix B Processing Time Series Data with SAS Enterprise Guide (Self-Study)

Exporting the Results Table

You can store the table as a permanent SAS data set


that can be accessed by other projects.
33

Making Data Equally Spaced


The various stock exchanges are closed on holidays.
The stock exchanges have reduced hours on certain
days, such as the Friday after Thanksgiving in the
United States.
Even if you process stock transactions to create daily
values, some days will be missing.
While target variables and input variables can be
missing, dates cannot be missing or the data will not
be spaced equally.

continued...

34
B.1 Processing Time Stamped Transactional Data B-19

Making Data Equally Spaced

The raw EBAY stock transaction continued...


data table has missing dates.
35

Making Data Equally Spaced

Some dates are missing, such as 26SEP1998, which is


a Saturday. Missing weekend days are okay if the
WEEKDAY format is used.

continued...

36
B-20 Appendix B Processing Time Series Data with SAS Enterprise Guide (Self-Study)

Making Data Equally Spaced

Some dates are missing because the stock exchange is


closed. The date 26NOV1998 is missing because
NASDAQ was closed for the U.S. Thanksgiving holiday.

continued...

37

Making Data Equally Spaced

continued...
Use the Prepare Time Series Data task.
38
B.1 Processing Time Stamped Transactional Data B-21

Making Data Equally Spaced

Specify the date interval as continued...

39
Daily, ignoring weekends.

Making Data Equally Spaced

The frequency of observations will not change.

continued...

40
B-22 Appendix B Processing Time Series Data with SAS Enterprise Guide (Self-Study)

Making Data Equally Spaced

No interpolation
produces missing
values for the new
date records.

continued...

41

Making Data Equally Spaced

Thanksgiving (U.S.)

The resulting data table has equally spaced records


with some missing time series variable values.

42

The TSFS accommodates missing values, so the above data set can be used for forecasting.
B.2 Transposing Data B-23

B.2 Transposing Data

Objectives
Use the SAS Enterprise Guide Transpose task to
convert time series values stored in rows to values
stored in columns.
Use the SAS Enterprise Guide data update feature to
modify data properties and apply SAS display formats
to time ID values.

44

Transposing Data
A common practice in sales tracking is to use a
spreadsheet to produce rows of summary sales data
for each department, with columns identifying specific
months.
SAS Enterprise Guide and the Time Series
Forecasting System expect columns to be time series
variables and rows to correspond to dates.
The Transpose task in the SAS Enterprise Guide Data
category allows you to convert data stored as rows
into data stored as columns.

45
B-24 Appendix B Processing Time Series Data with SAS Enterprise Guide (Self-Study)

The Transpose Project

Open a new SAS Enterprise Guide project and add a


SAS data table, CEROW.
46

The CEROW Data Table

Item represents the code for a product within a warehouse. For


example, warehouse 1 is DC1, with product code 603_560613.
Sales for this coded item were 585 units in May 2002.

47
B.2 Transposing Data B-25

The Transpose Task

Transpose Task

48

Task Roles for CEROW Variables

continued...

49
B-26 Appendix B Processing Time Series Data with SAS Enterprise Guide (Self-Study)

Task Roles for CEROW Variables

continued...

50

Task Roles for CEROW Variables

continued...

51

The YYMMDD10.0 format produces the appropriate aggregation level (daily) and the appropriate sort
order.
The example portion of the display illustrates how the format works.

SIZE represents the number of shares purchased at a given time and price.
B.2 Transposing Data B-27

Task Roles for CEROW Variables

52

Transpose Options
You can change the
name and label of the
new source column.

Uncheck the prefix option


so that column names
have the original value in
the Item variable.

53
B-28 Appendix B Processing Time Series Data with SAS Enterprise Guide (Self-Study)

The Transpose Task Results Data

The new Source column contains the old column names.


Because Source is a character variable, it cannot be used
as a time ID variable. A new column must be created.

54

Modifying the Results Data


Put the data table in
update mode, then insert
a new column to contain
a numeric SAS date
variable.

continued...

55
B.2 Transposing Data B-29

Modifying the Results Data


Add a numeric
variable named
Date to
contain the time
ID for
forecasting.

continued...

56

Modifying the Results Data


The Expression
Builder provides
access to SAS
functions and
programming
features in an
interactive
framework.

continued...

57
B-30 Appendix B Processing Time Series Data with SAS Enterprise Guide (Self-Study)

Modifying the Results Data


The INPUT function converts
character values to numeric values
using a SAS conversion informat.

continued...

58

Modifying the Results Data


This INPUT specification converts
character variable Source to a
numeric date variable using the
MONYY7. conversion informat.

continued...

59
B.2 Transposing Data B-31

Modifying the Results Data

continued...

60

Modifying the Results Data


You can assign a
SAS display
format to control
how values of the
new variable are
displayed in
reports and plots.

continued...

61
B-32 Appendix B Processing Time Series Data with SAS Enterprise Guide (Self-Study)

Modifying the Results Data

The new Date


column appears with
values displayed using
the YYMON7. format.
The Source column
is no longer needed continued...
and can be deleted.
62

Modifying the Results Data

63
B.2 Transposing Data B-33

Exporting the Results Data

64 continued...

Exporting The Results Data

The data table is exported


as a SAS data table.

65
B-34 Appendix B Processing Time Series Data with SAS Enterprise Guide (Self-Study)

Forecasting the Exported Data


SAS Enterprise Guide

Use the SAS


Enterprise
Guide Basic
Forecasting
task to
forecast the
12 series.

66

Forecasting the Exported DataTSFS

continued...

67
B.2 Transposing Data B-35

Forecasting the Exported DataTSFS

All 12 series are forecast automatically.


continued...

68

Forecasting the Exported DataTSFS

The Produce Forecasts window places forecasts


for all 12 series in SAS table
continued...
WORK.FORECAST using the format
69 Concatenated.
B-36 Appendix B Processing Time Series Data with SAS Enterprise Guide (Self-Study)

Forecasting the Exported DataTSFS

70

The models derived by the TSFS are discussed in the main body of the course.
B.2 Transposing Data B-37

Exercises

1. (Self-Study) Data set FETS.INSURANCE contains information about individual insurance claims,
including the date that the injury occurred, INJURYDATE, and the date that the claim closed,
CLOSEDATE. Create a new data set that contains the number of claims per month by INJURYDATE.
B-38 Appendix B Processing Time Series Data with SAS Enterprise Guide (Self-Study)

B.3 Changing the Frequency of Time Series Data

Objectives
Describe situations where multiple time series must be
merged by time ID.
Show how the SAS Enterprise Guide Prepare Time
Series Data task can be used to convert time series
data from one frequency to another.
Show how the SAS Enterprise Guide Query Builder
can be used to merge time series data by time ID.

72

Combining Time Series Data Recorded at


Different Time Frequencies
Dynamic forecast models use input time series to
forecast target time series.
All of the series must be synchronized by date.
If different intervals are employed, interpolation or
aggregation is necessary to convert some of the
time series from one interval to another.
After conversion, the resulting tables can be joined
using an inner join in the SAS Enterprise Guide
Query Builder.

73
B.3 Changing the Frequency of Time Series Data B-39

Changing Frequencies
A time interval (for example, weekly, monthly) is
associated with a frequency (for example, 52 values
per year, 12 values per year).
Weekly data is recorded at a higher frequency than
monthly data.
Time intervals can be nested (for example, exactly 7
days are in one week, exactly 12 months are in one
year). For nested intervals, aggregation can provide
exact results when converting to lower frequencies.
If time intervals are not nested (for example, weeks in
months, weeks in years), then conversion to a lower
frequency is approximate.
Interpolation from lower frequencies to higher
frequencies is always approximate.

74

Open a New Project in SAS Enterprise Guide


and Add Data

75
B-40 Appendix B Processing Time Series Data with SAS Enterprise Guide (Self-Study)

The General Retail Data Has Three Columns

76

Import a CSV File Containing the


Monthly U.S. Unemployment Rate

77
B.3 Changing the Frequency of Time Series Data B-41

Create a New SAS Table Using the


Import Data Window

78

The CSV File Is a Comma-Delimited File

79
B-42 Appendix B Processing Time Series Data with SAS Enterprise Guide (Self-Study)

Use Column Options to


Manually Configure the Data

80

Column Zero Is Year

81
B.3 Changing the Frequency of Time Series Data B-43

Columns 1 through 12 Contain Values by


Month

82

Modify Column Names

83
B-44 Appendix B Processing Time Series Data with SAS Enterprise Guide (Self-Study)

Column 13 Contains the


Annual Unemployment Rate

84

By Default, the Resulting SAS Table Is


Placed in the WORK Library

85
B.3 Changing the Frequency of Time Series Data B-45

A View of the Imported Data

86

The Process Flow So Far

87
B-46 Appendix B Processing Time Series Data with SAS Enterprise Guide (Self-Study)

Save the New Project

88

Prepare the General Retail Data Table for


Forecasting

89
B.3 Changing the Frequency of Time Series Data B-47

DATE Is the Time ID Variable

90

Input Frequency Weekly Is Converted to


Output Frequency Monthly

91
B-48 Appendix B Processing Time Series Data with SAS Enterprise Guide (Self-Study)

An Approximate Conversion Must Be Used

Because weeks are not nested in months, an


interpolation method must be employed. Cubic spline
92 interpolation is the default.

The Converted Data Is Stored in a SAS Table

93
B.3 Changing the Frequency of Time Series Data B-49

The Process Flow

95

The Imported Data Is Converted to Time


Series Data Using the Transpose Task

96
B-50 Appendix B Processing Time Series Data with SAS Enterprise Guide (Self-Study)

Monthly Columns Are Transposed and


Grouped by Year

97

The New Columns Are Named

The Source column


that contains the old
column names will be
named Month.

The new column that


contains the old row
values will be named
UURate1.

98
B.3 Changing the Frequency of Time Series Data B-51

The Result Is a SAS Table

99

A View of the Transposed Data

100
B-52 Appendix B Processing Time Series Data with SAS Enterprise Guide (Self-Study)

Create a Time ID Variable for the


Transposed Data

101

The SAS INPUT Function Creates the Time ID

The SAS INPUT function uses existing variables and a


SAS display format to create the time ID variable.
102
B.3 Changing the Frequency of Time Series Data B-53

The Time ID Variable Is Named Date and


Associated with a Date Group

103

The YYMONw.d SAS Display Format Is Used

104
B-54 Appendix B Processing Time Series Data with SAS Enterprise Guide (Self-Study)

Columns Year and Month Are No Longer


Needed

continued...

105

Columns Year and Month Are No Longer


Needed

106
B.3 Changing the Frequency of Time Series Data B-55

Modify Properties of the


New Unemployment Rate Column

107

Change the Name and Add a Label

108
B-56 Appendix B Processing Time Series Data with SAS Enterprise Guide (Self-Study)

Assign a Numeric Display Format

109

A View of the Unemployment Rate Table

110
B.3 Changing the Frequency of Time Series Data B-57

The Process Flow

111

Use the Query Builder to Merge the Data

112
B-58 Appendix B Processing Time Series Data with SAS Enterprise Guide (Self-Study)

The Query Builder Opens for the


General Retail Data

Click the Add Data button to add the


Unadjusted Unemployment Rate data.

113

The Unemployment Rate Table Is Contained in


the Project

114
B.3 Changing the Frequency of Time Series Data B-59

You Must Specify How to Join the Tables

115

Connect the Date Variables

116
B-60 Appendix B Processing Time Series Data with SAS Enterprise Guide (Self-Study)

Right-Click to Modify the Join

117

Rows Are Matched by Date

118
B.3 Changing the Frequency of Time Series Data B-61

The New Output Table Is Created

119

A View of the Joined Table

120
B-62 Appendix B Processing Time Series Data with SAS Enterprise Guide (Self-Study)

The Final Process Flow

121

Export the Data for Forecast Projects

122
B.3 Changing the Frequency of Time Series Data B-63

Save the New Table on the Local Computer


with Name GRetail_URate_Monthly

123
B-64 Appendix B Processing Time Series Data with SAS Enterprise Guide (Self-Study)

Exercises

2. (Self-Study) The comma-delimited file MVAccidents.csv contains death rates per 100,000
persons in the United States. Use the techniques of this section to place this data in an appropriate
form for forecasting. You can view the file in the SAS program editor. The first row contains column
names.
3. (Self-Study) Data set FETS.SALEDATA contains weekly sales figures for a consumer retail
organization. Convert these weekly numbers to monthly values for variable SALESAMOUNT. Keep
only the two variables DATE and SALESAMOUNT in the new data set.
B.4 Augmenting Data with Event Variables B-65

B.4 Augmenting Data with Event Variables

Objectives
Show features of SAS Enterprise Guide for creating
event variables.
Provide examples of events and identify different types
of event effects.

126

The Events Project


Sample 100% of the Data

Modify the Sampled Data

127
B-66 Appendix B Processing Time Series Data with SAS Enterprise Guide (Self-Study)

The random sample task is an inefficient way to get a copy of the original data. Your only goal is to get a
copy of the data so that you do not modify the original data table. You could use the operating system to
create a copy, or you could use various SAS features to copy the data. Within SAS Enterprise Guide, you
could also create a query that returns all of the data. The above approach is for illustration to emphasize
that you almost always want to keep a clean copy of the original data.

Sampling 100% of the Data

128

Specifying 202 rows ensures that all of the data will be used for the new data table.
B.4 Augmenting Data with Event Variables B-67

Modify the New Data Table

Insert a column for a new Christmas event variable.

129

Name and Label the New Event Variable

130
B-68 Appendix B Processing Time Series Data with SAS Enterprise Guide (Self-Study)

Use SAS Functions and Boolean Logic to


Create a Christmas Indicator Variable

131

The new variable will take the value 1 when the week begins within 14 days before Christmas (December
11 through December 25).

General Properties of the New Event Variable

132
B.4 Augmenting Data with Event Variables B-69

Event Logic
month(Date)=12 Is the month December?

AND

11<=day(Date)<=25 Is the day of the month


between 11 and 25
inclusive?

Date Month Day Result #


21JUL2002 FALSE AND TRUE IS FALSE =0
07DEC2003 TRUE AND FALSE IS FALSE =0
21DEC2003 TRUE AND TRUE IS TRUE =1
133

SAS codes FALSE as zero (0) and TRUE as one (1). When reading Boolean values, SAS treats zero as
FALSE and any other number as TRUE.

A View of the Event Data with Christmas


Indicator

134
B-70 Appendix B Processing Time Series Data with SAS Enterprise Guide (Self-Study)

When you forecast beyond the end of the time series, you need to extend dates and events beyond the end
of the series. Event variables like the one defined above for Christmas are available at all past and future
values. Events that are subject to randomness, such as earthquakes, cannot be coded exactly for future
values, although it is common to perform a what-if analysis to see what the forecast would be if the event
occurs on a given date.

Add Rows in Update Mode

135
B.4 Augmenting Data with Event Variables B-71

A SAS Date Is a Number

136

Unfortunately, when you type in the value of the date for the appended record, you get an error message.

You Can Determine the SAS Number


Corresponding to a Date

21NOV2004=16396 days from 1JAN1960

137

Date is a numeric variable formatted to look like a date. You could calculate the numeric value
representing 21 November 2004.
B-72 Appendix B Processing Time Series Data with SAS Enterprise Guide (Self-Study)

SAS Conversion Informats Are Easier!

138

SAS informats make data entry much easier. Continue adding values to the new appended record.

Enter Known Values

139
B.4 Augmenting Data with Event Variables B-73

The Row Is Added to the Table

Missing values are


displayed as periods.

140

SAS Display Formats and


Conversion Informats
Using SAS
Format/Informat

You type 19DEC2004

SAS converts to 16424 DATE9.0

SAS displays as 12-19-2004 MMDDYY10.0

19DEC2004=16,424 days from 1JAN1960

141

By manually appending records that represent the future, you can predict future values of a target variable
for pre-specified event variables.
B-74 Appendix B Processing Time Series Data with SAS Enterprise Guide (Self-Study)

B.5 Chapter Summary


Time series data often originates as a set of transactions at non-equally spaced intervals. SAS Enterprise
Guide provides tools for processing transactions to create equally spaced time series data. Tools are also
provided for transposing data and changing the frequency of data. Event variables can be created using
Boolean logic or by manually modifying data. Data processing can consume 50% to 80% of a time series
forecasting project. SAS Enterprise Guide can make data processing easier and help reduce data
processing time.

For Additional Information


Tutorial: Getting Started with SAS Enterprise Guide
http://www.sas.com/apps/elearning/elearning_details.jsp?pubcode=59271
B.6 Solutions to Exercises B-75

B.6 Solutions to Exercises


1. Follow the example in section B.1.
2. Follow the examples in sections B.2 and B.3.
3. Follow the examples in section B.3. Because weeks are not nested in months, the interpolation is
approximate.
B-76 Appendix B Processing Time Series Data with SAS Enterprise Guide (Self-Study)
Appendix C Processing Time Series
Data with SAS Code (Self-Study)

C.1 Processing Time Stamped Transactional Data ........................................................... C-3

C.2 Transposing Data........................................................................................................... C-9

C.3 Changing the Frequency of Time Series Data .......................................................... C-13

C.4 Augmenting Data with Event Variables ..................................................................... C-20

C.5 Chapter Summary........................................................................................................ C-24


C-2 Appendix C Processing Time Series Data with SAS Code (Self-Study)
C.1 Processing Time Stamped Transactional Data C-3

C.1 Processing Time Stamped Transactional Data

Objectives
Process time stamped transactional data into equally
spaced time series data.
Work with SAS date, time, and datetime values,
formats, informats, and functions.

The code below prints the first 20 observations of the fets.ebay9810 data set.

title 'First 20 Observations';


proc print data=fets.ebay9810(obs=20);
run;

First 20 Observations

Obs Symbol DateTime Time Price Size Date

1 EBAY 01OCT98:09:24:35 9:24:35 43.000 400 01OCT1998


2 EBAY 01OCT98:09:26:45 9:26:45 43.000 200 01OCT1998
3 EBAY 01OCT98:09:27:00 9:27:00 43.000 200 01OCT1998
4 EBAY 01OCT98:09:30:11 9:30:11 42.625 1000 01OCT1998
5 EBAY 01OCT98:09:30:12 9:30:12 42.875 100 01OCT1998
6 EBAY 01OCT98:09:30:14 9:30:14 42.875 100 01OCT1998
7 EBAY 01OCT98:09:30:15 9:30:15 42.875 100 01OCT1998
8 EBAY 01OCT98:09:30:15 9:30:15 42.625 100 01OCT1998
9 EBAY 01OCT98:09:30:16 9:30:16 42.875 100 01OCT1998
10 EBAY 01OCT98:09:30:16 9:30:16 42.875 100 01OCT1998
11 EBAY 01OCT98:09:30:16 9:30:16 42.875 300 01OCT1998
12 EBAY 01OCT98:09:30:17 9:30:17 42.875 200 01OCT1998
13 EBAY 01OCT98:09:30:18 9:30:18 42.625 200 01OCT1998
14 EBAY 01OCT98:09:30:20 9:30:20 42.625 200 01OCT1998
15 EBAY 01OCT98:09:30:21 9:30:21 42.875 100 01OCT1998
C-4 Appendix C Processing Time Series Data with SAS Code (Self-Study)

16 EBAY 01OCT98:09:30:33 9:30:33 42.875 100 01OCT1998


17 EBAY 01OCT98:09:30:34 9:30:34 42.875 100 01OCT1998
18 EBAY 01OCT98:09:30:36 9:30:36 42.625 200 01OCT1998
19 EBAY 01OCT98:09:30:42 9:30:42 42.625 500 01OCT1998
20 EBAY 01OCT98:09:30:46 9:30:46 42.625 300 01OCT1998

The data is time-stamp data. Each trade is recorded at the time it is executed with the price and number of
shares in the size column.
These data need to be converted into a time series with equally spaced time IDs. The following code
converts the time-stamped transactional data to several time series that represent different summary
statistics for each day of trading. The summary statistics chosen are the daily high and low price, the
opening and closing price, and the volume of shares traded on each day.

* Accumulate transaction data into weekday time series;

* Identify DailyHigh;
proc timeseries data=fets.ebay9810
out=ebayhigh(rename=(price=DailyHigh));
var price;
id date interval=weekday accumulate=max;
run;

* Identify DailyLow;
proc timeseries data=fets.ebay9810
out=ebaylow(rename=(price=DailyLow));
var price;
id date interval=weekday accumulate=min;
run;

* Calculate Daily Volume;


proc timeseries data=fets.ebay9810
out=ebayvolume(rename=(size=Volume));
var size;
id date interval=weekday accumulate=total;
run;

* Identify Opening Price;


proc timeseries data=fets.ebay9810
out=ebayopen(rename=(price=OpeningPrice));
var price;
id date interval=weekday accumulate=first;
run;

* Identify Closing Price;


proc timeseries data=fets.ebay9810
out=ebayclose(rename=(price=ClosingPrice));
var price;
id date interval=weekday accumulate=last;
run;

* Create Ebay Time Series File;


C.1 Processing Time Stamped Transactional Data C-5

data ebayOct98;
merge ebayopen ebayhigh ebaylow ebayclose ebayvolume;
by date;
run;

title 'October 1998 Ebay Time Series Data';


proc print data=ebayOct98;
run;
PROC TIMESERIES is used to identify the chosen summary statistics that are each stored in a separated
file. The ACCUMULATE= statement is used to define which summary statistic is produced.
Because the market is closed on Saturdays and Sunday, the WEEKDAY interval is chosen. The final step
is to merge the separate times series into one file.
October 1998 Ebay Time Series Data

Opening Daily Daily Closing


Obs Date Price High Low Price Volume

1 01OCT1998 43.0000 43.2500 39.7500 39.7500 792200


2 02OCT1998 40.2500 41.7500 35.0000 40.0313 1754600
3 05OCT1998 39.3750 39.3750 34.8750 35.5000 597300
4 06OCT1998 36.2500 38.2500 32.0000 36.8750 714500
5 07OCT1998 35.5000 35.6250 30.5000 31.3750 624800
6 08OCT1998 30.0000 30.0000 25.2500 29.0000 1006300
7 09OCT1998 30.0000 32.2500 29.5000 30.8125 698500
8 12OCT1998 31.7500 32.0000 31.5000 31.5000 502500
9 13OCT1998 31.5625 31.7500 29.1250 29.3750 271600
10 14OCT1998 29.1250 32.1250 29.1250 30.0000 549100
11 15OCT1998 30.1250 33.0000 30.1250 32.1250 530300
12 16OCT1998 33.3750 36.5000 33.0000 36.0000 793500
13 19OCT1998 37.1875 46.0000 37.0000 45.1875 1408600
14 20OCT1998 46.6250 51.8750 45.2500 49.7500 2058700
15 21OCT1998 49.0000 51.5000 47.2500 50.5000 1152200
16 22OCT1998 51.6250 53.5000 49.2500 51.6250 947500
17 23OCT1998 51.6250 52.2500 49.5000 50.1250 572800
18 26OCT1998 52.0000 75.0000 52.0000 75.0000 6955500
19 27OCT1998 78.0000 90.8125 77.0000 81.0000 10153000
20 28OCT1998 81.1875 87.0000 76.2500 80.0000 4524500
21 29OCT1998 81.0000 82.9375 79.6094 80.2500 1442400
22 30OCT1998 79.7500 84.3750 79.7500 83.2500 1675900

Note that the dates exclude weekend days because of the WEEKDAY format used. However, any date for
which no transactions were recorded will also be missing. The next program and output illustrate this
point.
C-6 Appendix C Processing Time Series Data with SAS Code (Self-Study)

* Show that there is no row in the data for


26NOV1998, Thanksgiving';

title 'Ebay Data 16NOV1998-01DEC1998';


Proc print data=fets.ebayrawdaily;
where date between '16nov1998'd and '01dec1998'd;
run;

Ebay Data 16NOV1998-01DEC1998

Opening Daily Daily Closing


Obs Price High Low Price Volume DATE

38 43.1667 43.3333 40.7292 42.5417 1445200 16NOV1998


39 42.5000 44.3333 41.3333 42.8750 1430200 17NOV1998
40 43.5000 49.5000 41.7917 49.1667 3528200 18NOV1998
41 50.3333 51.7083 47.2708 47.9167 2384500 19NOV1998
42 50.0000 50.0000 46.7917 49.0000 1178700 20NOV1998
43 51.0000 65.1667 50.5625 64.3333 2850000 23NOV1998
44 63.0000 78.0417 59.3333 65.6042 6005400 24NOV1998
45 67.0000 71.4167 65.1667 68.1667 3429200 25NOV1998
46 70.3333 73.3750 69.0000 72.6667 1168500 27NOV1998
47 74.8125 75.0000 62.6667 65.8750 2380900 30NOV1998
48 62.3542 69.6667 60.6667 69.0833 2593200 01DEC1998

Note that 26Nov1998 is missing because the market was closed on Thanksgiving. This gap in the time ID
will be detected by the TSFS and give an error message. Time IDs must be equally spaced. The solution
to this problem is to insert time IDs for these dates with missing values for the time series values. The
next program illustrates the solution.
C.1 Processing Time Stamped Transactional Data C-7

Making Data Equally Spaced


The various stock exchanges are closed on holidays.
The stock exchanges have reduced hours on certain
days, such as the Friday after Thanksgiving in the
United States.
Even if you process stock transactions to create daily
values, some days will be missing.
While target variables and input variables can be
missing, dates cannot be missing or the data will not
be spaced equally.

* Insert dates for weekdays when market was closed;

proc expand data=fets.ebayrawdaily from=weekday to=weekday


out=ebay9899;
convert DailyHigh DailyLow OpeningPrice ClosingPrice Volume/
method=none;
id date;
run;

title 'Ebay Data 16NOV1998-01DEC1998 with Thanksgiving Date';


proc print data=fets.ebay9899;
where date between '16nov1998'd and '01dec1998'd;
run;
C-8 Appendix C Processing Time Series Data with SAS Code (Self-Study)

Ebay Data 16NOV1998-01DEC1998 with Thanksgiving Date

Opening Daily Daily Closing


Obs Price High Low Price Volume DATE

38 43.1667 43.3333 40.7292 42.5417 1445200 16NOV1998


39 42.5000 44.3333 41.3333 42.8750 1430200 17NOV1998
40 43.5000 49.5000 41.7917 49.1667 3528200 18NOV1998
41 50.3333 51.7083 47.2708 47.9167 2384500 19NOV1998
42 50.0000 50.0000 46.7917 49.0000 1178700 20NOV1998
43 51.0000 65.1667 50.5625 64.3333 2850000 23NOV1998
44 63.0000 78.0417 59.3333 65.6042 6005400 24NOV1998
45 67.0000 71.4167 65.1667 68.1667 3429200 25NOV1998
46 . . . . . 26NOV1998
47 70.3333 73.3750 69.0000 72.6667 1168500 27NOV1998
48 74.8125 75.0000 62.6667 65.8750 2380900 30NOV1998
49 62.3542 69.6667 60.6667 69.0833 2593200 01DEC1998

Notice that there is now a row for Thanksgiving, 26NOV1998. The TSFS can handle missing values but
not gaps in the time ID.
C.2 Transposing Data C-9

C.2 Transposing Data

Objectives
Use the PROC TRANSPOSE task to convert time
series values stored in rows to values stored in
columns.
Use the SAS code to modify data properties and apply
SAS display formats to time ID values.

Transposing Data
A common practice in sales tracking is to use a
spreadsheet to produce rows of summary sales data
for each department, with columns identifying specific
months.
The Time Series Forecasting System expects columns
to be time series variables and rows to correspond to
dates.
PROC TRANSPOSE allows you to convert data stored
as rows into data stored as columns.

7
C-10 Appendix C Processing Time Series Data with SAS Code (Self-Study)

title 'First 5 Observations';


proc print data=fets.cerow(obs=5);
run;
Here is a printout of the first five rows in the cerow data set.
First 5 Observations

Obs item JAN2002 FEB2002 MAR2002 APR2002 MAY2002

1 DC1-170-683264 319 388 190 493 431


2 DC1-170-718069 195 270 308 359 381
3 DC1-986-632422 33 37 23 3 171
4 DC1-603-448761 60 76 63 64 63
5 DC1-603-560613 680 612 665 651 732

Obs JUN2002 JUL2002 AUG2002 SEP2002 OCT2002 NOV2002 DEC2002

1 553 390 697 934 431 730 797


2 325 225 349 420 376 319 409
3 150 136 150 244 182 173 277
4 52 63 32 31 73 82 168
5 687 721 760 698 725 724 918

Obs JAN2003 FEB2003 MAR2003 APR2003 MAY2003 JUN2003 JUL2003

1 705 642 739 665 636 556 631


2 358 366 345 300 276 254 284
3 187 59 22 274 176 295 310
4 34 27 32 36 45 32 36
5 758 697 765 760 789 758 790

Obs AUG2003 SEP2003 OCT2003 NOV2003 DEC2003

1 620 706 669 524 628


2 287 304 304 233 362
3 416 512 457 330 535
4 17 22 29 40 -0
5 853 803 821 802 966

For each item, the sales are recorded in columns for each month.
The TSFS requires that the data be transposed so that each row is associated with each date and the
columns represent the separate products.
C.2 Transposing Data C-11

The following program accomplishes the necessary data manipulation:


proc sort data=fets.cerow out=cerow2;
by item;
run;

proc transpose data=cerow2 out=transout;


var Jan2002--Dec2003;
id item;
run;

title 'Raw Transposed Dataset';


proc print data=transout(obs=5);
run;
Below is partial output from the PROC PRINT.
Raw Transposed Dataset

DC1_170_ DC1_170_ DC1_170_ DC1_170_ DC1_456_ DC1_456_


Obs _NAME_ 545458 683264 718069 974499 469238 961898

1 JAN2002 242 319 195 191 202 231


2 FEB2002 6 388 270 42 30 53
3 MAR2002 24 190 308 14 157 220
4 APR2002 132 493 359 36 137 178
5 MAY2002 35 431 381 28 242 247

DC1_519_ DC1_603_ DC1_603_ DC1_826_ DC1_826_ DC1_873_ DC1_873_


Obs 294232 448761 560613 454731 685590 259002 812223

1 14 60 680 31 106 457 243


2 179 76 612 36 90 423 227
3 513 63 665 75 150 385 190
4 13 64 651 106 110 288 99
5 146 63 732 16 68 310 96

DC1_986_ DC2_170_ DC2_170_ DC2_170_ DC2_170_ DC2_456_ DC2_456_


Obs 632422 545458 683264 718069 974499 469238 961898

1 33 583 306 216 445 403 300


2 37 47 298 202 77 97 112
3 23 57 223 253 34 461 310
4 3 392 348 257 89 391 358
5 171 228 406 303 91 769 526
C-12 Appendix C Processing Time Series Data with SAS Code (Self-Study)

The date value under the label _NAME_ is a character variable. The next portion of the program creates
as SAS date value and deletes the character version.
data cecolumns(drop=_name_);
format date YYMON7.;
set transout;
date=input(_name_,monyy7.);
run;

title 'CECOLUMN Data Set';


proc print data=transout(obs=5);
run;
The input function converts the character variable _name_ to a numeric variable using the monyy7.
informat.
Here is partial output from PROC PRINT.
CECOLUMN Data Set

DC1_170_ DC1_170_ DC1_170_ DC1_170_ DC1_456_ DC1_456_


Obs date 545458 683264 718069 974499 469238 961898

1 2002JAN 242 319 195 191 202 231


2 2002FEB 6 388 270 42 30 53
3 2002MAR 24 190 308 14 157 220
4 2002APR 132 493 359 36 137 178
5 2002MAY 35 431 381 28 242 247

DC1_519_ DC1_603_ DC1_603_ DC1_826_ DC1_826_ DC1_873_ DC1_873_


Obs 294232 448761 560613 454731 685590 259002 812223

1 14 60 680 31 106 457 243


2 179 76 612 36 90 423 227
3 513 63 665 75 150 385 190
4 13 64 651 106 110 288 99
5 146 63 732 16 68 310 96

DC1_986_ DC2_170_ DC2_170_ DC2_170_ DC2_170_ DC2_456_ DC2_456_


Obs 632422 545458 683264 718069 974499 469238 961898

1 33 583 306 216 445 403 300


2 37 47 298 202 77 97 112
3 23 57 223 253 34 461 310
4 3 392 348 257 89 391 358
5 171 228 406 303 91 769 526
C.3 Changing the Frequency of Time Series Data C-13

C.3 Changing the Frequency of Time Series Data

Objectives
Describe situations where multiple time series must be
merged by time ID.
Show how PROC EXPAND can be used to convert
time series data from one frequency to another.

Combining Time Series Data Recorded at


Different Time Frequencies
Dynamic forecast models use input time series to
forecast target time series.
All of the series must be synchronized by date.
If different intervals are employed, interpolation or
aggregation is necessary to convert some of the
time series from one interval to another.
After conversion, the resulting tables can be merged
so that the one can be used as an input for dynamic
regression.

10
C-14 Appendix C Processing Time Series Data with SAS Code (Self-Study)

title 'First 15 Observations of the General Retail Dataset';


proc print data=fets.genretail(obs=15);
run;

Here is a partial listing of the general retail data.


First 15 Observations of the General Retail Dataset

Obs DATE PSUnits DGUnits

1 07JAN2001 1469604 1162465


2 14JAN2001 1423274 1031519
3 21JAN2001 1364800 1069500
4 28JAN2001 1489164 1054189
5 04FEB2001 1548546 1192984
6 11FEB2001 1413982 1057071
7 18FEB2001 1438682 1110855
8 25FEB2001 1549122 1091822
9 04MAR2001 1577593 1201956
10 11MAR2001 1543679 1076238
11 18MAR2001 1603629 1124774
12 25MAR2001 1563594 1035035
13 01APR2001 1717986 1156107
14 08APR2001 1599631 1201291
15 15APR2001 1591251 1071805

Note that the general retail data is weekly.


PROC IMPORT is used to create a SAS data set from a CSV values file.
* Import CSV file;

proc import out= work.impw6902


datafile= "C:\workshop\winsas\FETS\UnempRateUnadj90_05.csv"
dbms=CSV replace;
getnames=no;
datarow=1;
run;

title 'Unemployment Date with Default Column Names';


proc print data=impw6902(obs=5);
run;
C.3 Changing the Frequency of Time Series Data C-15

The default column names are not very informative. Column VAR1 contains the year. Columns VAR2
through VAR13 include the data for January through December. The column VAR14 is the annual rate.
Unemployment Date with Default Column Names

Obs VAR1 VAR2 VAR3 VAR4 VAR5

1 1990 6 5.9 5.5 5.3


2 1991 7.1 7.3 7.2 6.5
3 1992 8.1 8.2 7.8 7.2
4 1993 8 7.8 7.4 6.9
5 1994 7.3 7.1 6.8 6.2

Obs VAR6 VAR7 VAR8 VAR9 VAR10

1 5.2 5.4 5.6 5.5 5.6


2 6.7 7 6.8 6.6 6.5
3 7.3 8 7.7 7.4 7.3
4 6.8 7.2 7 6.6 6.4
5 5.9 6.2 6.2 5.9 5.6

Obs VAR11 VAR12 VAR13 VAR14

1 5.5 5.9 6 5.6


2 6.5 6.7 6.9 6.8
3 6.9 7.1 7.1 7.5
4 6.4 6.2 6.1 6.9
5 5.4 5.3 5.1 6.1

The columns are renamed using PROC DATASETS.


* Rename Default Column Names;

proc datasets library=work;


modify impw6902;
rename var1=year
var2=January
var3=February
var4=March
var5=April
var6=May
var7=June
var8=July
var9=August
var10=September
var11=October
var12=November
var13=December
var14=Annual;
run;

title 'Unemployment Dataset';


proc print data=impw6902(obs=5);
run;
C-16 Appendix C Processing Time Series Data with SAS Code (Self-Study)

Now the names are more meaningful.


Unemployment Dataset

Obs year January February March April

1 1990 6 5.9 5.5 5.3


2 1991 7.1 7.3 7.2 6.5
3 1992 8.1 8.2 7.8 7.2
4 1993 8 7.8 7.4 6.9
5 1994 7.3 7.1 6.8 6.2

Obs May June July August September

1 5.2 5.4 5.6 5.5 5.6


2 6.7 7 6.8 6.6 6.5
3 7.3 8 7.7 7.4 7.3
4 6.8 7.2 7 6.6 6.4
5 5.9 6.2 6.2 5.9 5.6

Obs October November December Annual

1 5.5 5.9 6 5.6


2 6.5 6.7 6.9 6.8
3 6.9 7.1 7.1 7.5
4 6.4 6.2 6.1 6.9
5 5.4 5.3 5.1 6.1

Note that the unemployment data is monthly while the retail data is weekly.

Changing Frequencies
A time interval (for example, weekly, monthly) is
associated with a frequency (for example, 52 values
per year, 12 values per year).
Weekly data is recorded at a higher frequency than
monthly data.
Time intervals can be nested (for example, exactly 7
days are in one week, exactly 12 months are in one
year). For nested intervals, aggregation can provide
exact results when converting to lower frequencies.
If time intervals are not nested (for example, weeks in
months, weeks in years), then conversion to a lower
frequency is approximate.
Interpolation from lower frequencies to higher
frequencies is always approximate.

11
C.3 Changing the Frequency of Time Series Data C-17

First convert the weekly data to monthly. The second step is to transpose the unemployment data. The
final step is to merge the two data sets to create the final analysis file.
proc expand data=fets.genretail from=week to=month
out=MonthlyRetail observed=(total,total);
convert PSunits DGunits;
id date;
run;

title 'Monthly General Retail Data';


proc print data=MonthlyRetail(obs=13);
run;
Here is partial output of the monthly retail data.
Monthly General Retail Data

Obs DATE PSUnits DGUnits

1 JAN2001 6186885.45 5353825.95


2 FEB2001 5933087.60 4442022.62
3 MAR2001 6963464.09 4916015.99
4 APR2001 7041131.29 4938364.85
5 MAY2001 7603774.57 5140901.36
6 JUN2001 8009789.14 5214016.78
7 JUL2001 7694409.79 5252386.33
8 AUG2001 8700013.17 5716203.49
9 SEP2001 8334787.21 5867668.60
10 OCT2001 9402228.01 6573922.16
11 NOV2001 9150608.24 6486436.86
12 DEC2001 9291927.75 6674101.22
13 JAN2002 9727955.96 6809275.67

Notice that the monthly aggregation of the weekly data is not integers. The noninteger values are because
of the approximation technique used by PROC EXPAND. You could round the values to integer if
desired in a DATA step.
The following code transposes the unemployment data and creates a final file with a SAS date value for
the time ID. The printout of the raw file is not shown.
* Transpose Unemployment;

proc transpose data=impw6902 out=unempdata;


by year;
run;

title 'Raw Transposed Unemployment Data';


proc print data=unempdata;
run;
;

* Rename col1 as UURate1 ;


* Create SAS date value from month and year variables;
* Drop rows with annual rate;
* Keep only date and UERate1;
C-18 Appendix C Processing Time Series Data with SAS Code (Self-Study)

data unempdata(keep=date UURate1);


format date yymon7.;
set unempdata(rename=(col1=UURate1));
if _name_ ne 'Annual';
date=input(substr(_name_,1,3)||put(year,$4.),monyy7.);
run;

title 'Polished Transposed Unemployment Data';


proc print data=unempdata;
run;
Here is a partial listing of the polished unemployment data.
Polished Transposed Unemployment Data

Obs date UURate1

1 1990JAN 6
2 1990FEB 5.9
3 1990MAR 5.5
4 1990APR 5.3
5 1990MAY 5.2
6 1990JUN 5.4
7 1990JUL 5.6
8 1990AUG 5.5
9 1990SEP 5.6
10 1990OCT 5.5
11 1990NOV 5.9
12 1990DEC 6
13 1991JAN 7.1
14 1991FEB 7.3
15 1991MAR 7.2
16 1991APR 6.5
17 1991MAY 6.7
18 1991JUN 7
19 1991JUL 6.8
20 1991AUG 6.6

Notice that the unemployment data begins much before the current retail data. Consequently, when the
unemployment data is merged with the retail data below, you include only unemployment data during the
range of the retail data.
* Merge Unemployment data to general retail data. ;

data GRetail_Urate_Monthly;
merge MonthlyRetail(in=inretail) Unempdata;
by date;
if inretail;
run;

title 'General Retail Data with Unemployment Rate';


proc print data=GRetail_Urate_Monthly;
run;
C.3 Changing the Frequency of Time Series Data C-19

Partial listing of the final data set.


General Retail Data with Unemployment Rate

Obs DATE PSUnits DGUnits UURate1

1 JAN2001 6186885.45 5353825.95 4.7


2 FEB2001 5933087.60 4442022.62 4.6
3 MAR2001 6963464.09 4916015.99 4.5
4 APR2001 7041131.29 4938364.85 4.2
5 MAY2001 7603774.57 5140901.36 4.1
6 JUN2001 8009789.14 5214016.78 4.7
7 JUL2001 7694409.79 5252386.33 4.7
8 AUG2001 8700013.17 5716203.49 4.9
9 SEP2001 8334787.21 5867668.60 4.7
10 OCT2001 9402228.01 6573922.16 5
11 NOV2001 9150608.24 6486436.86 5.3
12 DEC2001 9291927.75 6674101.22 5.4
13 JAN2002 9727955.96 6809275.67 6.3
14 FEB2002 9131924.11 6222051.23 6.1
15 MAR2002 11130402.64 7414744.83 6.1
C-20 Appendix C Processing Time Series Data with SAS Code (Self-Study)

C.4 Augmenting Data with Event Variables

Objectives
Show how to create event variables in SAS code.
Show how to extend event variables into the future for
forecasting.

13

Event Logic
month(Date)=12 Is the month December?

AND

11<=day(Date)<=25 Is the day of the month


between 11 and 25
inclusive?

Date Month Day Result #


21JUL2002 FALSE AND TRUE IS FALSE =0
07DEC2003 TRUE AND FALSE IS FALSE =0
21DEC2003 TRUE AND TRUE IS TRUE =1
14
C.4 Augmenting Data with Event Variables C-21

The program below implements the above logic to define the Christmas event variable.
* Add a Christmas Event variable to the
General Retail data.;

* Christmas is defined to be weeks starting


between Dec 11 and Dec 25.;

data GenRetailEvent;
set fets.GenRetail;
if (month(date)=12 and (11 le day(date) le 25))
then Christmas=1;
else Christmas=0;
run;

title 'December Weeks with Christmas Variable';


proc print data=GenRetailEvent;
where month(date)=12;
run;
Output showing the Christmas event variable added to the data set.
December Weeks with Christmas Variable

Obs DATE PSUnits DGUnits Christmas

48 02DEC2001 2244991 1584696 0


49 09DEC2001 2369021 1722342 0
50 16DEC2001 1829552 1316690 1
51 23DEC2001 1973506 1422175 1
52 30DEC2001 2100746 1559736 0
100 01DEC2002 3246212 2311164 0
101 08DEC2002 3258548 2427740 0
102 15DEC2002 2954631 2408430 1
103 22DEC2002 2456986 1946951 1
104 29DEC2002 2591363 1809073 0
153 07DEC2003 4358134 3081776 0
154 14DEC2003 4463008 2928776 1
155 21DEC2003 3279413 2142082 1
156 28DEC2003 4001218 2325820 0

Other months are not shown. The Christmas variable is 0 for all other months.
For forecast to reflect the effect of an event variable, the event variable must be defined for all time
periods in the forecast horizon. The following program illustrates how one can append future values of
the Christmas event variable to the analysis data set.
* Appended future values of the Christmas variable for
Forecasting.;

data GenRetailEvent(drop=lastdate);
set fets.GenRetail end=eof;
if (month(date)=12 and (11 le day(date) le 25))
then Christmas=1;
else Christmas=0;
C-22 Appendix C Processing Time Series Data with SAS Code (Self-Study)

output;
if eof=1 then do while (date le '01jan2005'd);
lastdate=date;
PSUnits=.;
DGUnits=.;
date=intnx('week',lastdate,1);
if (month(date)=12 and (11 le day(date) le 25))
then Christmas=1;
else Christmas=0;
output;
end;
run;

title 'General Retail Data with Future Christmas Event Defined';


proc print data=GenRetailEvent;
where date ge '01oct2004'd;
run;
The END option is a flag that equals one when the last observation is read from the input data set.
Consequently, the DO-WHILE group is executed only when the input data set has been read completely.
The loop appends a record for each week from the last week in the input dataset until 1 January 2005.
The values of the retail series are set to missing.
Here is a listing of the last three months of the data set.
General Retail Data with Future Christmas Event Defined

Obs DATE PSUnits DGUnits Christmas

196 03OCT2004 5383896 3699786 0


197 10OCT2004 5364075 3715727 0
198 17OCT2004 5036930 3408898 0
199 24OCT2004 5938714 4149982 0
200 31OCT2004 5866577 3822875 0
201 07NOV2004 6184032 4411890 0
202 14NOV2004 5222806 3975664 0
203 21NOV2004 . . 0
204 28NOV2004 . . 0
205 05DEC2004 . . 0
206 12DEC2004 . . 1
207 19DEC2004 . . 1
208 26DEC2004 . . 0
209 02JAN2005 . . 0

Many display formats are available in SAS.


C.4 Augmenting Data with Event Variables C-23

SAS Display Formats and


Conversion Informats
Using SAS
Format/Informat

You type 19DEC2004

SAS converts to 16424 DATE9.0

SAS displays as 12-19-2004 MMDDYY10.0

19DEC2004=16,424 days from 1JAN1960


15
C-24 Appendix C Processing Time Series Data with SAS Code (Self-Study)

C.5 Chapter Summary


Time series data often originates as a set of transactions at non-equally spaced intervals. SAS provides
tools for processing transactions to create equally spaced time series data. Tools are also provided for
transposing data and changing the frequency of data. Event variables can be created using Boolean logic
or by manually modifying data. Data processing can consume 50% to 80% of a time series forecasting
project. SAS code can make data processing easier and help reduce data processing time.
Appendix D Index
processing time stamped transactional
A data, B-3B-21
transposing, B-23B-36, C-9C-12
abrupt
data processing
permanent effect, 5-195-20
transactional data, C-3C-8
temporary effect, 5-165-19
detrending, 1-591-60
accuracy statistic, 1-671-69
diagnostic statistic
additive decomposition
model, 1-721-76
examples, 1-631-65
diagnostic statistics, 1-111-12
additive decomposition model, 1-56
Dickey-Fuller
autocorrelation function (ACF), 3-43-10, 3-
unit root test, 1-89
183-20
differencing
autocorrelation plots and functions, 1-841-
notation for trend and seasonality, 4-8
87
stochastic seasonal functions, 4-6
Automatic Model Fitting Results window, 1-
stochastic trend functions, 1-481-49, 4-
33
44-5
Automatic Model Fitting Window, 1-291-31
dynamic regression, 5-655-69
autoregressive models, 3-143-20
autoregressive moving average model
E
identifying appropriate, 3-233-59
estimation methods, 3-613-105
B event models, 5-145-55
event variables
Box-Jenkins
augment data, B-65B-73
ARMA models, 3-103-13
augmenting data, C-20C-23
forecasting, 3-33-13
events, 2-552-74
methodology for dynamic regression, 5-65
changes in levels and trends, 2-632-68
modeling methodology, 3-26
effects of, 2-692-74
seasonal model, 4-474-49
exponential smoothing models, 2-85, 2-79
time series regression model, 5-575-59
2-97, 2-792-97
trend model, 4-13
trends and seasonal components, 2-972-
business forecasting, 1-31-40
107
business forecasting by industry, 1-381-40
F
C
forecasting
cross-correlation function, 5-665-68
environments using SAS, 1-18, 1-19
D using SAS Enterprise Guide, A-3A-26
forecasting methods, 3-613-105
data forecasts
augmenting with event variables, B-65 choosing, 1-10
B-73, C-20C-23 frequencies
importing, A-5A-9 changing, C-13C-19
plotting with SAS Enterprise Guide, A-
13A-15 G
preparing for forecasting, A-11A-12
general rational transfer function, 5-10
gradual
D-2 Index

permanent effect, 5-215-22 T


time series analysis
H
events, 2-552-74
holdout sample time series data
choosing, 1-15, 1-16 analysis, 1-771-100
changing frequency, B-38B-62, C-13C-
I 19
irregular component, 1-58 time series forecasting, 1-411-70
time series forecasting system
M comparison with SAS Enterprise Guide,
A-25A-26
measuring forecast accuracy, 1-711-76 Time Series Forecasting System (TSFS), 1-
mixed decomposition model, 1-57 231-27
Model Selection Criteria window, 1-301-31 functionality, 1-771-85
Model Viewer, 1-341-35 time series regression, 5-85-9
modeling time series regression models, 5-575-81
trend, 2-32-32 Time Series Viewer, 1-28
modeling nonstationary time series, 4-34-4 time stamped transactional data
moving average models, 3-213-22 processing, B-3B-21, C-3C-8
multiple linear regression models, 5-35-7 transfer function, 5-605-65
multiplication decomposition model, 1-57 transposing
data, B-23B-36, C-9C-12
R trend
regression detecting with the TSFS, 4-144-16
time series, 5-85-9 deterministic, 2-32-4
regression models, 5-35-13 diagnosing, 1-92
regressors in time series, 1-461-49
types, 5-105-13 modeling, 2-72-15
residual analysis models, 2-72-15
example, 1-66 stochastic, 2-32-4
trend and seasonality
S detect with the TSFS, 4-504-51
Trend Models, 4-104-46
SAS Enterprise Guide, 1-351-37
basic forecasting, A-1A-26 U
comparison with the time series
forecasting system, A-26 universal time series model, 1-541-56
SAS windowing environment, 1-191-24
seasonal differencing W
stochastic seasonal functions, 1-55 weighted averages
seasonal models, 2-352-40, 4-474-83 exponential smoothing, 2-772-78
seasonality, 2-342-53 white noise
diagnosing, 1-93 testing for, 1-88
examples, 1-601-62 Winters Additive model assessment, 2-107
in time series, 1-501-54
Series Selection window, 1-261-28 Y
smoothing
types, 2-792-84 Yule-Walker equations, 3-17
stationary time series, 3-33-4
statistical time series, 1-431-44

Potrebbero piacerti anche