Patrick Li - 1 year ago 173

R Question

I am using

`lowess`

`x`

`y`

`x`

`x=2.5`

`loess`

`lowess`

`set.seed(1)`

x <- 1:10

y <- x + rnorm(x)

fit <- lowess(x, y)

plot(x, y)

lines(fit)

Answer Source

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):

https://www.r-bloggers.com/interpolation-and-smoothing-functions-in-base-r/

**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.