Table Of Content0.875”
D Basic Data Analysis
e
r
r
y
b for Time Series with R
e
r
r
y
DeWayne R. Derryberry
Presents modern methods to analyzing data
with multiple applications in a variety of scientific fields
Written at a readily accessible level, Basic Data Analysis for Time Series with R emphasizes
B
the mathematical importance of collaborative analysis of data used to collect increments of
a
time or space. Balancing a theoretical and practical approach to analyzing data within the
s
context of serial correlation, the book presents a coherent and systematic regression-based i
c
approach to model selection. The book illustrates these principles of model selection and
D
model building through the use of information criteria, cross validation, hypothesis tests, and
confidence intervals. a
t
a
Focusing on frequency- and time-domain and trigonometric regression as the primary themes,
A
the book also includes modern topical coverage on Fourier series and Akaike’s Information
n
Criterion (AIC). In addition, Basic Data Analysis for Time Series with R also features: a
l
y
• Real-world examples to provide readers with practical hands-on experience
s
• Multiple R software subroutines employed with graphical displays is
• Numerous exercise sets intended to support readers understanding of the core concepts f
o
• Specific chapters devoted to the analysis of the Wolf sunspot number data and the Vostok r
ice core data sets T
i
m
Basic Data Analysis for Time Series with R is an ideal textbook for upper-undergraduate and
e
beginning graduate-level courses using time series analysis as well as a useful reference for
practicing statisticians and scientists. S
e
r
i
e
DeWayne R. Derryberry, PhD, is Associate Professor in the Department of Mathematics s
and Statistics at Idaho State University. Dr. Derryberry has published more than a dozen w
journal articles and his research interests include meta-analysis, discriminant analysis with messy i
t
data, time series analysis of the relationship between several cancers, and geographically h
weighted regression. R
Cover Design: Wiley
Cover Image: © iStockphoto/vlastas
Graph: Courtesy of the author
Subscribe to our free Statistics eNewsletter at
wiley.com/enewsletters
Visit wiley.com/statistics
Also available
as an e-book
JWST451-fm JWST451-Derryberry May23,2014 10:39 PrinterName: Trim:6.125in×9.25in
ii
JWST451-fm JWST451-Derryberry May23,2014 10:39 PrinterName: Trim:6.125in×9.25in
BASIC DATA
ANALYSIS FOR TIME
SERIES WITH R
i
JWST451-fm JWST451-Derryberry May23,2014 10:39 PrinterName: Trim:6.125in×9.25in
ii
JWST451-fm JWST451-Derryberry May23,2014 10:39 PrinterName: Trim:6.125in×9.25in
BASIC DATA
ANALYSIS FOR TIME
SERIES WITH R
DEWAYNER.DERRYBERRY
DepartmentofMathematicsandStatistics
IdahoStateUniversity
Boise,ID
iii
JWST451-fm JWST451-Derryberry May23,2014 10:39 PrinterName: Trim:6.125in×9.25in
Copyright©2014byJohnWiley&Sons,Inc.Allrightsreserved.
PublishedbyJohnWiley&Sons,Inc.,Hoboken,NewJersey.
PublishedsimultaneouslyinCanada.
Nopartofthispublicationmaybereproduced,storedinaretrievalsystem,ortransmittedinanyformor
byanymeans,electronic,mechanical,photocopying,recording,scanning,orotherwise,exceptas
permittedunderSection107or108ofthe1976UnitedStatesCopyrightAct,withouteithertheprior
writtenpermissionofthePublisher,orauthorizationthroughpaymentoftheappropriateper-copyfeeto
theCopyrightClearanceCenter,Inc.,222RosewoodDrive,Danvers,MA01923,(978)750-8400,
fax(978)750-4470,oronthewebatwww.copyright.com.RequeststothePublisherforpermission
shouldbeaddressedtothePermissionsDepartment,JohnWiley&Sons,Inc.,111RiverStreet,Hoboken,
NJ07030,(201)748-6011,fax(201)748-6008,oronlineathttp://www.wiley.com/go/permission.
LimitofLiability/DisclaimerofWarranty:Whilethepublisherandauthorhaveusedtheirbesteffortsin
preparingthisbook,theymakenorepresentationsorwarrantieswithrespecttotheaccuracyor
completenessofthecontentsofthisbookandspecificallydisclaimanyimpliedwarrantiesof
merchantabilityorfitnessforaparticularpurpose.Nowarrantymaybecreatedorextendedbysales
representativesorwrittensalesmaterials.Theadviceandstrategiescontainedhereinmaynotbesuitable
foryoursituation.Youshouldconsultwithaprofessionalwhereappropriate.Neitherthepublishernor
authorshallbeliableforanylossofprofitoranyothercommercialdamages,includingbutnotlimitedto
special,incidental,consequential,orotherdamages.
Forgeneralinformationonourotherproductsandservicesorfortechnicalsupport,pleasecontactour
CustomerCareDepartmentwithintheUnitedStatesat(800)762-2974,outsidetheUnitedStatesat
(317)572-3993orfax(317)572-4002.
Wileyalsopublishesitsbooksinavarietyofelectronicformats.Somecontentthatappearsinprintmay
notbeavailableinelectronicformats.FormoreinformationaboutWileyproducts,visitourwebsiteat
www.wiley.com.
LibraryofCongressCataloging-in-PublicationData:
Derryberry,DeWayneR.,author.
BasicdataanalysisfortimeserieswithR/DeWayneR.Derryberry,DepartmentofMathematicsand
Statistics,IdahoStateUniversity,Voise,ID.
pagescm
Includesbibliographicalreferencesandindex.
ISBN978-1-118-42254-0(hardback)
1.Time-seriesanalysis–Dataprocessing. 2.R(Computerprogramlanguage) I.Title.
QA280.D4752014
001.4′2202855133–dc23
2014007300
PrintedintheUnitedStatesofAmerica
ISBN:9781118422540
10 9 8 7 6 5 4 3 2 1
iv
JWST451-fm JWST451-Derryberry May23,2014 10:39 PrinterName: Trim:6.125in×9.25in
CONTENTS
PREFACE xv
ACKNOWLEDGMENTS xvii
PARTI BASICCORRELATIONSTRUCTURES
1 RBasics 3
1.1 GettingStarted, 3
1.2 SpecialRConventions, 5
1.3 CommonStructures, 5
1.4 CommonFunctions, 6
1.5 TimeSeriesFunctions, 6
1.6 ImportingData, 7
Exercises, 7
2 ReviewofRegressionandMoreAboutR 8
2.1 GoalsofthisChapter, 8
2.2 TheSimple(ST)RegressionModel, 8
2.2.1 OrdinaryLeastSquares, 8
2.2.2 PropertiesofOLSEstimates, 9
2.2.3 MatrixRepresentationoftheProblem, 9
2.3 SimulatingtheDatafromaModelandEstimatingtheModel
ParametersinR, 9
2.3.1 SimulatingData, 9
2.3.2 EstimatingtheModelParametersinR, 9
v
JWST451-fm JWST451-Derryberry May23,2014 10:39 PrinterName: Trim:6.125in×9.25in
vi CONTENTS
2.4 BasicInferencefortheModel, 12
2.5 ResidualsAnalysis—WhatCanGoWrong…, 13
2.6 MatrixManipulationinR, 15
2.6.1 Introduction, 15
2.6.2 OLStheHardWay, 15
2.6.3 SomeOtherMatrixCommands, 16
Exercises, 16
3 TheModelingApproachTakeninthisBookandSomeExamples
ofTypicalSeriallyCorrelatedData 18
3.1 SignalandNoise, 18
3.2 TimeSeriesData, 19
3.3 SimpleRegressionintheFramework, 20
3.4 RealDataandSimulatedData, 20
3.5 TheDiversityofTimeSeriesData, 21
3.6 GettingDataIntoR, 24
3.6.1 Overview, 24
3.6.2 TheDisketteandthescan()andts()Functions—New
YorkCityTemperatures, 25
3.6.3 TheDisketteandtheread.table()Function—The
SemmelweisData, 25
3.6.4 CutandPasteDatatoaTextEditor, 26
Exercises, 26
4 SomeCommentsonAssumptions 28
4.1 Introduction, 28
4.2 TheNormalityAssumption, 29
4.2.1 RightSkew, 30
4.2.2 LeftSkew, 30
4.2.3 HeavyTails, 30
4.3 EqualVariance, 31
4.3.1 Two-Samplet-Test, 31
4.3.2 Regression, 31
4.4 Independence, 31
4.5 PowerofLogarithmicTransformationsIllustrated, 32
4.6 Summary, 34
Exercises, 34
5 TheAutocorrelationFunctionAndAR(1),AR(2)Models 35
5.1 StandardModels—WhataretheAlternativestoWhiteNoise?, 35
5.2 AutocovarianceandAutocorrelation, 36
5.2.1 Stationarity, 36
5.2.2 ANoteAboutConditions, 36
JWST451-fm JWST451-Derryberry May23,2014 10:39 PrinterName: Trim:6.125in×9.25in
CONTENTS vii
5.2.3 PropertiesofAutocovariance, 36
5.2.4 WhiteNoise, 37
5.2.5 EstimationoftheAutocovarianceandAutocorrelation, 37
5.3 Theacf()FunctioninR, 37
5.3.1 Background, 37
5.3.2 TheBasicCodeforEstimatingtheAutocovariance, 38
5.4 TheFirstAlternativetoWhiteNoise:Autoregressive
Errors—AR(1),AR(2), 40
5.4.1 DefinitionoftheAR(1)andAR(2)Models, 40
5.4.2 SomePreliminaryFacts, 40
5.4.3 TheAR(1)ModelAutocorrelationandAutocovariance, 41
5.4.4 UsingCorrelationandScatterplotstoIllustratetheAR(1)
Model, 41
5.4.5 TheAR(2)ModelAutocorrelationandAutocovariance, 41
5.4.6 SimulatingDataforAR(m)Models, 42
5.4.7 ExamplesofStableandUnstableAR(1)Models, 44
5.4.8 ExamplesofStableandUnstableAR(2)Models, 46
Exercises, 49
6 TheMovingAverageModelsMA(1)AndMA(2) 51
6.1 TheMovingAverageModel, 51
6.2 TheAutocorrelationforMA(1)Models, 51
6.3 ADualityBetweenMA(l)AndAR(m)Models, 52
6.4 TheAutocorrelationforMA(2)Models, 52
6.5 SimulatedExamplesoftheMA(1)Model, 52
6.6 SimulatedExamplesoftheMA(2)Model, 54
6.7 AR(m)andMA(l)modelacf()Plots, 54
Exercises, 57
PARTII ANALYSISOFPERIODICDATAANDMODEL
SELECTION
7 ReviewofTranscendentalFunctionsandComplexNumbers 61
7.1 Background, 61
7.2 ComplexArithmetic, 62
7.2.1 TheNumberi, 62
7.2.2 ComplexConjugates, 62
7.2.3 TheMagnitudeofaComplexNumber, 62
7.3 SomeImportantSeries, 63
7.3.1 TheGeometricandSomeTranscendentalSeries, 63
7.3.2 ARationaleforEuler’sFormula, 63
7.4 UsefulFactsAboutPeriodicTranscendentalFunctions, 64
Exercises, 64
JWST451-fm JWST451-Derryberry May23,2014 10:39 PrinterName: Trim:6.125in×9.25in
viii CONTENTS
8 ThePowerSpectrumandthePeriodogram 65
8.1 Introduction, 65
8.2 ADefinitionandaSimplifiedFormforp(f), 66
8.3 Invertingp(f)toRecovertheC Values, 66
k
8.4 ThePowerSpectrumforSomeFamiliarModels, 68
8.4.1 WhiteNoise, 68
8.4.2 TheSpectrumforAR(1)Models, 68
8.4.3 TheSpectrumforAR(2)Models, 70
8.5 ThePeriodogram,aCloserLook, 72
8.5.1 WhyisthePeriodogramUseful?, 72
8.5.2 SomeNa¨ıveCodeforaPeriodogram, 72
8.5.3 AnExample—TheSunspotData, 74
8.6 TheFunctionspec.pgram()inR, 75
Exercises, 77
9 Smoothers,TheBias-VarianceTradeoff,andtheSmoothed
Periodogram 79
9.1 WhyisSmoothingRequired?, 79
9.2 Smoothing,Bias,andVariance, 79
9.3 SmoothersUsedinR, 80
9.3.1 TheRFunctionlowess(), 81
9.3.2 TheRFunctionsmooth.spline(), 82
9.3.3 KernelSmoothersinspec.pgram(), 83
9.4 SmoothingthePeriodogramforaSeriesWithaKnownand
UnknownPeriod, 85
9.4.1 PeriodKnown, 85
9.4.2 PeriodUnknown, 86
9.5 Summary, 87
Exercises, 87
10 ARegressionModelforPeriodicData 89
10.1 TheModel, 89
10.2 AnExample:TheNYCTemperatureData, 91
10.2.1 FittingaPeriodicFunction, 91
10.2.2 AnOutlier, 92
10.2.3 RefittingtheModelwiththeOutlierCorrected, 92
10.3 Complications1:CO Data, 93
2
10.4 Complications2:SunspotNumbers, 94
10.5 Complications3:AccidentalDeaths, 96
10.6 Summary, 96
Exercises, 96
Description:Written at a readily accessible level, Basic Data Analysis for Time Series with R emphasizes the mathematical importance of collaborative analysis of data used to collect increments of time or space. Balancing a theoretical and practical approach to analyzing data within the context of serial correl