Table Of ContentG A L I T S H M U E L I
K E N N E T H C. L I C H T E N DA H L J R .
P R A C T I C A L
T I M E S E R I E S
F O R E C A S T I N G
W I T H R
A H A N D S - O N G U I D E
SECOND EDITION
AXELROD SCHNALL PUBLISHERS
Copyright©2016GalitShmueli&KennethC.LichtendahlJr.
published by axelrod schnall publishers
isbn-13: 978-0-9978479-1-8
isbn-10: 0-9978479-1-3
Coverart: PunakhaDzong,Bhutan. Copyright©2016BoazShmueli
ALLRIGHTSRESERVED.Nopartofthisworkmaybeusedorreproduced,transmitted,
storedorusedinanyformorbyanymeansgraphic,electronic,ormechanical,includingbut
notlimitedtophotocopying,recording,scanning,digitizing,taping,Webdistribution,infor-
mationnetworksorinformationstorageandretrievalsystems,orinanymannerwhatsoever
withoutpriorwrittenpermission.
Forfurtherinformationseewww.forecastingbook.com
SecondEdition,July2016
Contents
Preface 9
1 ApproachingForecasting 15
1.1 Forecasting: Where? . . . . . . . . . . . . . . . . . . 15
1.2 BasicNotation . . . . . . . . . . . . . . . . . . . . . . 15
1.3 TheForecastingProcess . . . . . . . . . . . . . . . . 16
1.4 GoalDefinition . . . . . . . . . . . . . . . . . . . . . 18
1.5 Problems . . . . . . . . . . . . . . . . . . . . . . . . . 23
2 TimeSeriesData 25
2.1 DataCollection . . . . . . . . . . . . . . . . . . . . . 25
2.2 TimeSeriesComponents . . . . . . . . . . . . . . . . 28
2.3 VisualizingTimeSeries. . . . . . . . . . . . . . . . . 30
2.4 InteractiveVisualization . . . . . . . . . . . . . . . . 35
2.5 DataPre-Processing. . . . . . . . . . . . . . . . . . . 39
2.6 Problems . . . . . . . . . . . . . . . . . . . . . . . . . 42
3 PerformanceEvaluation 45
3.1 DataPartitioning . . . . . . . . . . . . . . . . . . . . 45
3.2 NaiveForecasts . . . . . . . . . . . . . . . . . . . . . 50
3.3 MeasuringPredictiveAccuracy . . . . . . . . . . . . 51
3.4 EvaluatingForecastUncertainty . . . . . . . . . . . 55
3.5 AdvancedDataPartitioning: Roll-ForwardValidation 62
3.6 Example: ComparingTwoModels . . . . . . . . . . 65
3.7 Problems . . . . . . . . . . . . . . . . . . . . . . . . . 67
4 ForecastingMethods: Overview 69
4.1 Model-Basedvs. Data-DrivenMethods . . . . . . . 69
4
4.2 ExtrapolationMethods,EconometricModels,andEx-
ternalInformation . . . . . . . . . . . . . . . . . . . 70
4.3 Manualvs. AutomatedForecasting . . . . . . . . . 72
4.4 CombiningMethodsandEnsembles . . . . . . . . . 73
4.5 Problems . . . . . . . . . . . . . . . . . . . . . . . . . 77
5 SmoothingMethods 79
5.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . 79
5.2 MovingAverage . . . . . . . . . . . . . . . . . . . . . 80
5.3 Differencing . . . . . . . . . . . . . . . . . . . . . . . 85
5.4 SimpleExponentialSmoothing . . . . . . . . . . . . 87
5.5 AdvancedExponentialSmoothing . . . . . . . . . . 90
5.6 SummaryofExponentialSmoothinginRUsingets 98
5.7 ExtensionsofExponentialSmoothing . . . . . . . . 101
5.8 Problems . . . . . . . . . . . . . . . . . . . . . . . . . 107
6 RegressionModels: Trend&Seasonality 117
6.1 ModelwithTrend . . . . . . . . . . . . . . . . . . . . 117
6.2 ModelwithSeasonality . . . . . . . . . . . . . . . . 125
6.3 ModelwithTrendandSeasonality . . . . . . . . . . 129
6.4 CreatingForecastsfromtheChosenModel . . . . . 132
6.5 Problems . . . . . . . . . . . . . . . . . . . . . . . . . 133
7 RegressionModels: Autocorrelation&ExternalInfo 143
7.1 Autocorrelation . . . . . . . . . . . . . . . . . . . . . 143
7.2 ImprovingForecastsbyCapturingAutocorrelation:
ARandARIMAModels . . . . . . . . . . . . . . . . 147
7.3 EvaluatingPredictability . . . . . . . . . . . . . . . . 153
7.4 IncludingExternalInformation . . . . . . . . . . . . 154
7.5 Problems . . . . . . . . . . . . . . . . . . . . . . . . . 170
8 ForecastingBinaryOutcomes 179
8.1 ForecastingBinaryOutcomes . . . . . . . . . . . . . 179
8.2 NaiveForecastsandPerformanceEvaluation . . . . 180
8.3 LogisticRegression . . . . . . . . . . . . . . . . . . . 181
8.4 Example: RainfallinMelbourne,Australia . . . . . 183
8.5 Problems . . . . . . . . . . . . . . . . . . . . . . . . . 187
9 NeuralNetworks 189
5
9.1 NeuralNetworksforForecastingTimeSeries . . . . 189
9.2 TheNeuralNetworkModel . . . . . . . . . . . . . . 190
9.3 Pre-Processing . . . . . . . . . . . . . . . . . . . . . . 194
9.4 UserInput . . . . . . . . . . . . . . . . . . . . . . . . 195
9.5 ForecastingwithNeuralNetsinR . . . . . . . . . . 196
9.6 Example: ForecastingAmtrakRidership. . . . . . . 198
9.7 Problems . . . . . . . . . . . . . . . . . . . . . . . . . 201
10 CommunicationandMaintenance 203
10.1 PresentingForecasts . . . . . . . . . . . . . . . . . . 203
10.2 MonitoringForecasts . . . . . . . . . . . . . . . . . . 205
10.3 WrittenReports . . . . . . . . . . . . . . . . . . . . . 206
10.4 KeepingRecordsofForecasts . . . . . . . . . . . . . 207
10.5 AddressingManagerial"ForecastAdjustment" . . . 208
11 Cases 211
11.1 ForecastingPublicTransportationDemand . . . . . 211
11.2 ForecastingTourism(2010Competition,PartI) . . . 215
11.3 ForecastingStockPriceMovements(2010INFORMS
Competition). . . . . . . . . . . . . . . . . . . . . . . 219
DataResources,Competitions,andCodingResources 225
Bibliography 227
Index 231
7
To Boaz Shmueli, who made the production
of the Practical Analytics book series
a reality
Preface
Thepurposeofthistextbookistointroducethereadertoquan-
titativeforecastingoftimeseriesinapracticalandhands-on
fashion. Mostpredictiveanalyticscoursesindatascienceand
businessanalyticsprogramstouchverylightlyontimeseries
forecasting,ifatall. Yet,forecastingisextremelypopularand
usefulinpractice.
Fromourexperience,learningisbestachievedbydoing.
Hence,thebookisdesignedtoachieveself-learninginthefol-
lowingways:
• Thebookisrelativelyshortcomparedtoothertimeseries
textbooks,toreducereadingtimeandincreasehands-ontime.
• Explanationsstrivetobeclearandstraightforwardwithmore
emphasisonconceptsthanonstatisticaltheory.
• Chaptersincludeend-of-chapterproblems,ranginginfocus
fromconceptualtohands-onexercises,withmanyrequiring
runningsoftwareonrealdataandinterpretingtheoutputin
lightofagivenproblem.
• Realdataisusedtoillustratethemethodsthroughoutthe
book.
• Thebookemphasizestheentireforecastingprocessratherthan
focusingonlyonparticularmodelsandalgorithms.
• Casesaregiveninthelastchapter,guidingthereaderthrough
suggestedsteps,butallowingself-solution. Workingonthe
caseshelpsintegratetheinformationandexperiencegained.
10
Course Plan
Thebookwasdesignedforaforecastingcourseatthegradu-
ateorupper-undergraduatelevel. Itcanbetaughtinamini-
semester(6-7weeks)orasasemester-longcourse,usingthe
casestointegratethelearningfromdifferentchapters. Asug-
gestedscheduleforatypicalcourseis:
Week1 Chapters1("ApproachingForecasting")and2("Data")
covergoaldefinition;datacollection,characterization,visualiza-
tion,andpre-processing.
Week2 Chapter3("PerformanceEvaluation")coversdatapar-
titioning,naiveforecasts,measuringpredictiveaccuracyand
uncertainty.
Weeks3-4 Chapter4("ForecastingMethods: Overview")de-
scribesandcomparesdifferentapproachesunderlyingforecast-
ingmethods. Chapter5("SmoothingMethods")coversmoving
average,exponentialsmoothing,anddifferencing.
Weeks5-6 Chapters6("RegressionModels: TrendandSeason-
ality")and7("RegressionModels: AutocorrelationandExternal
Information")coverlinearregressionmodels,autoregressive
(AR)andARIMAmodels,andmodelingexternalinformationas
predictorsinaregressionmodel.
Week7 Chapter10("CommunicationandMaintenance")dis-
cussespracticalissuesofpresenting,reporting,documentingand
monitoringforecasts. Thisweekisagoodpointforproviding
feedbackonacaseanalysisfromChapter11.
Week8(optional) Chapter8("ForecastingBinaryOutcomes")
expandsforecastingtobinaryoutcomes,andintroducesthe
methodoflogisticregression.
Week9(optional) Chapter9("NeuralNetworks")introduces
neuralnetworksforforecastingbothcontinuousandbinary
outcomes.
Description:PRACTICAL TIME SERIES FORECASTING WITH R: A HANDS-ON GUIDE, SECOND EDITION provides an applied approach to time-series forecasting. Forecasting is an essential component of predictive analytics. The book introduces popular forecasting methods and approaches used in a variety of business applications