Spectrum-class: Class '"Spectrum"'

Spectrum-classR Documentation

Class "Spectrum"

Description

Objects from class "Spectrum" spectra computed by spectrum.

Usage

## S3 method for class 'Spectrum'
print(x, ..., n = 128, standardize = TRUE)

## S3 method for class 'Spectrum'
plot(x, y, to, from = y, n = 128, standardize = TRUE,
    log = NULL, main = "Spectral density", xlab = "Frequency", ylab = NULL, ...)

Arguments

x

a "Spectrum" object.

y

not used but same as from

from,to

interval of frequencies to plot, defaults to [0,1/2].

n

number of points to plot (for the plot method), number of points to look at for the peaks and troughs (print method).

standardize

if TRUE make the spectral density integrate to one (i.e., be a probability density function).

log

if log = "y" plot the logarithm of the spectral density, see ?plot.default.

main

a character string, the title of the plot.

xlab

a character string, the label for the x-axis.

ylab

a character string, the label for the y-axis. If NULL, the default, the label is set to "Spd" or "log(Spd)", depending on the value of argument log.

...

for print, further arguments for print.default();

for plot, further arguments for curve.

Details

"Spectrum" is an S4 class and as such autoprinting calls the "Spectrum" method for show(), which prints and plots. show has a single argument, the object. For more control over printing, call print which has additional arguments. Similarly, call plot for more flexible graphics.

print(object) (i.e., without further arguments) is equivalent to show(object), except that the former returns object while the latter returns NULL (both invisibly), as is standard for these functions. If print is called with further arguments. the spectrum is not plotted.

The peaks and throughs printed by print are computed by evaluating the spectral density at n equially spaced points and recording the maxima of the resulting discrete sequence. Set argument n to get a finer/coarser grid or to force calculations for particular frequencies. For example, a multiple of 12 may be suitable for n if the data is monthly.

Except for x and standardize the arguments of the plot method are as for curve. With the default standardize = TRUE the spectral density integrates to one over one whole period (usually (-1/2, 1/2] but due to its symmetry it is usually plotted over the second half of that interval.

Objects from the Class

Objects contain spectra produced by sarima::spectrum, see spectrum for details.

Objects can also be created by calling "new" but this is not recommended and currently considered internal.

Slots

.Data:

Object of class "function" ~~

call:

Object of class "call" ~~

model:

Object of class "ANY", the underlying model.

Methods

plot

signature(x = "Spectrum", y = "ANY"): plots x.

show

signature(object = "Spectrum"):

plots object and prints succinct information about it, including the peaks and troughs in the spectral density. It is equivalent to calling print and plot with a single argument, see section ‘Details’.

Author(s)

Georgi N. Boshnakov

See Also

spectrum for details and further examples,

ArmaSpectrum for ARMA spectra

Examples

## ARFIMA(0,d,0) with parameters 'freq' and 'd'
spARFIMA0d0 <- function(freq){  sigma2 / (2 * sin(2*pi*freq/2)^(2 * d)) }
sp <- spectrum(spARFIMA0d0, param = list(sigma2 = 1, d = 0.2))
print(sp, digits = 4)
## evaluate the spd at selected frequencies 
sp(c(0:4 / 8))

## argument 'freq' doesn't need to be called 'freq' but it needs to be
##   the first one. This is equivalent to above:
spARFIMA0d0b <- function(x){  sigma2 / (2 * sin(2*pi*x/2)^(2 * d)) }
spb <- spectrum(spARFIMA0d0b, param = list(sigma2 = 1, d = 0.2))
plot(spb)

## An example without parameters, as above with sigma2 = 1, d = 0.2 hard
##   coded:
spARFIMA0d0c <- function(freq){  1 / (2 * sin(2*pi*freq/2)^(2 * 0.2)) }
spc <- spectrum(spARFIMA0d0c)
print(spc, digits = 4)

spc(c(0:4 / 8))
all.equal(spc(c(0:4 / 8)), sp(c(0:4 / 8))) # TRUE

sarima documentation built on Aug. 11, 2022, 5:11 p.m.