Why Add a LOESS Smoother?
A scatterplot shows the individual observations, but a dense cloud of points can make the overall response pattern difficult to see. A straight line is one possible summary, but it requires the pattern to be adequately represented by a single linear trend. When the relationship may bend, a LOESS smoother offers a flexible visual summary: it fits a small regression near each predictor value and joins those local fitted values into a curve.
The curve is an aid to reading the scatterplot, not a replacement for its points. It helps summarize how the average response changes across the observed predictor values without requiring one straight-line relationship for the entire range. It does not, by itself, establish a cause-and-effect relationship or show how certain the pattern is.
How the Local Fits Work
Suppose the data consist of paired observations \((x_i,y_i)\), where \(x_i\) is a quantitative predictor and \(y_i\) is a quantitative response. To find the curve’s value at a target \(x_0\), LOESS identifies a neighborhood of observations around \(x_0\). It assigns each observation in that neighborhood a nonnegative weight \(w_i\) based on its distance from \(x_0\), then fits a low-degree polynomial by weighted least squares. In a local linear fit, the fitted equation near \(x_0\) is \(a+b(x_i-x_0)\); the smoother’s value at \(x_0\) is the fitted intercept \(a\).
A common weighting rule is the tricube weight. If \(d_i=|x_i-x_0|\), and \(h\) is the distance from \(x_0\) to the farthest observation included in its neighborhood, define \(u_i=d_i/h\). For observations with \(u_i<1\), the weight is \((1-u_i^3)^3\); an observation at the neighborhood boundary has weight zero. The exact options can vary across software, so the plotting settings matter. The examples below state their neighborhood and fitting choices explicitly.
This is a local calculation: changing \(x_0\) changes the distances, weights, and fitted coefficients. Repeating the calculation over a sequence of target values produces the points of the curve. A software plotting function usually performs these fits and draws the overlay for you; understanding the calculation explains what the plotted line represents.
Worked Local Fits
Worked Example: A Local Linear Fit Near a Bend
Consider the following hypothetical observations. Use a local linear fit at \(x_0=2\), with all five observations defining the neighborhood and tricube weights.
| \(x_i\) | \(y_i\) | \(d_i=|x_i-2|\) |
|---|---|---|
| 0 | 9 | 2 |
| 1 | 5 | 1 |
| 2 | 3 | 0 |
| 3 | 5 | 1 |
| 4 | 9 | 2 |
Here \(h=2\). The observations at \(x=0\) and \(x=4\) are at the neighborhood boundary, so their weights are zero. At \(x=1\) and \(x=3\), \(u=1/2\), giving the weight
The weights are symmetric around \(x_0=2\), as are the two responses of 5. Thus the weighted local linear fit has slope zero at this target, and its fitted value is the weighted response average. Substituting the nonzero weights gives
The observed response at \(x=2\) is 3, while the local fitted response is about 4.145. That difference is not an error in the calculation: the fitted value summarizes a weighted local pattern rather than copying the response at the target. The result is a curve point at approximately \((2,4.145)\), on the response’s original scale.
Worked Example: A Local Fit on a Straight Pattern
Now use hypothetical responses \(10,12,14,16,18\) at predictor values \(0,1,2,3,4\), respectively. At \(x_0=2\), use the same neighborhood and tricube weights as in the previous example. This data pattern follows \(y=10+2x\).
The two boundary observations again have weight zero, and the observations at \(x=1\) and \(x=3\) each have weight \(0.6699\). Because these weights are symmetric, their effects on the fitted slope are balanced around \(x_0\). The local fitted value is therefore
Using the unrounded weight \(w=0.669921875\), the numerator is \(12w+14+16w=14+28w=32.7578125\), and the denominator is \(1+2w=2.33984375\). Hence
The local smoother returns 14 at \(x=2\), matching the response on this exactly straight pattern. This example illustrates a useful point: LOESS can summarize a straight-looking relationship too. Its flexibility means it does not require the entire relationship to be straight; it does not mean that every fitted curve must visibly bend.
Worked Example: Plotting a Local Constant LOESS Fit
A local polynomial can also have degree zero, meaning the local fit is a weighted constant rather than a weighted line. For the hypothetical U-shaped data in the first example, use that degree-zero fit at \(x_0=2\), again with the stated five-point neighborhood and tricube weights. This calculation shows how a local weighted average becomes one point on the overlay.
A degree-zero fit minimizes the weighted squared deviations from a constant \(a\), so its fitted value is the weighted response average. The boundary observations have zero weight, and the other three responses are \(5,3,5\), with weights \(0.6699,1,0.6699\). Therefore,
To add this result to a scatterplot, keep the five original points visible and place the fitted point at \((2,4.145)\) as part of the smoother. In practice, software repeats the local calculation at many target values and draws the resulting curve. This degree-zero illustration and the local linear fit above happen to agree at this symmetric target; they need not agree at other targets or for other data.
Adding and Reading the Overlay
A useful display begins with a scatterplot of the paired observations, with the predictor on the horizontal axis and the response on the vertical axis. Add a LOESS layer using the plotting software’s smoother option, keeping the raw points visible. The curve should be drawn across the region where the data provide support; it is not a substitute for observations, and its appearance depends on the fitting settings.
Read the curve as a summary of local response levels. For example, if it rises over part of the predictor range, the local fitted responses tend to increase there. If it levels off or turns, the summary indicates a changing pattern rather than one constant straight-line direction. Such descriptions refer to the plotted association, not to an effect caused by changing the predictor.
LOESS is especially useful as an exploratory overlay when a single straight line might hide a changing pattern. It does not determine which model should ultimately be used, and a smooth-looking curve does not prove that the underlying relationship has that exact form. The individual observations remain important: they show how much data the curve is summarizing and where it is being fitted.
Common Mistakes and Practical Limits
- Replacing the scatterplot with the curve. A smoother suppresses detail. Keep the observed points visible so that the summary can be compared with the data.
- Calling the curve a global straight-line fit. LOESS fits locally, so different parts of the curve can have different slopes.
- Treating the curve as proof of causation. A visual association alone does not show that changing \(x\) causes a change in \(y\).
- Reading beyond the observed predictor values as if supported. Local fits depend on nearby observations. Where data are scarce, a plotted extension should not be treated as well-supported evidence.
- Assuming the overlay is a confidence interval or prediction. The basic smoother is a fitted summary curve, not an interval around a parameter or a guarantee about a future response.
A useful workflow is to plot the points first, add the LOESS overlay, and then describe the broad pattern in context. Note the predictor and response units when describing rises, falls, or approximate levels. The curve is most informative when it helps summarize the cloud without being mistaken for more than a visual summary.
Check Your Understanding
Try these questions without looking back.
- In a LOESS fit at \(x_0\), why does an observation close to \(x_0\) generally have more influence than a distant observation?
- For tricube weights with \(u=1/2\), calculate \((1-u^3)^3\) to four decimal places.
- What does the LOESS fitted value at a target \(x_0\) represent in a local linear fit?
- Why should the raw observations usually remain visible after adding a smoother?
- Does a LOESS curve by itself establish that the predictor causes a change in the response? Explain briefly.