Estimate Spectrum of Time Series

DESCRIPTION:
Estimates spectra using either a smoothed periodogram or autoregressive parameters.

USAGE:
spectrum(x, method="pgram", plot=T, ...)

REQUIRED ARGUMENTS:
x:
a univariate or multivariate time series, or a vector, or a matrix with a univariate series per column. Missing values are allowed only at the ends. If method="ar", then this can also be a list as returned by the ar function.

OPTIONAL ARGUMENTS:
method:
either the string "ar" or "pgram" depending on whether an autoregressive model or a smoothed periodogram is to be used in estimating the spectrum.
...:
additional arguments.

If method="pgram", then the possible arguments and their defaults are: spans=1, taper=0.1, pad=0, detrend=TRUE, demean=FALSE. The most useful of these is spans which should be a vector of odd integers specifying spans of Daniell smoothers used on the periodogram. See spec.pgram for further information.

If method="ar", additional arguments can be n.freq (the number of frequencies at which the spectrum is to be estimated - the default is 1 plus half the length of the series), and frequency (the frequency of the observations of the time series - the default is the frequency of x). See spec.ar.


VALUE:
a list as returned by spec.pgram if method="pgram", or as returned by spec.ar if method="ar". The most important components are freq (the frequencies at which the spectrum is estimated) and spec (a vector or matrix of spectral estimates in decibels). If the series is multivariate, components coh and phase give the coherency and phase of the series.

SIDE EFFECTS:
if plot=TRUE, a plot is created on the current graphics device.

DETAILS:
Only the (central) part of the series that is free of missing values is used.

If method="pgram", the spectrum is estimated by taking the discrete Fourier transform of the (detrended then tapered then padded) data. The squared modulus of this transform is then smoothed by a sequence of running averages. If method="ar", the parameters of an autoregressive model fitted to x, and its prediction variance are used to compute the spectral estimate of x. See Bloomfield (1976) for a discussion of the methods.


REFERENCES:
Bloomfield, P. (1976). Fourier Analysis of Time Series: An Introduction. Wiley, New York.

The chapter "Analyzing Time Series" of the S-PLUS Guide to Statistical and Mathematical Analysis.


SEE ALSO:
spec.ar , spec.pgram , spec.plot , spec.taper .

EXAMPLES:
spectrum(log(lynx), pad=1, spans=3)  # Compute and plot Raw Periodogram.
p2 <- spectrum(log(lynx), method="ar", plot=F)
spec.plot(p2,add=T)                # Superimpose an autoregressive spectrum