Tal Galili
Tal Galili

Reputation: 25356

Extracting the fitted terms in the local polynomial function of a loess (in R) (NOT predict())

How can I extract what the parameters that the loess function fitted for the polynomial function it uses, for a particular x of my data?

For example, in:

 cars.lo <- loess(dist ~ speed, cars)
 cars.lo

What did it fit for when cars.lo$x == 5 ?

Update: I want the parameters of the polynomial function, not the prediction (predict) of the loess.

I am asking for it to get an estimate of the slope in that point.

Thanks, Tal

Upvotes: 2

Views: 1218

Answers (3)

hadley
hadley

Reputation: 103948

I think you're going to be on your own for this one. I'd start by reading the references in lowess, and then read the source for the C lowess function. I'd recommend starting there instead of with loess because it's an older and slightly simpler algorithm that you might find easier to adapt for your needs.

Upvotes: 0

Rob Hyndman
Rob Hyndman

Reputation: 31820

I would compute the predicted values at x, x+eps, x-eps, and then fit a quadratic to the results. It's not very efficient in computer time, but if you haven't got to do it very often, it is very efficient in programmer time.

Upvotes: 2

Yorgos
Yorgos

Reputation: 30485

I would say

predict(cars.lo, data.frame(speed=5))
[1] 7.797353

Upvotes: 1

Related Questions