tseries (version 0.1-1)

kernel: Smoothing Kernel Objects

Description

The "kernel" class is designed to represent symmetric normalized smoothing kernels. These kernels can be used to smooth vectors, matrices, or time series objects. Furthermore, they are used for the spectrum estimation and related routines. The "kernel" class also provides common plot, print, and extract methods.

Usage

kernel (coef, m, name)
daniell.kernel (m)
fejer.kernel (m, r)
dirichlet.kernel (m, r)

df.kernel (k) is.kernel (k)

print (k, digits = max(3,.Options$digits-3)) plot (k) k[i] apply.kernel (x, k, circular = FALSE) apply.kernel (k1, k2)

Arguments

coef
the upper half of the smoothing kernel coefficients (inclusive coefficient zero).
m
the kernel dimension. The number of kernel coefficients is 2*m+1.
name
the name of the kernel.
r
the kernel order.
k, k1, k2
smoothing "kernel" objects.
digits
the number of digits to format real numbers.
x
an input vector, matrix, or time series to be smoothed.
circular
a logical indicating whether the input sequence to be smoothed is treated as circular, i.e., periodic.

Value

  • kernel, daniell.kernel, fejer.kernel, and dirichlet.kernel return "kernel" objects. These objects consist of a list with class "kernel", the coefficients coef, and the kernel dimension m. An additional attribute is "name". k[i] returns the i'th coefficient of the kernel. The print and plot methods return the invisible input object.

    apply.kernel returns the smoothed input sequence.

Details

kernel, daniell.kernel, fejer.kernel, and dirichlet.kernel are used to construct a general kernel and the named specific kernels, respectively. df.kernel returns the "equivalent degrees of freedom" of a smoothing kernel as defined in Brockwell and Davies (1991), p. 362. apply.kernel computes the convolution between an input sequence and a specific kernel. See also convolve.

References

P. J. Brockwell and R. A. Davis (1991): Time Series: Theory and Methods, 2nd Edition, Springer Verlag, NY, pp. 350-365.

See Also

density, convolve, spectrum

Examples

Run this code
data (finance)    # Demonstrate a simple trading strategy for the 
x <- finance[,1]  # financial time series German stock index DAX.
k1 <- daniell.kernel (50)  # a long moving average
k2 <- daniell.kernel (10)  # and a short one
plot (k1) 
plot (k2)
x1 <- apply.kernel (x, k1)
x2 <- apply.kernel (x, k2)
plot (x)
lines (x1, col = "red")    # go long if the short crosses the long upwards
lines (x2, col = "green")  # and go short otherwise

data (sunspot)     # Reproduce example 10.4.3 from Brockwell and Davies (1991)
x <- sunspot.year  # p. 354
k1 <- daniell.kernel (11)
k2 <- daniell.kernel (7)
k3 <- daniell.kernel (3)
k <- apply.kernel (k1, k2)
k <- apply.kernel (k, k3)
spectrum (x, k)

Run the code above in your browser using DataCamp Workspace