I am trying to understand the different behaviors of these two smoothing functions when given apparently equivalent inputs. My understanding was that locpoly
just takes a fixed bandwidth argument, while locfit
can also include a varying part in its smoothing parameter (a nearest-neighbors fraction, "nn
"). I thought setting this varying part to zero in locfit
should make the "h
" component act like the fixed bandwidth used in locpoly
, but this is evidently not the case.
A working example:
library(KernSmooth)
library(locfit)
set.seed(314)
n <- 100
x <- runif(n, 0, 1)
eps <- rnorm(n, 0, 1)
y <- sin(2 * pi * x) + eps
plot(x, y)
lines(locpoly(x, y, bandwidth=0.05, degree=1), col=3)
lines(locfit(y ~ lp(x, nn=0, h=0.05, deg=1)), col=4)
Produces this plot:
locpoly
gives the smooth green line, and locfit
gives the wiggly blue line. Clearly, locfit
has a smaller "effective" bandwidth here, even though the supposed bandwidth parameter has the same value for each.
What are these functions doing differently?