[R] Span for loess regression
varin sacha
v@r|n@@ch@ @end|ng |rom y@hoo@|r
Tue Apr 14 23:00:34 CEST 2020
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
}
#######################################################################
More information about the R-help
mailing list