Patrick Li Patrick Li - 17 days ago 4x
R Question

Prediction at a new value using lowess function in R

I am using

function to fit a regression between two variables
. Now I want to know the fitted value at a new value of
. For example, how do I find the fitted value at
in the following example. I know
can do that, but I want to reproduce someone's plot and he used

x <- 1:10
y <- x + rnorm(x)
fit <- lowess(x, y)
plot(x, y)

enter image description here


Local regression (lowess) is a non-parametric statistical method, it's a not like linear regression where you can use the model directly to estimate new values.

You'll need to take the values from the function (that's why it only returns a list to you), and choose your own interpolation scheme. Use the scheme to predict your new points.

Common technique is spline interpolation (but there're others):

EDIT: I'm pretty sure the predict function does the interpolation for you. I also can't find any information about what exactly predict uses, so I've tried to trace the source code.

else { ## interpolate
## need to eliminate points outside original range - not in pred_

I'm sure the R code calls the underlying C implementation, but it's not well documented so I don't know what algorithm it uses.

My suggestion is: either trust the predict function or roll out your own interpolation algorithm.