# [R] coefficients of each local polynomial from loess() or locfit()

From: Liu, Delong (NIH/CIT) [C] <liud2_at_mail.nih.gov>
Date: Mon 08 Jan 2007 - 18:45:55 GMT

Dieter,

Thanks for your suggestions and help. I am not an expert with R programming. In my current application, I am not interested in point prediction from loess(). Instead, I am more interested in obtaining the coefficient estimates of local polynomial from loess(). Is it straightforward to modify loess() so that the coefficient estimates can be put into the return list of loess()?

Delong

```--

Message: 8
Date: Fri, 5 Jan 2007 14:01:46 +0000 (UTC)
From: Dieter Menne <dieter.menne@menne-biomed.de>
Subject: Re: [R] coefficients of each local polynomial from loess() or
locfit()
To: r-help@stat.math.ethz.ch
Message-ID: <loom.20070105T145441-714@post.gmane.org>
Content-Type: text/plain; charset=us-ascii

Liu, Delong (NIH/CIT) [C] <liud2 <at> mail.nih.gov> writes:

>>>
I want to extract estimated coeffiicents of each local polynomial at
given x from loess(),  locfit(), or KernSmooth().  Can some experts
provide me with suggestions?  Thanks.
>>

Try

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

List of 17
\$ n        : int 50
\$ fitted   : num [1:50]  5.89  5.89 12.57 12.57 15.37 ...
\$ residuals: Named num [1:50] -3.894  4.106 -8.568  9.432  0.631 ...
... omitted

..\$ cell       : num 0.2

..\$ family     : chr "gaussian"
..\$ iterations : num 1
\$ kd       :List of 5

..\$ parameter: Named int [1:7] 1 50 2 19 11 1049 849

.. ..- attr(*, "names")= chr [1:7] "d" "n" "vc" "nc" ...

..\$ a        : int [1:19] 1 1 1 1 1 1 1 0 0 0 ...

..\$ xi       : num [1:19] 15 12 19 9 13 17 20 0 0 0 ...
..\$ vert     : num [1:2]  3.90 25.11
..\$ vval     : num [1:22]  5.71  1.72 96.46 10.88 41.21 ...
\$ call     : language loess(formula = dist ~ speed, data = cars)

Looks like kd holds information about the polynomials. Then, try

getAnywhere(predict.loess)

which will show you that the real work is done in function predLoess.
Trying again

getAnywhere(predLoess)

you get an idea how the parameters are used for prediction.

fit[inside] <- .C(R_loess_ifit, as.integer(kd\$parameter),
as.integer(kd\$a), as.double(kd\$xi), as.double(kd\$vert),
as.double(kd\$vval), as.integer(M1), as.double(x.evaluate[inside,

]), fit = double(M1))\$fit

Dieter

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help