Skip to content

Local polynomial regression and LOESS

Local polynomial regression fits nearby data at each target. See how a local line handles a boundary, why response weights can be negative, and how LOESS settings differ.

Local polynomial regression estimates a regression curve by fitting a low-degree polynomial to observations near each target point, then reading off its fitted value there. LOESS is a family of local regression smoothers typically using nearest-neighbour neighbourhoods and distance weights, with optional robust refitting. A quant can use these methods to inspect a curved relationship—such as trading cost against order size—without imposing one polynomial over the entire sample. The fitted curve describes the data; it does not by itself establish a causal cost law.

The distinction that matters near an edge is simple: averaging nearby responses ignores their slope, while fitting a local line can account for it.

Fit near the question, then move the question

Write the conditional mean as m(x)=E[Y∣X=x]m(x)=\mathbb{E}[Y\mid X=x]. For one predictor, a target x0x_0 and a degree pp, solve

β^(x0)=arg⁡min⁡β∑i=1nwi(x0)[yi−∑j=0pβj(xi−x0)j]2,m^(x0)=β^0(x0).\hat{\boldsymbol{\beta}}(x_0) =\arg\min_{\boldsymbol{\beta}}\sum_{i=1}^n w_i(x_0)\left[y_i-\sum_{j=0}^{p}\beta_j(x_i-x_0)^j\right]^2, \qquad \hat m(x_0)=\hat\beta_0(x_0).
The centring makes the intercept the prediction at the target. This is weighted least squares, repeated at different targets. Degree zero gives a local constant; degree one gives a local line. The collection of local predictions can form a curved smoother even though each individual fit is a line. See García-Portugués, §3.2.2.
For a fixed-bandwidth version, a common specification is wi(x0)=K((xi−x0)/h)w_i(x_0)=K((x_i-x_0)/h), with a nonnegative kernel KK and a bandwidth h>0h>0 measured in predictor units. These distance weights express locality; they need not be inverse error variances. With kernel weights, degree zero gives Nadaraya–Watson regression.

A boundary where averaging misses the trend

Take the constructed observations below, in arbitrary units. Estimate at the left boundary x0=0x_0=0, using fitting weight 1 for every observation.
Predictor xix_iResponse yiy_iFitting weight
001
111
221

A local constant minimises the sum of squared deviations from a single value, so it returns (0+1+2)/3=1(0+1+2)/3=1. The underlying line m(x)=xm(x)=x has value zero at the target. Averaging observations lying entirely to its right shifts the estimate upward.

A local line minimises

(0−β0)2+(1−β0−β1)2+(2−β0−2β1)2.(0-\beta_0)^2+(1-\beta_0-\beta_1)^2+(2-\beta_0-2\beta_1)^2.
The unique minimiser is β^0=0\hat\beta_0=0, β^1=1\hat\beta_1=1, with zero residuals. Its boundary estimate is therefore 0, rather than 1. The uniqueness follows because the intercept and predictor columns are linearly independent.
Constructed points at x and y equal to 0, 1 and 2, all with fitting weight 1. At target x=0 the local line estimates 0 and the local constant estimates 1. The line's equivalent response weights are 5/6, 1/3 and minus 1/6.
Constructed points at x and y equal to 0, 1 and 2, all with fitting weight 1. At target x=0 the local line estimates 0 and the local constant estimates 1. The line's equivalent response weights are 5/6, 1/3 and minus 1/6.
Figure: A single local fit at the left boundary recovers the linear trend. Its equivalent response weights include a negative value, although every fitting weight is positive.

This is polynomial reproduction: with a full-rank weighted design, unpenalised degree-pp fitting recovers noiseless polynomial responses of degree at most pp. It is not a statement that every nonlinear curve is estimated without bias. For example, keep the same predictors and fitting weights but change the responses to yi=xi2y_i=x_i^2: the fitted local-line intercept becomes −1/3-1/3, although the true quadratic equals zero at the target.

Why a positive-weight fit can have a negative weight

For the original three predictors, the fitted intercept can be written directly in terms of the responses:

