title: Local linear regression in R -- locfit() vs locpoly()
body: <p>I am trying to understand the different behaviors of these two smoothing functions when given apparently equivalent inputs.  My understanding was that <code>locpoly</code> just takes a fixed bandwidth argument, while <code>locfit</code> can also include a varying part in its smoothing parameter (a nearest-neighbors fraction, "<code>nn</code>").  I thought setting this varying part to zero in <code>locfit</code> should make the "<code>h</code>" component act like the fixed bandwidth used in <code>locpoly</code>, but this is evidently not the case.      </p>
  
  <p>A working example:</p>
  
  <pre><code>library(KernSmooth)
  library(locfit)
  set.seed(314)
  
  n &lt;- 100
  x &lt;- runif(n, 0, 1)
  eps &lt;- rnorm(n, 0, 1)
  y &lt;- 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)
  </code></pre>
  
  <p>Produces this plot:</p>
  
  <p><img src="https://i.imgur.com/U62pczY.png" alt="plot of smoothers"></p>
  
  <p><code>locpoly</code> gives the smooth green line, and <code>locfit</code> gives the wiggly blue line.  Clearly, <code>locfit</code> has a smaller "effective" bandwidth here, even though the supposed bandwidth parameter has the same value for each.</p>
  
  <p>What are these functions doing differently?</p>