I am trying to reimplement the lowess algorithm in java. I read the matlab page explaining lowess with the following steps:
- Compute the regression weights for each data point in the span.
- A weighted linear least-squares regression is performed. For lowess, the regression uses a first degree polynomial.
- 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();
reg.addObservations(kernel,y);
double rm = reg.getIntercept();
double rm0 = reg.getSlope();
- Where should I determine the degree (first degree polynomial)?
- 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?