## Not run: ------------------------------------
# # Example (Old Faithful geyser). Take x=waiting time; y=eruption duration. The sample size n=272.
# xdat=faithful[[2]]
# ydat=faithful[[1]]
# harray=seq(0.5,10,len=100)
# cv=CV_reg(harray,xdat,ydat)
# R=range(xdat)
# h_cv=round(optimize(CV_reg,c(0.01,(R[2]-R[1]/4)),desx=xdat,y=ydat)$minimum,digits=4)
# dev.new()
# plot(harray,cv,'l',lwd=3,xlab="h",ylab="CV(h)",main="CV function for the Old Faithful
# geyser data", cex.lab=1.7,cex.axis=1.7,cex.main=1.5)
# legend(6,0.155,legend="n=272",cex=1.8,bty="n")
# legend(1,0.18,legend=paste("h_CV=",h_cv),cex=2,bty="n")
## ---------------------------------------------
Run the code above in your browser using DataLab