Univariate and Multivariate Spectral Estimation
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.
mvspec(x, spans = NULL, kernel = NULL, taper = 0, pad = 0, fast = TRUE, demean = FALSE, detrend = TRUE, plot = TRUE, log='n', type = NULL, na.action = na.fail, ...)
x |
univariate or multivariate time series (i.e., the p columns of x are time series) |
spans |
specify smoothing; same as |
kernel |
specify kernel; same as |
taper |
specify taper; same as |
pad |
specify padding; same as |
fast |
specify use of FFT; same as |
demean |
if TRUE, series is demeaned first; same as |
detrend |
if TRUE, series is detrended first; same as |
plot |
plot the estimate; same as |
log |
same as |
type |
type of plot to be drawn, defaults to lines |
na.action |
same as |
... |
additional arguments; same as |
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 default for the plot is NOT to plot on a log scale and the graphic will have a grid. 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 for univariate time series. Note that the script does not taper by default (taper=0
); this forces the user to do "conscious tapering".
An object of class "spec", which is a list containing at least the following components:
fxx |
spectral matrix estimates; an array of dimensions |
freq |
vector of frequencies at which the spectral density is estimated. |
spec |
vector (for univariate series) or matrix (for multivariate series) of estimates of the spectral density at frequencies corresponding to freq. |
details |
matrix with columns: frequency, period, spectral ordinate(s) |
coh |
NULL 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. |
phase |
NULL for univariate series. For multivariate time series a matrix containing the cross-spectrum phase between different series. The format is the same as coh. |
Lh |
Number of frequencies (approximate) used in the band, as defined in Chapter 4. |
n.used |
Sample length used for the FFT |
series |
The name of the time series. |
snames |
For multivariate input, the names of the component series. |
method |
The method used to calculate the spectrum. |
The results are returned invisibly if plot is true.
# real raw periodogram mvspec(soi) mvspec(soi, log='y') # on a log scale # smooth and some details printed mvspec(soi, spans=c(7,7), taper=.5)$details[1:45,] # 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$df # degrees of freedom plot(dog, plot.type="coherency") # plot of squared coherency
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.