| kalman.spec | R Documentation |
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.
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, ...)
x |
for |
nfreq |
number of frequencies. They are spaced evenly in the logarithm of period, from 2 years to half the length of the series. |
freq |
|
log.power |
|
col |
colours for the surface, low to high. A viridis ramp if
|
key |
|
xlab, ylab |
axis labels. |
... |
arguments passed to |
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.
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 |
|
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.
This function is experimental and may change in future releases, as
may kalman.ar.
Andy Bunn
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.
kalman.ar, wavelet.plot
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)")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.