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 and a span with , LOESS estimates the trend at each target value . It takes the nearest neighbors of 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 is that polynomial evaluated at . Repeating this over many traces the curve. LOWESS (Cleveland, 1979) adds robustness iterations that downweight points with large residuals.
Key Formula
Where:
- = The target x-value where you want a smoothed estimate
- = Tricube weight of point i: 1 at the target, falling to 0 at distance d
- = Distance from to the q-th nearest data point, where q is set by the span
- = Intercept of the local line. Because x is centered at , a equals the smoothed value at
- = Slope of the local line near
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.
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.
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.
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.
