## Artificial example
x <- seq(0, 1, len = 100)
mu <- x + .2 * sin(2 * pi * x)
y <- matrix(mu + rnorm(2000, sd = .25), 20, 100, byrow = TRUE)
h <- c(.005, .01, .02, .05, .1, .15)
cv <- numeric()
for (i in 1:length(h)) cv[i] <- cv.score(h[i], x, y, 1)
plot(h, cv, type = "l")
## Plasma citrate data
## Compare cross-validation scores and bandwidths
## for local linear and local quadratic smoothing
## Not run:
# data(plasma)
# time <- 8:21
# h1 <- seq(.5, 1.3, .05)
# h2 <- seq(.75, 2, .05)
# cv1 <- sapply(h1, cv.score, x = time, y = plasma, degree = 1)
# cv2 <- sapply(h2, cv.score, x = time, y = plasma, degree = 2)
# plot(h1, cv1, type = "l", xlim = range(c(h1,h2)), ylim = range(c(cv1, cv2)),
# xlab = "Bandwidth (hour)", ylab = "CV score",
# main = "Cross validation for local polynomial estimation")
# lines(h2, cv2, col = 2)
# legend("topleft", legend = c("Linear", "Quadratic"), lty = 1,
# col = 1:2, cex = .9)
#
# ## Note: using local linear (resp. quadratic) smoothing
# ## with a bandwidth smaller than .5 (resp. .75) can result
# ## in non-definiteness or numerical instability of the estimator.
# ## End(Not run)
Run the code above in your browser using DataLab