Most of the data files are one long column, even if they contain more than one series. Some data files are in multicolumn formats. It would be a good idea to look at the file before you use it. As you can see, the data files have .dat extensions, but they are ascii files that can be opened with any text editor (like notepad).
Notes from the book's author:
Everything you see in a box below is R code. You can copy-and-paste any line (or multiple lines) into R. Make sure the data files are in the mydata directory (or change the code accordingly). R code for Chapter 6 has its own page and we also have some code for Chapter 7. We have improved, corrected or streamlined some of the code below, so there are a few cases where the code here differs slightly from what is in the text.
Disclaimer: Sometimes I use t for time, e.g., t = 1984:2001. This is considered bad R practice because t is used for matrix transpose, i.e., t(A) is the transpose of matrix A. If you don't want to be bad, you can replace our t in the code below with something else, BUT NOT time because that's reserved, too. Also, when I can, I prefer to use the simple assignment character (=) to the more complex assignment characters (<- or ->); this is also considered bad R practice. I like to be bad sometimes, but you've been warned ... so don't blame me if you turn to a life of crime.
July 2009 - these now work with the newest version of R. I've marked the main scripts at the top with a version number, which is the date (month.day.year) the script is posted. The latest version of everything is 7.21.2009.
There are three levels (0,1,2) of filtering and smoothing, and they are contained in ss0.R, ss1.R, ss2.R. You can download them individually below, or get them in one file: ssall.R. Keep reading for details and examples.
Each ss*.R is a script for providing the Kalman filter and smoother, the innovations and the corresponding variance-covariance matrices, and the value of the innovations likelihood at the location of the parameter values passed to the script. MLE is then accomplished by calling the script that runs the filter. The model is specified by passing the model parameters. Code for running the examples in the text are provided below.
Level 0 is for the case of a fixed measurement matrix and no inputs; i.e., if At = A for all t, and there are no inputs, then use the code at level 0. If the measurement matrices are time varying or there are inputs, use the code at a higher level (1 or 2). Many of the examples in the text can be done at level 0. Level 1 allows for time varying measurement matrices and inputs, and level 2 adds the possibility of correlated noise processes. The models for each case are (below, x is state, y is observation, and t = 1, ..., n):
◊ Level 0: xt = Φ xt-1 + wt, yt = A xt + vt, wt ~ iid Np(0, Q) ⊥ vt ~ iid Nq(0, R) ⊥ x0 ~ Np(μ0, Σ0)
◊ Level 1: xt = Φ xt-1 + Υ ut + wt, yt = At xt + Γ ut + vt, ut are r-dimensional inputs, etc.
◊ Level 2: xt+1 = Φ xt + Υ ut + wt, yt = At xt + Γ ut + vt, cov(ws, vt) = S δst, etc.
Finally, at the bottom of this page you'll find the code for the material that uses switching: §6.8 DLM with Switching and §6.10 Stochastic Volatility Models.
Table of Contents
Preface
1 Characteristics of Time Series
1.1 Introduction
1.2 The Nature of Time Series Data
1.3 Time Series Statistical Models
1.4 Measures of Dependence: Autocorrelation and Cross-Correlation
1.5 Stationary Time Series
1.6 Estimation of Correlation
1.7 Vector-Valued and Multidimensional Series
Problems
2 Time Series Regression and Exploratory Data Analysis
2.1 Introduction
2.2 Classical Regression in the Time Series Context
2.3 Exploratory Data Analysis
2.4 Smoothing in the Time Series Context
Problems
3 ARIMA Models
3.1 Introduction
3.2 Autoregressive Moving Average Models
3.3 Di.erence Equations
3.4 Autocorrelation and Partial Autocorrelation
3.5 Forecasting
3.6 Estimation
3.7 Integrated Models for Nonstationary Data
3.8 Building ARIMA Models
3.9 Multiplicative Seasonal ARIMA Models
Problems
4 Spectral Analysis and Filtering
4.1 Introduction
4.2 Cyclical Behavior and Periodicity
4.3 The Spectral Density
4.4 Periodogram and Discrete Fourier Transform
4.5 Nonparametric Spectral Estimation
4.6 Parametric Spectral Estimation
4.7 Multiple Series and Cross-Spectra
4.8 Linear Filters
4.9 Dynamic Fourier Analysis and Wavelets
4.10 Lagged Regression Models
4.11 Signal Extraction and Optimum Filtering
4.12 Spectral Analysis of Multidimensional Series
Problems
5 Additional Time Domain Topics
5.1 Introduction
5.2 Long Memory ARMA and Fractional Differencing
5.3 Unit Root Testing
5.4 GARCH Models
5.5 Threshold Models
5.6 Regression with Autocorrelated Errors
5.7 Lagged Regression: Transfer Function Modeling
5.8 Multivariate ARMAX Models
Problems
6 State-Space Models
6.1 Introduction
6.2 Filtering, Smoothing, and Forecasting
6.3 Maximum Likelihood Estimation
6.4 Missing Data Modi.cations
6.5 Structural Models: Signal Extraction and Forecasting
6.6 State-Space Models with Correlated Errors
6.6.1 ARMAX Models
6.6.2 Multivariate Regression with Autocorrelated Errors
6.7 Bootstrapping State-Space Models
6.8 Dynamic Linear Models with Switching
6.9 Stochastic Volatility
6.10 Nonlinear and Non-normal State-Space Models Using Monte Carlo Methods
Problems
7 Statistical Methods in the Frequency Domain
7.1 Introduction
7.2 Spectral Matrices and Likelihood Functions
7.3 Regression for Jointly Stationary Series
7.4 Regression with Deterministic Inputs
7.5 Random Coe.cient Regression
7.6 Analysis of Designed Experiments
7.7 Discrimination and Cluster Analysis
7.8 Principal Components and Factor Analysis
7.9 The Spectral Envelope
Problems
Appendix A: Large Sample Theory
A.1 Convergence Modes
A.2 Central Limit Theorems
A.3 The Mean and Autocorrelation Functions
Appendix B: Time Domain Theory
B.1 Hilbert Spaces and the Projection Theorem
B.2 Causal Conditions for ARMA Models
B.3 Large Sample Distribution of the AR(p) Conditional Least Squares Estimators
B.4 The Wold Decomposition
Appendix C: Spectral Domain Theory
C.1 Spectral Representation Theorem
C.2 Large Sample Distribution of the DFT and Smoothed Periodogram
C.3 The Complex Multivariate Normal Distribution
Appendix R: R Supplement
R.1 First Things First
R.1.1 Included Data Sets
R.1.2 Included Scripts
R.2 Getting Started
R.3 Time Series Primer
References
Index