I am trying to reimplement the lowess algorithm in java. I read the matlab page explaining lowess with the following steps:

  1. Compute the regression weights for each data point in the span.
  2. A weighted linear least-squares regression is performed. For lowess, the regression uses a first degree polynomial.
  3. The smoothed value is given by the weighted regression at the predictor value of interest.

I have a list of data points (x,y), and for each data point I compute the weight of neighbors (here, alpha = 0.01, i.e. considering 0.01 of neighbors for smoothing) using tri-cubic kernel (step 1).

I am not sure what method I should use for the second step. Currently I have two arrays, kernel and y. w is the list of weights, d.x is the x position of the data point, and the d.y is the y position of the data point. j refers to the *j*th neighbor. The smoothed value should be computed on the y axis.

kernel[j][0] = w[j];
kernel[j][1] = w[j]*d.x;
y[j] = w[j]*d.y;

I am using the following lines to compute the regression:

SimpleRegression reg = new SimpleRegression();
double rm = reg.getIntercept();
double rm0 = reg.getSlope();
  1. Where should I determine the degree (first degree polynomial)?
  2. Is what I have correct and is the rm0 is the smoothed value, or I should still do something or use another method for regression?

1 Answer 1


The "first degree polynomial" just means fit a straight line, the other options used in loess is to fit a degree 0 polynomial which just means find the horizontal line or the degree 2 polynomial which means fit a parabola.

If you want to get a better understanding of what is going on you can run the loess.demo function in the TeachingDemos package for R. It plots your data then you click on the plot and for that point it shows which points are included in the window, what their weights are, the fitted line (or parabola) and the resulting prediction point on the loess curve, clicking on a new point will update the graph to show the weights, etc. for that prediction.

  • 3
    $\begingroup$ +1. And I'd add a note of caution: lowess, in some implementations called loess or locfit, is perhaps better thought of not as a single precisely defined method, but as a family of methods depending on polynomial degree, kernel used, whether there is extra robustness built-in, etc. Different implementations won't agree unless they follow exactly the same recipe. $\endgroup$
    – Nick Cox
    Jun 7, 2013 at 7:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.