Description Usage Arguments Details Value Examples

In its arguments `x`

and `dataX`

vectorized function to compute
the classical Nadaraya-Watson estimator (as it is *m_n* in eq. (1.1)
in Eichner & Stute (2012)).

1 | ```
nadwat(x, dataX, dataY, K, h)
``` |

`x` |
Numeric vector with the location(s) at which the Nadaraya-Watson regression estimator is to be computed. |

`dataX` |
Numeric vector |

`dataY` |
Numeric vector |

`K` |
A kernel function (with vectorized in- & output) to be used for the estimator. |

`h` |
Numeric scalar for bandwidth |

Implementation of the classical Nadaraya-Watson estimator as in eq. (1.1) in
Eichner & Stute (2012) at given location(s) in `x`

for data *(X_1,
Y_1), …, (X_n, Y_n)*, a kernel function *K* and a bandwidth *h*.

A numeric vector of the same length as `x`

.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | ```
require(stats)
# Regression function: a polynomial of degree 4 with one maximum (or
# minimum), one point of inflection, and one saddle point.
# Memo: for p(x) = a * (x - x1) * (x - x2)^3 + b the max. (or min.)
# is at x = (3*x1 + x2)/4, the point of inflection is at x =
# (x1 + x2)/2, and the saddle point at x = x2.
m <- function(x, x1 = 0, x2 = 8, a = 0.01, b = 0) {
a * (x - x1) * (x - x2)^3 + b
}
# Note: for m()'s default values a minimum is at x = 2, a point
# of inflection at x = 4, and a saddle point at x = 8.
n <- 100 # Sample size.
set.seed(42) # To guarantee reproducibility.
X <- runif(n, min = -3, max = 15) # X_1, ..., X_n
Y <- m(X) + rnorm(length(X), sd = 5) # Y_1, ..., Y_n
x <- seq(-3, 15, length = 51) # Where the Nadaraya-Watson estimator
# mn of m shall be computed.
mn <- nadwat(x = x, dataX = X, dataY = Y, K = dnorm, h = n^(-1/5))
plot(x = X, y = Y); rug(X)
lines(x = x, y = mn, col = "blue") # The estimator.
curve(m, add = TRUE, col = "red") # The "truth".
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.