# Computing lowess mean value

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();

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.