Description Usage Arguments Value See Also Examples
This function computes the leave-one-out cross-validation criterion CV(h) for the trial bandwidths supplied in the vector h
, where
CV(h) = \frac{1}{n}∑_{i=1}^{n} (Y_i-\hat{m}^{(-i)}_h(x_i))^2
Used in find_hcv
to find an optimal data-driven bandwidth.
1 |
h |
a vector of bandwidths at which to evaluate CV(h) |
data |
the data, specified as a data frame containing two components |
estimator |
an R function for the estimator, with inputs and return type similar to |
... |
additional arguments to be passed to the estimator (e.g. |
The function returns a list with components
h |
the vector of bandwidths used |
cv |
a vector containing the computed values of CV(h) |
find_hcv
1 2 3 4 5 6 7 8 9 10 | # simulate and plot some data
m <- function(x) (x^2+1)*sin(2*pi*x*((1-x) + 4*x))
x <- sort(runif(100))
y <- m(x) + rnorm(length(x), sd=0.1)
simdata <- data.frame(x=x,y=y)
# create sequence of bandwidths, compute and plot CV function
h <- seq(from=0,to=0.1,length=100)
info <- lscv(h, simdata, nw, kernel=gauss)
plot(info$h,info$cv, type="l", xlab="h", ylab="CV(h)")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.