Skip to content

Span for loess regression

3 messages · varin sacha, Ivan Krylov

#
Dear R-experts,

I am trying to find the best span for my loess regression. Here below a reproducible example. I don't get the result. Am I missing something ?

Many thanks for your help.

############################################################
a<-c(2,3,4,3,2,6,5,7,4,5,12,13,21,6,4,5,6,7)
b<-c(12,13,32,14,23,21,76,34,12,32,43,23,12,32,43,12,32,11)
model <- loess(b ~ a)
bestLoess <- function(model, spans = c(.05, .95)) {
?f <- function(span) {
???????? mod <- update(model, span = span)
???????? loessGCV(mod)[["gcv"]]
???? }
???? result <- optimize(f, spans)
???? result
?}
#######################################################################
#
On Tue, 14 Apr 2020 21:00:34 +0000 (UTC)
varin sacha via R-help <r-help at r-project.org> wrote:

            
Thanks for providing a concise piece of code.

The code doesn't return any visible results because the bestLoess
function created by it is never called. To get the results you should
call the function and pass the model object to it as an argument.

Another problem with the code is missing definition for loessGCV
function. I can only assume that the code is supposed to reference the
recently archived NormalizeMets CRAN package.
#
Dear Ivan,

Many thanks I got it now. 

Best,




Le mercredi 15 avril 2020 ? 09:49:26 UTC+2, Ivan Krylov <krylov.r00t at gmail.com> a ?crit : 





On Tue, 14 Apr 2020 21:00:34 +0000 (UTC)
varin sacha via R-help <r-help at r-project.org> wrote:

            
Thanks for providing a concise piece of code.

The code doesn't return any visible results because the bestLoess
function created by it is never called. To get the results you should
call the function and pass the model object to it as an argument.

Another problem with the code is missing definition for loessGCV
function. I can only assume that the code is supposed to reference the
recently archived NormalizeMets CRAN package.