kalman.spec: Evolutive Spectrum from a Time-Varying Autoregressive Model

View source: R/kalman.ar.R

kalman.specR Documentation

Evolutive Spectrum from a Time-Varying Autoregressive Model

Description

Computes the autoregressive spectrum of every year from the coefficients estimated by kalman.ar, and plots the result as a surface in time and period.

Usage

kalman.spec(x, nfreq = 200, freq = NULL)

## S3 method for class 'kalman.spec'
plot(x, log.power = TRUE, col = NULL, key = TRUE,
     xlab = gettext("Time", domain = "R-dplR"),
     ylab = gettext("Period", domain = "R-dplR"), ...)

## S3 method for class 'kalman.spec'
print(x, ...)

Arguments

x

for kalman.spec, an object of class "kalman.ar". For the methods, an object of class "kalman.spec".

nfreq

number of frequencies. They are spaced evenly in the logarithm of period, from 2 years to half the length of the series.

freq

numeric. Frequencies to use instead, in cycles per year, increasing, above 0 and no more than 0.5.

log.power

logical. Plot the base-10 logarithm of the spectrum. AR spectra have sharp peaks, and without the logarithm little else can be seen.

col

colours for the surface, low to high. A viridis ramp if NULL.

key

logical. Draw a colour key. This uses layout; set it to FALSE to put the plot in a layout of your own.

xlab, ylab

axis labels.

...

arguments passed to image, for instance main.

Details

The spectrum in year t at frequency f is

S_t(f) = \frac{\sigma^2}{\left|1 - \sum_{j=1}^{p} a_{j,t} e^{-2\pi i j f}\right|^2}

which is the usual AR spectrum, scaled as in spec.ar, with the coefficients of that year. If the fit had variance = "varying", \sigma^2 is that of the year as well, so the whole spectrum of a year rises and falls with its innovation variance.

There is no test of significance. The surface shows what the fitted model implies and is only as good as the choice of order and lambda in kalman.ar; see the details there. The spectrum of the model with fixed coefficients is returned as spec.fixed for comparison.

The first order years of the series have no spectrum.

Value

kalman.spec returns an object of class "kalman.spec", a list with elements:

yrs

the years.

freq

frequencies in cycles per year.

period

the same as periods in years.

spec

matrix of spectral density, one row per year and one column per frequency.

spec.fixed

spectrum of the AR model with fixed coefficients, at the innovation variance of that model (its geometric mean if the variance varies).

sigma2.t

innovation variance of each year.

order, prior, lambda, variance

from the fit.

The plot method returns x invisibly.

Note

This function is experimental and may change in future releases, as may kalman.ar.

Author(s)

Andy Bunn

References

Kitagawa, G. and Gersch, W. (1985) A smoothness priors time-varying AR coefficient modeling of nonstationary covariance time series. IEEE Transactions on Automatic Control, 30(1), 48–56.

See Also

kalman.ar, wavelet.plot

Examples

ss <- datasets::sunspot.year
fit <- kalman.ar(as.numeric(ss), yrs = as.numeric(time(ss)), order = 30,
            lambda = 1e-3)
sp <- kalman.spec(fit)
sp
plot(sp)

## The period with the most power between 7 and 16 years, by year
band <- sp$period > 7 & sp$period < 16
peak <- sp$period[band][apply(sp$spec[, band], 1, which.max)]
plot(sp$yrs, peak, type = "l", xlab = "Year", ylab = "Period (years)")

dplR documentation built on Dec. 6, 2026, 1:07 a.m.