m^(0)=56y0+13y1−16y2.\hat m(0)=\frac56 y_0+\frac13 y_1-\frac16 y_2.
Here the subscripts identify the observations at predictor values 0, 1 and 2. These equivalent response weights are different from the weights inside the squared-error objective. They add to one, preserving a constant, and their weighted predictor values add to zero, cancelling the slope at x0=0x_0=0. A negative weight makes that cancellation possible with observations on only one side.

Consequently, a local polynomial prediction need not lie between the observed responses or respect a positivity constraint. The quadratic counterexample above illustrates this directly. Positive kernels alone do not enforce a positive fitted curve.

There is also a variance cost in this example. Keep the predictors fixed and suppose the responses equal xix_i plus independent, zero-mean errors with common variance σ2\sigma^2. Then

Var(m^linear(0))=56σ2,Var(m^constant(0))=13σ2.\text{Var}(\hat m_{\mathrm{linear}}(0))=\frac56\sigma^2, \qquad \text{Var}(\hat m_{\mathrm{constant}}(0))=\frac13\sigma^2.
These follow by summing squared response weights; see Chen's linear-smoother formulation. The line removes the slope bias here while having higher variance. This is a concrete bias–variance trade-off, rather than a universal ranking of the two estimators.

What LOESS adds to the specification

A fixed distance bandwidth and a nearest-neighbour span are different choices. A span selects a fraction of training observations near each target. The neighbourhood's physical width therefore changes with predictor density: it can be narrow in a dense region and wide in a sparse one.

Implementation details matter:

  • R's stats::loess defaults to degree 2 and span 0.75. For spans below one, it uses a neighbourhood containing the specified fraction of observations and tricube distance weights. Its default family="gaussian" uses weighted least squares; family="symmetric" adds residual-based robust iterations using Tukey's biweight. Robust refitting is therefore an option, not an automatic property of every LOESS fit. See the official R documentation.
  • Python's statsmodels.lowess implements local linear fits, with defaults frac=2/3 and it=3; it controls residual-based reweightings. Its delta option can replace some local regressions with interpolation. See the official statsmodels documentation.

Record the implementation, degree, span or bandwidth, distance kernel and robust settings when reporting a result. With fixed predictor-based weights, local polynomial least squares is linear in the responses. Residual-based robust weights depend on the responses, so the final robust smoother generally loses that property.

Where a smooth-looking curve can mislead

A fit needs enough distinct, positively weighted predictor values to identify its coefficients: in one dimension, at least p+1p+1 for degree pp. Counting neighbours alone is insufficient if predictor values repeat or the kernel gives some neighbours zero weight. A nearly singular design can produce unstable predictions even when a numerical solution exists.
Bandwidth or span selection is part of fitting. A very small neighbourhood can chase noise; a wide one can blur genuine curvature. Use validation appropriate to the intended prediction task, keeping the final test set out of that choice. For financial time series, respect information availability: a smoother fitted across a complete historical sample may use future responses to estimate a past date, creating look-ahead bias if treated as an implementable trading signal.

Extrapolation beyond observed support is especially fragile. Recovering a straight line in the constructed example does not supply evidence for how an unknown relationship behaves outside the data. Nor does unconstrained LOESS guarantee the economic shape restrictions required for a pricing curve.

For a wider comparison with other nonlinear methods, Beyond Linearity: Splines, Local Regression, and Generalized Additive Models develops span-based local fitting alongside splines and additive models. A public preview is available; the full lesson requires membership.

Sources

  • Eduardo García-Portugués, A Short Course on Nonparametric Curve Estimation, §3.2.1–3.2.2: Kernel regression estimation: local-constant and local-polynomial objectives, centred design and equivalent response weights.
  • Yen-Chi Chen, University of Washington, Lecture 7: Nonparametric Regression, “Local Polynomial Regression” and “Linear Smoother”: matrix formulation and response-weight representation.
  • R stats, Local Polynomial Regression Fitting, Usage, Arguments and Details: degree, span, tricube weighting and robust family.
  • statsmodels, LOWESS documentation, signature, Parameters and Notes: local-linear implementation and reweighting/interpolation controls.
Last updated
  • local regression
  • loess
  • nonparametric regression
  • boundary bias
  • smoothing
← Back to the glossaryBack to top ↑