kernel                 package:stats                 R Documentation

Smoothing Kernel Objects

Description:

     The '"tskernel"' class is designed to represent discrete symmetric
     normalized smoothing kernels.  These kernels can be used to smooth
     vectors, matrices, or time series objects.

     There are 'print', 'plot' and '[' methods for these kernel
     objects.

Usage:

     kernel(coef, m, r, name)

     df.kernel(k)
     bandwidth.kernel(k)
     is.tskernel(k)
     ## S3 method for class 'tskernel':
     plot(x, type = "h", xlab = "k", ylab = "W[k]",
          main = attr(x,"name"), ...)

Arguments:

    coef: the upper half of the smoothing kernel coefficients
          (including coefficient zero) _or_ the name of a kernel
          (currently '"daniell"', '"dirichlet"', '"fejer"' or
          '"modified.daniell"'.

       m: the kernel dimension(s).  When 'm' has length larger than
          one, it means the convolution of kernels of dimension 'm[j]',
          for 'j in 1:length(m)'. Currently this is supported only for
          the named "*daniell" kernels.

    name: the name the kernel will be called.

       r: the kernel order for a Fejer kernel.

     k,x: a '"tskernel"' object.

type, xlab, ylab, main, ...: arguments passed to 'plot.default'.

Details:

     'kernel' is used to construct a general kernel or named specific
     kernels.  The modified Daniell kernel halves the end coefficients
     (as used by S-PLUS).

     The '[' method allows natural indexing of kernel objects with
     indices in '(-m) : m'.  The normalization is such that for 'k <-
     kernel(*)', 'sum(k[ -k$m : k$m ])' is one.

     'df.kernel' returns the 'equivalent degrees of freedom' of a
     smoothing kernel as defined in Brockwell and Davis (1991), page
     362, and 'bandwidth.kernel' returns the equivalent bandwidth as
     defined in Bloomfield (1976), p. 201, with a continuity
     correction.

Value:

     'kernel()' returns an object of class '"tskernel"' which is
     basically a list with the two components 'coef' and the kernel
     dimension 'm'.  An additional attribute is '"name"'.

Author(s):

     A. Trapletti; modifications by B.D. Ripley

References:

     Bloomfield, P. (1976) _Fourier Analysis of Time Series: An
     Introduction._ Wiley.

     Brockwell, P.J. and Davis, R.A. (1991) _Time Series: Theory and
     Methods._ Second edition. Springer, pp. 350-365.

See Also:

     'kernapply'

Examples:

     require(graphics)

     ## Demonstrate a simple trading strategy for the
     ## financial time series German stock index DAX.
     x <- EuStockMarkets[,1]
     k1 <- kernel("daniell", 50)  # a long moving average
     k2 <- kernel("daniell", 10)  # and a short one
     plot(k1)
     plot(k2)
     x1 <- kernapply(x, k1)
     x2 <- kernapply(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

     ## More interesting kernels
     kd <- kernel("daniell", c(3,3))
     kd # note the unusual indexing
     kd[-2:2]
     plot(kernel("fejer", 100, r=6))
     plot(kernel("modified.daniell", c(7,5,3)))

     # Reproduce example 10.4.3 from Brockwell and Davis (1991)
     spectrum(sunspot.year, kernel=kernel("daniell", c(11,7,3)), log="no")

