You are previewing Basic Data Analysis for Time Series with R.
O'Reilly logo
Basic Data Analysis for Time Series with R

Book 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 correlation, the book presents a coherent and systematic regression-based approach to model selection. The book illustrates these principles of model selection and model building through the use of information criteria, cross validation, hypothesis tests, and confidence intervals.

Focusing on frequency- and time-domain and trigonometric regression as the primary themes, the book also includes modern topical coverage on Fourier series and Akaike's Information Criterion (AIC). In addition, Basic Data Analysis for Time Series with R also features:

  • Real-world examples to provide readers with practical hands-on experience

  • Multiple R software subroutines employed with graphical displays

  • Numerous exercise sets intended to support readers understanding of the core concepts

  • Specific chapters devoted to the analysis of the Wolf sunspot number data and the Vostok ice core data sets

  • Table of Contents

    1. PREFACE
      1. What This Book is About
      2. Motivation
      3. Required Background
      4. A Couple of Odd Features
    2. ACKNOWLEDGMENTS
    3. PART I BASIC CORRELATION STRUCTURES
      1. 1 R Basics
        1. 1.1 Getting Started
        2. 1.2 Special R Conventions
        3. 1.3 Common Structures
        4. 1.4 Common Functions
        5. 1.5 Time Series Functions
        6. 1.6 Importing Data
        7. Exercises
      2. 2 Review of Regression and More About R
        1. 2.1 Goals of This Chapter
        2. 2.2 The Simple(ST) Regression Model
        3. 2.3 Simulating The Data From A Model and Estimating The Model Parameters in R
        4. 2.4 Basic Inference for the Model
        5. 2.5 Residuals Analysis—What Can go Wrong…
        6. 2.6 Matrix Manipulation in R
        7. Exercises
      3. 3 The Modeling Approach Taken in this Book and Some Examples of Typical Serially Correlated Data
        1. 3.1 Signal and Noise
        2. 3.2 Time Series Data
        3. 3.3 Simple Regression in the Framework
        4. 3.4 Real Data and Simulated Data
        5. 3.5 The Diversity of Time Series Data
        6. 3.6 Getting Data Into R
        7. Exercises
      4. 4 Some Comments on Assumptions
        1. 4.1 Introduction
        2. 4.2 The Normality Assumption
        3. 4.3 Equal Variance
        4. 4.4 Independence
        5. 4.5 Power of Logarithmic Transformations Illustrated
        6. 4.6 Summary
        7. Exercises
      5. 5 The Autocorrelation Function And AR(1), AR(2) Models
        1. 5.1 Standard Models—What are the Alternatives to <i xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:svg="http://www.w3.org/2000/svg">WHITE NOISE</i>??
        2. 5.2 Autocovariance and Autocorrelation
        3. 5.3 The <i xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:svg="http://www.w3.org/2000/svg">acf()</i> Function in R Function in R
        4. 5.4 The First Alternative to White Noise: Autoregressive Errors—AR(1), AR(2)
        5. Exercises
      6. 6 The Moving Average Models MA(1) And MA(2)
        1. 6.1 The Moving Average Model
        2. 6.2 The Autocorrelation for MA(1) Models
        3. 6.3 A Duality Between MA(<i xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:svg="http://www.w3.org/2000/svg">l</i>) And AR() And AR(<i xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:svg="http://www.w3.org/2000/svg">m</i>) Models) Models
        4. 6.4 The Autocorrelation for MA(2) Models
        5. 6.5 Simulated Examples of the MA(1) Model
        6. 6.6 Simulated Examples of the MA(2) Model
        7. 6.7 AR(<i xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:svg="http://www.w3.org/2000/svg">m</i>) and MA() and MA(<i xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:svg="http://www.w3.org/2000/svg">l</i>) model ) model <i xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:svg="http://www.w3.org/2000/svg">acf()</i> Plots Plots
        8. Exercises
    4. PART II ANALYSIS OF PERIODIC DATA AND MODEL SELECTION
      1. 7 Review of Transcendental Functions and Complex Numbers
        1. 7.1 Background
        2. 7.2 Complex Arithmetic
        3. 7.3 Some Important Series
        4. 7.4 Useful Facts About Periodic Transcendental Functions
        5. Exercises
      2. 8 The Power Spectrum and the Periodogram
        1. 8.1 Introduction
        2. 8.2 A Definition and a Simplified Form for <i xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:svg="http://www.w3.org/2000/svg">p</i>((<i xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:svg="http://www.w3.org/2000/svg">f</i>))
        3. 8.3 Inverting <i xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:svg="http://www.w3.org/2000/svg">p</i>((<i xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:svg="http://www.w3.org/2000/svg">f</i>) to Recover the ) to Recover the <i xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:svg="http://www.w3.org/2000/svg">C<sub>k</sub></i> Values Values
        4. 8.4 The Power Spectrum for Some Familiar Models
        5. 8.5 The Periodogram, a Closer Look
        6. 8.6 The Function <i xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:svg="http://www.w3.org/2000/svg">SPEC.PGRAM()</i> in R in R
        7. Exercises
      3. 9 Smoothers, The Bias-Variance Tradeoff, and the Smoothed Periodogram
        1. 9.1 Why is Smoothing Required?
        2. 9.2 Smoothing, Bias, and Variance
        3. 9.3 Smoothers Used in R
        4. 9.4 Smoothing the Periodogram for a Series With a Known and Unknown Period
        5. 9.5 Summary
        6. Exercises
      4. 10 A Regression Model for Periodic Data
        1. 10.1 The Model
        2. 10.2 An Example: The NYC Temperature Data
        3. 10.3 Complications 1: CO<sub xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:svg="http://www.w3.org/2000/svg">2</sub> Data Data
        4. 10.4 Complications 2: Sunspot Numbers
        5. 10.5 Complications 3: Accidental Deaths
        6. 10.6 Summary
        7. Exercises
      5. 11 Model Selection and Cross-Validation
        1. 11.1 Background
        2. 11.2 Hypothesis tests in simple regression
        3. 11.3 A more general setting for likelihood ratio tests
        4. 11.4 A subtlety different situation
        5. 11.5 Information criteria
        6. 11.6 Cross-validation (Data splitting): NYC temperatures
        7. 11.7 Summary
        8. Exercises
      6. 12 Fitting Fourier series
        1. 12.1 Introduction: more complex periodic models
        2. 12.2 More complex periodic behavior: Accidental deaths
        3. 12.3 The Boise river flow data
        4. 12.4 Where do we go from here?
        5. Exercises
      7. 13 Adjusting for AR(1) Correlation in Complex Models
        1. 13.1 Introduction
        2. 13.2 The Two-Sample <b xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:svg="http://www.w3.org/2000/svg"><i>t</i></b>-Test&#8212;UNCUT and Patch-Cut Forest-Test—UNCUT and Patch-Cut Forest
        3. 13.3 The Second Sleuth Case—Global Warming, A Simple Regression
        4. 13.4 The Semmelweis Intervention
        5. 13.5 The NYC Temperatures (Adjusted)
        6. 13.6 The Boise River Flow Data: Model Selection With Filtering
        7. 13.7 Implications of AR(1) Adjustments and the “Skip” Method
        8. 13.8 Summary
        9. Exercises
    5. PART III COMPLEX TEMPORAL STRUCTURES
      1. 14 The backshift operator, the impulse response function, and general ARMA models
        1. 14.1 The general ARMA model
        2. 14.2 The backshift (shift, lag) operator
        3. 14.3 The impulse response operator – intuition
        4. 14.4 Impulse response operator, <i xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:svg="http://www.w3.org/2000/svg">g(B)</i>&#8212;computation—computation
        5. 14.5 Interpretation and utility of the impulse response function
        6. Exercises
      2. 15 The Yule–Walker Equations and the Partial Autocorrelation Function
        1. 15.1 Background
        2. 15.2 Autocovariance of an ARMA(<i xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:svg="http://www.w3.org/2000/svg">m,l</i>) Model) Model
        3. 15.3 AR(<i xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:svg="http://www.w3.org/2000/svg">m</i>) and the Yule&#8211;Walker Equations) and the Yule–Walker Equations
        4. 15.4 The Partial Autocorrelation Plot
        5. 15.5 The Spectrum For Arma Processes
        6. 15.6 Summary
        7. Exercises
      3. 16 Modeling philosophy and Complete Examples
        1. 16.1 Modeling overview
        2. 16.2 A complex periodic model—Monthly river flows, Furnas 1931–1978
        3. 16.3 A modeling example—trend and periodicity: CO<sub xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:svg="http://www.w3.org/2000/svg">2</sub> levels at Mauna Lau levels at Mauna Lau
        4. 16.4 Modeling periodicity with a possible intervention—two examples
        5. 16.5 Periodic models: monthly, weekly, and daily averages
        6. 16.6 Summary
        7. Exercises
    6. PART IV SOME DETAILED AND COMPLETE EXAMPLES
      1. 17 Wolf's sunspot number data
        1. 17.1 Background
        2. 17.2 Unknown period ⇒ nonlinear model
        3. 17.3 The function <i xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:svg="http://www.w3.org/2000/svg">nls()</i> IN R IN R
        4. 17.4 Determining the period
        5. 17.5 Instability in the mean, amplitude, and period
        6. 17.6 Data splitting for prediction
        7. 17.7 Summary
        8. Exercises
      2. 18 An Analysis of Some Prostate and Breast Cancer Data
        1. 18.1 Background
        2. 18.2 The First Data Set
        3. 18.3 The Second Data Set
        4. Exercises
      3. 19 Christopher Tennant/Ben Crosby Watershed Data
        1. 19.1 Background and Question
        2. 19.2 Looking at the Data and Fitting Fourier Series
        3. 19.3 Averaging Data
        4. 19.4 Results
        5. Exercises
      4. 20 Vostok Ice Core Data
        1. 20.1 Source of the Data
        2. 20.2 Background
        3. 20.3 Alignment
        4. 20.4 A NaÏve Analysis
        5. 20.5 A Related Simulation
        6. 20.6 An AR(1) Model for Irregular Spacing
        7. 20.7 Summary
        8. Exercises
      5. Appendix A Using Datamarket
        1. A.1 Overview
        2. A.2 Loading a Time Series in Datamarket
        3. A.3 Respecting Datamarket Licensing Agreements
      6. Appendix B AIC is PRESS!
        1. B.1 Introduction
        2. B.2 Press
        3. B.3 Connection to Akaike's result
        4. B.4 Normalization and <i xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:svg="http://www.w3.org/2000/svg">R</i><sup xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:svg="http://www.w3.org/2000/svg">2</sup>
        5. B.5 An example
        6. B.6 Conclusion and further comments
      7. Appendix C A 15-Minute Tutorial on Nonlinear Optimization
        1. C.1 Introduction
        2. C.2 Newton's method for one-dimensional nonlinear optimization
        3. C.3 A sequence of directions, step sizes, and a stopping rule
        4. C.4 What could go wrong?
        5. C.5 Generalizing the optimization problem
        6. C.6 What could go wrong—revisited
        7. C.7 What can be done?
    7. REFERENCES
    8. INDEX
    9. End User License Agreement