| 42333 |
ripley |
1 |
% File src/library/stats/man/kernel.Rd
|
| 68948 |
ripley |
2 |
% Part of the R package, https://www.R-project.org
|
| 67599 |
ripley |
3 |
% Copyright 1995-2014 R Core Team
|
| 42333 |
ripley |
4 |
% Distributed under GPL 2 or later
|
|
|
5 |
|
| 27497 |
ripley |
6 |
\name{kernel}
|
| 56186 |
murdoch |
7 |
\alias{kernel}
|
| 27497 |
ripley |
8 |
\alias{bandwidth.kernel}
|
|
|
9 |
\alias{df.kernel}
|
|
|
10 |
\alias{is.tskernel}
|
| 34932 |
maechler |
11 |
\alias{plot.tskernel}
|
| 27497 |
ripley |
12 |
\title{Smoothing Kernel Objects}
|
|
|
13 |
\description{
|
|
|
14 |
The \code{"tskernel"} class is designed to represent discrete
|
|
|
15 |
symmetric normalized smoothing kernels. These kernels can be used to
|
|
|
16 |
smooth vectors, matrices, or time series objects.
|
| 34932 |
maechler |
17 |
|
|
|
18 |
There are \code{\link{print}}, \code{\link{plot}} and \code{\link{[}}
|
|
|
19 |
methods for these kernel objects.
|
| 27497 |
ripley |
20 |
}
|
|
|
21 |
\usage{
|
| 53718 |
ripley |
22 |
kernel(coef, m = 2, r, name)
|
| 27497 |
ripley |
23 |
|
|
|
24 |
df.kernel(k)
|
|
|
25 |
bandwidth.kernel(k)
|
|
|
26 |
is.tskernel(k)
|
| 50416 |
ripley |
27 |
|
| 34932 |
maechler |
28 |
\method{plot}{tskernel}(x, type = "h", xlab = "k", ylab = "W[k]",
|
|
|
29 |
main = attr(x,"name"), \dots)
|
| 27497 |
ripley |
30 |
}
|
|
|
31 |
\arguments{
|
|
|
32 |
\item{coef}{the upper half of the smoothing kernel coefficients
|
| 34932 |
maechler |
33 |
(including coefficient zero) \emph{or} the name of a kernel
|
| 27497 |
ripley |
34 |
(currently \code{"daniell"}, \code{"dirichlet"}, \code{"fejer"} or
|
| 74363 |
maechler |
35 |
\code{"modified.daniell"}).}
|
| 53722 |
ripley |
36 |
\item{m}{the kernel dimension(s) if \code{coef} is a name. When \code{m}
|
| 34932 |
maechler |
37 |
has length larger than one, it means the convolution of
|
|
|
38 |
kernels of dimension \code{m[j]}, for \code{j in 1:length(m)}.
|
|
|
39 |
Currently this is supported only for the named "*daniell" kernels.}
|
|
|
40 |
\item{name}{the name the kernel will be called.}
|
| 27497 |
ripley |
41 |
\item{r}{the kernel order for a Fejer kernel.}
|
| 53722 |
ripley |
42 |
\item{k, x}{a \code{"tskernel"} object.}
|
| 34932 |
maechler |
43 |
\item{type, xlab, ylab, main, \dots}{arguments passed to
|
|
|
44 |
\code{\link{plot.default}}.}
|
| 27497 |
ripley |
45 |
}
|
|
|
46 |
\details{
|
|
|
47 |
\code{kernel} is used to construct a general kernel or named specific
|
|
|
48 |
kernels. The modified Daniell kernel halves the end coefficients (as
|
| 34932 |
maechler |
49 |
used by S-PLUS).
|
|
|
50 |
|
|
|
51 |
The \code{\link{[}} method allows natural indexing of kernel objects
|
|
|
52 |
with indices in \code{(-m) : m}. The normalization is such that for
|
|
|
53 |
\code{k <- kernel(*)}, \code{sum(k[ -k$m : k$m ])} is one.
|
|
|
54 |
|
| 42961 |
ripley |
55 |
\code{df.kernel} returns the \sQuote{equivalent degrees of freedom} of
|
| 42819 |
murdoch |
56 |
a smoothing kernel as defined in Brockwell and Davis (1991), page
|
| 27497 |
ripley |
57 |
362, and \code{bandwidth.kernel} returns the equivalent bandwidth as
|
| 65208 |
hornik |
58 |
defined in Bloomfield (1976), p.\sspace{}201, with a continuity correction.
|
| 27497 |
ripley |
59 |
}
|
|
|
60 |
\value{
|
| 34932 |
maechler |
61 |
\code{kernel()} returns an object of class \code{"tskernel"} which is
|
|
|
62 |
basically a list with the two components \code{coef} and the kernel
|
|
|
63 |
dimension \code{m}. An additional attribute is \code{"name"}.
|
| 27497 |
ripley |
64 |
}
|
|
|
65 |
\author{A. Trapletti; modifications by B.D. Ripley}
|
|
|
66 |
\seealso{
|
|
|
67 |
\code{\link{kernapply}}
|
|
|
68 |
}
|
|
|
69 |
\references{
|
| 34932 |
maechler |
70 |
Bloomfield, P. (1976)
|
|
|
71 |
\emph{Fourier Analysis of Time Series: An Introduction.}
|
|
|
72 |
Wiley.
|
| 27497 |
ripley |
73 |
|
| 34932 |
maechler |
74 |
Brockwell, P.J. and Davis, R.A. (1991)
|
|
|
75 |
\emph{Time Series: Theory and Methods.}
|
| 65208 |
hornik |
76 |
Second edition. Springer, pp.\sspace{}350--365.
|
| 27497 |
ripley |
77 |
}
|
|
|
78 |
\examples{
|
| 41508 |
ripley |
79 |
require(graphics)
|
|
|
80 |
|
| 34932 |
maechler |
81 |
## Demonstrate a simple trading strategy for the
|
|
|
82 |
## financial time series German stock index DAX.
|
|
|
83 |
x <- EuStockMarkets[,1]
|
| 27497 |
ripley |
84 |
k1 <- kernel("daniell", 50) # a long moving average
|
|
|
85 |
k2 <- kernel("daniell", 10) # and a short one
|
| 34932 |
maechler |
86 |
plot(k1)
|
| 27497 |
ripley |
87 |
plot(k2)
|
|
|
88 |
x1 <- kernapply(x, k1)
|
|
|
89 |
x2 <- kernapply(x, k2)
|
|
|
90 |
plot(x)
|
|
|
91 |
lines(x1, col = "red") # go long if the short crosses the long upwards
|
|
|
92 |
lines(x2, col = "green") # and go short otherwise
|
|
|
93 |
|
| 34932 |
maechler |
94 |
## More interesting kernels
|
| 61160 |
ripley |
95 |
kd <- kernel("daniell", c(3, 3))
|
| 34932 |
maechler |
96 |
kd # note the unusual indexing
|
|
|
97 |
kd[-2:2]
|
| 61160 |
ripley |
98 |
plot(kernel("fejer", 100, r = 6))
|
| 34932 |
maechler |
99 |
plot(kernel("modified.daniell", c(7,5,3)))
|
|
|
100 |
|
| 42819 |
murdoch |
101 |
# Reproduce example 10.4.3 from Brockwell and Davis (1991)
|
| 61160 |
ripley |
102 |
spectrum(sunspot.year, kernel = kernel("daniell", c(11,7,3)), log = "no")
|
| 27497 |
ripley |
103 |
}
|
|
|
104 |
\keyword{ts}
|
|
|
105 |
|