Solved – How to interpolate (spline, LOESS, etc.) with a mix of critical and non-critical points

interpolationloessregressionsplines

The data we are interpolating is monotonically increasing (for example, a car's odometer reading). We have two types of points we'd like the solution to interpolate through. The solution surface must pass through critical points. The solution does not have to pass through non-critical points, but must aim to minimize distance to them. See attached image.

From my understanding local regression options such as LOESS can create a smoothed interpolation solution, but cannot be forced to cross through certain points. An interpolating spline is forced to cross all points, but will not try to optimize its knot parameters to reduce distance to non-critical points. Do any packages in R achieve the type of solution sought?

enter image description here

Thank you.

Best Answer

You may want to use weighted loess, as in:

a = data.frame(x=1:10, y=c(2,5,3,4,5,9,7,8,9,10))
fit1 = loess(y~x, a)  # unweighted loess fit
fit2 = loess(y~x, a, weights = c(0.1,1,0.1,0.1,0.1,0.1,1,0.1,0.1,0.1))
plot(1:10, predict(fit1), col="blue", type="l", ylim=c(1,10)) # unweighted fit
lines(1:10, predict(fit3), col="darkgreen") # weighted fit
points(y~x, a, col="brown", type="b") # all points 
points(y~x, a[c(2,7),], col="red") # points of high importance

plot

One issue with this approach is that weighted regression assumes that weights are known exactly, while this is very rarely the case. Some ideas on estimating weights for the case of weighted linear regression can be found here. Quite often however even a vague idea on differences in weights may work better than nothing. For example, here even though there was no guarantee that the loess fitted line will go exactly through the "important" points, this was very nearly the case with a rather arbitrary choice of weights.