This function demonstrates the underlying calculations of loess
curves.
Given x
and y
vectors it will create a scatterplot and
add 2 loess fit lines (one using straight loess smooth with linear
interpolation and one that does a spline interpolation of the loess
fit).
The function then waits for the user to click on the plot. The
function then shows the window of points (centered at the x
value clicked on) used in the weighting for predicting that point and
shows a circle around each point in the window where the area of the
circle is proportional to the weight of that point in the linear fit.
The function also shows the linear (or quadratic) fit used to predict
at the selected point.
The basic steps of the loess algorithm (as demonstrated by the
function) is that to predict the y-value for a given x-value the
computer:
1. Find all the points within a window around the x-value (the width
of the window is based on the parameter span
).
2. Weight the points in the window with points nearest the x-value
having the highest weight.
3. Fit a weighted linear (quadratic) line to the points in the
window.
4. Use the y-value of the fitted line (curve) at the x-value to give
loess prediction at that x-value.
Clicking on another point in the graph will replot with the new
situation.
Right click and select 'stop' to end the demonstration.