Mathwords logoMathwords

Local Regression — Definition, Formula & Example

Local regression is a smoothing method that draws a curve through scattered data by fitting a small, separate regression at each location. Each small fit uses only nearby points, and the closest points count the most.

Given data (xi,yi)(x_i, y_i) and a span ff with 0<f≤10 < f \le 1, LOESS estimates the trend at each target value x0x_0. It takes the q=⌊fn⌋q = \lfloor fn \rfloor nearest neighbors of x0x_0 and weights them with a kernel that decreases with distance, usually the tricube. It then fits a polynomial of degree 1 or 2 by weighted least squares. The smoothed value y^(x0)\hat{y}(x_0) is that polynomial evaluated at x0x_0. Repeating this over many x0x_0 traces the curve. LOWESS (Cleveland, 1979) adds robustness iterations that downweight points with large residuals.

Key Formula

min⁡a, b ∑i=1nwi(yi−a−b(xi−x0))2,wi={(1−∣xi−x0d∣3)3∣xi−x0∣<d0otherwise\min_{a,\,b}\ \sum_{i=1}^{n} w_i\big(y_i - a - b(x_i - x_0)\big)^2, \qquad w_i = \begin{cases}\left(1 - \left|\dfrac{x_i - x_0}{d}\right|^3\right)^3 & |x_i - x_0| < d\\[4pt] 0 & \text{otherwise}\end{cases}
Where:
  • x0x_0 = The target x-value where you want a smoothed estimate
  • wiw_i = Tricube weight of point i: 1 at the target, falling to 0 at distance d
  • dd = Distance from x0x_0 to the q-th nearest data point, where q is set by the span
  • aa = Intercept of the local line. Because x is centered at x0x_0, a equals the smoothed value at x0x_0
  • bb = Slope of the local line near x0x_0

Worked Example

Problem: Hourly temperatures (°F) are recorded as (3, 62), (4, 64), (5, 70), (6, 68), (7, 75), where x is hours after 6 a.m. Use degree-1 local regression with the q = 5 nearest points and tricube weights to find the smoothed temperature at x = 5.
Step 1: The 5 nearest points to x = 5 are all five readings. The farthest are x = 3 and x = 7, so the bandwidth is d = 2. Divide each distance by d to get the scaled distances.
∣xi−5∣2:1, 12, 0, 12, 1\frac{|x_i - 5|}{2}: \quad 1,\ \tfrac{1}{2},\ 0,\ \tfrac{1}{2},\ 1
Step 2: Apply the tricube weight. Points at scaled distance 1 get weight 0, the target point gets weight 1, and the two next-door points get a weight in between.
w=(1−(12)3)3=(78)3=343512≈0.670w = \left(1 - \left(\tfrac{1}{2}\right)^3\right)^3 = \left(\tfrac{7}{8}\right)^3 = \tfrac{343}{512} \approx 0.670
Step 3: A weighted least-squares line passes through the weighted means. The weights are symmetric around 5, so the weighted mean of x is exactly 5. That means the local line's value at x = 5 equals the weighted mean of y.
y^(5)=343512(64)+1(70)+343512(68)343512+1+343512=40558599≈67.71\hat{y}(5) = \frac{\tfrac{343}{512}(64) + 1(70) + \tfrac{343}{512}(68)}{\tfrac{343}{512} + 1 + \tfrac{343}{512}} = \frac{40558}{599} \approx 67.71
Answer: The smoothed temperature at x = 5 is about 67.71 °F. The raw reading of 70 °F is pulled toward its neighbors, which is how LOESS evens out a local spike while still following the overall trend.

Why It Matters

Statistics software often adds a LOESS curve to residual plots so you can spot curvature that a linear model missed. In R, ggplot2's geom_smooth uses LOESS by default for data sets under 1,000 points. In time-series work, the STL method uses LOESS to split data such as monthly sales into trend and seasonal parts.

Common Mistakes

Mistake: Asking for the equation of the LOESS curve, or using it to predict far outside the data.
Correction: LOESS has no single global equation. Every x-value gets its own local fit. Report the curve as a graph or a table of fitted values. Avoid extrapolation, because the edges have few neighbors and the estimates there are unreliable.

Related Terms

  • Linear Regression — The global straight-line fit that LOESS repeats locally
  • Regression — Parent family of methods for modeling y from x
  • Residual Plot — Often overlaid with a LOESS curve to reveal curvature
  • Extrapolation — Especially unreliable with LOESS beyond the data range
  • Interpolation — Estimating inside the data range, where LOESS works best
  • Weighted Mean — Nearby points get larger weights, as in weighted averages