Learn R Programming

astsa (version 1.1)

mvspec: Univariate and Multivariate Spectral Estimation

Description

This is spec.pgram with a few changes in the defaults and written so you can easily extract the estimate of the multivariate spectral matrix as fxx. The bandwidth calculation has been changed to the more practical definition given in the text. Can be used to replace spec.pgram for univariate series.

Usage

mvspec(x, spans = NULL, kernel = NULL, taper = 0, pad = 0, 
         fast = TRUE, demean = FALSE, detrend = TRUE, 
         plot = TRUE, na.action = na.fail, ...)

Arguments

x
univariate or multivariate time series (i.e., the p columns of x are time series)
spans
specify smoothing; same as spec.pgram
kernel
specify kernel; same as spec.pgram
taper
specify taper; same as spec.pgram with different default
pad
specify padding; same as spec.pgram
fast
specify use of FFT; same as spec.pgram
demean
if TRUE, series is demeaned first; same as spec.pgram
detrend
if TRUE, series is detrended first; same as spec.pgram
plot
plot the estimate; same as spec.pgram
na.action
same as spec.pgram
...
additional arguments; same as spec.pgram

Value

  • An object of class "spec", which is a list containing at least the following components:
  • fxxspectral matrix estimates; an array of dimensions dim = c(p,p,nfreq)
  • freqvector of frequencies at which the spectral density is estimated.
  • specvector (for univariate series) or matrix (for multivariate series) of estimates of the spectral density at frequencies corresponding to freq.
  • cohNULL for univariate series. For multivariate time series, a matrix containing the squared coherency between different series. Column i + (j - 1) * (j - 2)/2 of coh contains the squared coherency between columns i and j of x, where i < j.
  • phaseNULL for univariate series. For multivariate time series a matrix containing the cross-spectrum phase between different series. The format is the same as coh.
  • LhNumber of frequencies (approximate) used in the band, as defined in (4.57) on page 204.
  • n.usedSample length used for the FFT
  • seriesThe name of the time series.
  • snamesFor multivariate input, the names of the component series.
  • methodThe method used to calculate the spectrum.
  • The results are returned invisibly if plot is true.

Details

This is spec.pgram with a few changes in the defaults and written so you can easily extract the estimate of the multivariate spectral matrix as fxx. The bandwidth calculation has been changed to the more practical definition given in the text, $(L_h/n.used)*frequency(x)$. Although meant to be used to easily obtain multivariate spectral estimates, this script can be used in Chapter 4 for the spectral analysis of a univariate time series. Note that the script does not taper by default (taper=0); this forces the user to do "conscious tapering". See Example 7.12 on page 461 for a demonstration.

References

http://www.stat.pitt.edu/stoffer/tsa3/

Examples

Run this code
# univariate example
plot(co2)   # co2 is an R data set
mvspec(co2, spans=c(5,5), taper=.5)

# multivariate example
ts.plot(mdeaths, fdeaths, col=1:2)   # an R data set, male/female monthly deaths ...
dog = mvspec(cbind(mdeaths,fdeaths), spans=c(3,3), taper=.1)
dog$fxx        # look a spectral matrix estimates
dog$bandwidth  # bandwidth with time unit = year
dog$bandwidth/frequency(mdeaths)  # ... with time unit = month
plot(dog, plot.type="coherency")  # plot of squared coherency

Run the code above in your browser using DataLab