This book gives the reader a step-by-step introduction to analyzing time series using the open source software R. Each time series model is illustrated through practical applications addressing contemporary issues, and is defined in mathematical notation.
Rhasacommandlineinterfacethato?ersconsiderableadvantagesovermenu systemsintermsofe?ciencyandspeedoncethecommandsareknownandthe languageunderstood. However,thecommandlinesystemcanbedauntingfor the?rst-timeuser,sothereisaneedforconcisetextstoenablethestudentor analysttomakeprogresswithRintheirareaofstudy. Thisbookaimstoful?l thatneedintheareaoftimeseries toenablethenon-specialisttoprogress, atafairlyquickpace,toalevelwheretheycancon?dentlyapplyarangeof timeseriesmethodstoavarietyofdatasets. Thebookassumesthereader hasaknowledgetypicalofa?rst-yearuniversitystatisticscourseandisbased aroundlecturenotesfromarangeoftimeseriescoursesthatwehavetaught overthelasttwentyyears. Someofthismaterialhasbeendeliveredtopo- graduate?nancestudentsduringaconcentratedsix-weekcourseandwaswell received,soaselectionofthematerialcouldbemasteredinaconcentrated course,althoughingeneralitwouldbemoresuitedtobeingspreadovera completesemester. Thebookisbasedaroundpracticalapplicationsandgenerallyfollowsa similar format for each time series model being studied. First, there is an introductory motivational section that describes practical reasons why the modelmaybeneeded. Second,themodelisdescribedandde?nedinma- ematicalnotation. Themodelisthenusedtosimulatesyntheticdatausing Rcodethatcloselyre?ectsthemodelde?nitionandthen?ttedtothes- theticdatatorecovertheunderlyingmodelparameters. Finally,themodel is?ttedtoanexamplehistoricaldatasetandappropriatediagnosticplots given. By using R, the whole procedure can be reproduced by the reader, 1 anditisrecommendedthatstudentsworkthroughmostoftheexamples. Mathematical derivations are provided in separate frames and starred sec- 1 WeusedtheRpackageSweavetoensurethat,ingeneral,yourcodewillproduce thesameoutputasours. However,forstylisticreasonswesometimeseditedour code;e. g. ,fortheplotstherewillsometimesbeminordi?erencesbetweenthose generatedbythecodeinthetextandthoseshownintheactual?gures. vii viii Preface tionsandcanbeomittedbythosewantingtoprogressquicklytopractical applications. Attheendofeachchapter,aconcisesummaryoftheRc- mands that were used is given followed by exercises. All data sets used in thebook,andsolutionstotheoddnumberedexercises,areavailableonthe websitehttp://www. massey. ac. nz/?pscowper/ts. WethankJohnKimmelofSpringerandtheanonymousrefereesfortheir helpfulguidanceandsuggestions,BrianWebbyforcarefulreadingofthetext andvaluablecomments,andJohnXieforusefulcommentsonanearlierdraft. TheInstituteofInformationandMathematicalSciencesatMasseyUniv- sity and the School of Mathematical Sciences, University of Adelaide, are acknowledgedforsupportandfundingthatmadeourcollaborationpossible. Paul thanks his wife, Sarah, for her continual encouragement and support duringthewritingofthisbook,andourson,Daniel,anddaughters,Lydia andLouise,forthejoytheybringtoourlives. AndrewthanksNataliefor providinginspirationandherenthusiasmfortheproject. PaulCowpertwaitandAndrewMetcalfe MasseyUniversity,Auckland,NewZealand UniversityofAdelaide,Australia December2008 Contents Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii 1 TimeSeriesData. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1. 1 Purpose. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1. 2 Timeseries. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1. 3 Rlanguage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1. 4 Plots,trends,andseasonalvariation . . . . . . . . . . . . . . . . . . . . . . . 4 1. 4. 1 A?yingstart:Airpassengerbookings. . . . . . . . . . . . . . . . 4 1. 4. 2 Unemployment:Maine. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 1. 4. 3 Multipletimeseries:Electricity,beerandchocolatedata 10 1. 4. 4 Quarterlyexchangerate:GBPtoNZdollar. . . . . . . . . . . 14 1. 4. 5 Globaltemperatureseries . . . . . . . . .