我的结果是 NA。我究竟做错了什么?
data(Boston, package='MASS')
x <- Boston$dis
y <- Boston$nox
n <- length(x)
cvs <- rep(0, n)
for(i in 1:n){
xi <- x[-i]
yi <- y[-i]
d <- loess(yi~xi, span=0.2, degree=2)
cvs[i] <- (y[i] - predict(d, newdata=data.frame(xi=x[i])))^2
}
mean(cvs)