Local polynomial regression
Fit weighted local Taylor models, derive reproduction identities, and understand boundary correction without assuming positive prediction weights.
On this page
The question for today
What you’ll understand
- Construct local-linear normal equations at a target point.
- Use polynomial reproduction to explain boundary behavior.
- Calculate local prediction weights and their conditional variance.
Nonparametric regression estimates the conditional mean of a response rather than the density of the predictors. A local polynomial fits a small Taylor-like model around each target location using nearby observations. The coefficients change with that location, so the global fitted curve need not be one polynomial. Local-linear fitting is especially useful near a boundary: it reproduces a line even when observations lie mostly on one side. That benefit is paid for by potentially negative prediction weights and by the need for a well-conditioned local design.
Fit around the point where a prediction is needed
Write with conditional mean-zero errors. At a target x, form polynomial coordinates in and minimize weighted squared residuals using nonnegative kernel weights. The fitted intercept estimates m(x); the fitted slope in a degree-one model estimates its local derivative only under additional smoothness and shrinking-bandwidth conditions. Scaling polynomial coordinates by h can improve numerical conditioning, but changes the interpretation of the slope coefficient by the corresponding factor.
Condition on the observed predictors when calculating a finite-sample fit. The weighted Gram matrix must be invertible on the polynomial columns used; a local-linear fit needs at least two distinct predictor values with positive weights. A zero denominator or nearly singular matrix is a local-data problem, not proof that the underlying mean is undefined. Random-design asymptotics typically require a positive design density near the target and enough observations inside the shrinking window, in addition to assumptions on the errors and regression function.
Reproduction identities remove the linear bias
For an invertible local-linear design, the estimate is a weighted sum , where the prediction weights sum to one and their first centered moment is zero. Therefore constant and linear mean functions are reproduced exactly conditional on the predictors. These identities hold even near a boundary. In contrast, a local-constant kernel average generally has a nonzero first moment in a one-sided window and can inherit a first-order boundary bias from a sloping mean.
The original least-squares weights are nonnegative, but the derived prediction weights need not be. Negative prediction weights are how a boundary fit can extrapolate a line back to the target. Thus a local-linear prediction need not lie between the observed responses. With independent homoskedastic errors conditional on the predictors, its variance is sigma squared times the sum of squared prediction weights. Large positive and negative weights can increase that variance substantially; polynomial reproduction does not by itself guarantee a stable estimate.
Local approximation and sampling error are separate
A Taylor expansion explains why reproducing a line helps when the true regression curve has a continuous second derivative. With standard regular kernels, a positive regular design density and a nonsingular limiting local moment matrix, local-linear bias is of order h squared, including at an ordinary one-sided support boundary; variance has order one over nh in one dimension. At a boundary the constants differ from the interior constants. These are local asymptotic statements, not guarantees for an empty window or a discontinuous mean.
Higher-degree fits reproduce more polynomial terms but require more information and can be unstable if the local geometry is poor. Choosing degree and bandwidth by visual flexibility alone can turn a sparse neighborhood into an extrapolation problem. The target is the conditional mean, so residual prediction error also includes irreducible response noise. A confidence interval for the mean is consequently narrower than a prediction interval for a new individual response, and both must account for any smoothing bias that remains relevant at the selected bandwidth.
Work it through
A boundary fit with a negative prediction weight
At target x=0 use predictor values 0,1,2, responses 1,2,2, and equal positive kernel weights. Find the local-linear intercept and compare it with the local-constant estimate.
The normal-equation matrix is [[3,3],[3,5]], and the right side is [5,6]. Its determinant is six, so the local-linear design is invertible.
Solving gives intercept (25−18)/6=7/6 and slope (18−15)/6=1/2. The intercept weights are 5/6,1/3,−1/6; they sum to one and their predictor-weighted sum is zero.
Applying the weights gives 5/6+2/3−1/3=7/6. The local-constant average is 5/3. The negative last weight is compatible with nonnegative kernel fitting weights and implements linear reproduction at the boundary.
The local-linear estimate is 7/6. Under conditional independent variance sigma², its variance is (5/6)sigma², compared with sigma²/3 for the equal average.
The living notebook
Explore the model
Interactive lab · function
Inspect curvature left after a tangent fit
Pause and Reset, then set both controls to coefficient a=1 and position x=0.5; predict value 0.25 and slope 1. Reset and set a=2 and x=0.5; predict value 0.5 and slope 2. For this quadratic, a tangent misses nearby values by exactly a times the squared displacement. The instrument exposes that deterministic Taylor remainder; it does not fit data or calculate kernel weights.
- y at chosen x
- 0.608
- Tangent slope · 2ax
- 1.35
- Signed area · ax³/3
- 0.182
This lab uses only y = ax². Playback traces the curve within the fixed integration interval from 0 to x; it does not estimate numerical error or change the chosen point. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forReproducing a tangent removes constant and linear error, leaving curvature to control the leading local approximation.
Pause & reason
Check your understanding
Your turn
Try it yourself
Keep predictor values 0,1,2 and equal local weights at target zero, but use responses 2,5,8. Find the local-linear and local-constant predictions and explain the difference.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
The responses lie on one line. Use reproduction or apply the intercept weights from the example.
Compare with the solution
The responses satisfy Y=2+3X exactly, so the local-linear intercept is two and the slope is three. Direct weighting gives (5/6)2+(1/3)5−(1/6)8=2. The local-constant estimate is five, the response average, which is centered at the average predictor one rather than at the target zero. This deterministic reproduction comparison does not mean that local-linear fitting always has smaller mean squared error once random noise is included.
Keep the idea
Take it with you
- Local polynomials fit a new weighted model at each target.
- Local-linear moment identities reproduce lines even in one-sided windows.
- Negative prediction weights can remove bias while increasing conditional variance.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.