Computes the kernel-weighted local mean estimator
m-hat(x) = sum K_h(x - X_i) Y_i divided by sum K_h(x - X_i),
with a Gaussian kernel.
Usage
nw_regression(x, y, x_eval, bandwidth)
Arguments
- x
Numeric vector of observed covariate values, length n.
- y
Numeric vector of observed outcomes, length n.
- x_eval
Numeric vector of evaluation points.
- bandwidth
Positive bandwidth h.
Value
Numeric vector of fitted values at x_eval.
References
Nadaraya, E. A. (1964). On Estimating Regression.
Theory of Probability and Its Applications, 9(1), 141-142.
Examples
set.seed(1)
x <- runif(80); y <- sin(2 * pi * x) + rnorm(80, 0, 0.2)
head(nw_regression(x, y, x_eval = seq(0, 1, 0.25), bandwidth = 0.1))
#> [1] 0.5046354 0.8332669 0.1052262 -0.8154072 -0.5018250