# Time Series Analysis and Its Applications: With R Examples

## Second Edition

This is the site for the second edition of the text and is no longer maintained. Follow this link if you're looking for the site of the 4th edition
.

# Code for Chapter 7 Examples

The examples in Chapter 7 were done, for the most part, using Matlab. If you don't own Matlab, you can obtain "free versions" by following this link to Matlab Clones. If we have converted code to R, we will also distribute that here, but if it's not here it hasn't been done. At this time, only the code for the spectral envelope is R code.

Some of the Matlab programs below use FDR.m and fprob.m so you might as well get them... they're small.

## §7.9 - The Spectral Envelope [R]

First, download and source mvspec.R, which is spec.pgram with a few changes in the defaults:

```function(x, spans = NULL, kernel = NULL, taper = 0, pad = 0,
fast = TRUE, demean = TRUE, detrend = FALSE, plot = FALSE,
na.action = na.fail,...)```
and written so you can extract the estimate of the multivariate spectral matrix as fxx. For example, if x contains a p-variate time series (i.e., the p columns of x are time series), and you issue the command spec = mvspec(x, spans=3), then spec\$fxx is an array with dimensions dim=c(p,p,nfreq), where nfreq is the number of frequencies used. If you print spec\$fxx you'll see nfreq p × p spectral matrix estimates.

• Code to do the analysis in Example 7.18 is given in specenv.txt; the corresponding data set can be found here: bnrf1ebv.dat.
• Code to do the analysis in Example 7.19 is given in specenvcont.txt; the data are the residuals from the MA(2) fit to the GNP returns in Example 3.35 and can be downloaded here: gnpres.dat.