#' @export
loess.gcv <- function(x, y){
##uses generalizaed cross validation to find optimum span
nobs <- length(y)
xs <- sort(x, index.return = TRUE)
x <- xs$x
y <- y[xs$ix]
tune.loess <- function(s){
lo <- loess(y ~ x, span = s)
mean((lo$fitted - y)^2) / (1 - lo$trace.hat/nobs)^2
}
os <- optimize(tune.loess, interval = c(.01, 99))$minimum
lo <- loess(y ~ x, span = os)
list(x = x, y = lo$fitted, df = lo$trace.hat, span = os)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.