Description Usage Arguments Details Value Examples
Leave-one-out cross-validation (LOOCV) error for a given bandwidth, either for the local polynomial estimator or the boundary-adjusted Nadaraya-Watson estimator.
1 2 3 4 5 6 7 8 9 10 11 | CV_error_fun(
X,
Y,
kernel = epanechnikov,
bw,
degree = 1L,
kernel_left = epanechnikov_left,
boundary_left = NA,
boundary_right = NA,
boundary_adjustment = FALSE
)
|
X |
Data for the regressor (vector). |
Y |
Data for the regressand (vector). |
kernel |
Kernel (function). Default is |
bw |
Bandwidth (scalar). |
degree |
Degree of the locally fitted polynomial (integer). Default is |
kernel_left |
Left boundary kernels (function). Default is |
boundary_left |
Lower boundary of the support of X (scalar). Default is |
boundary_right |
Upper boundary of the support of X (scalar). Default is |
boundary_adjustment |
Explicit boundary adjustment (boolean). Default is |
The LOOCV error function is the mean squared prediction errors.
LOOCV error for bandwidth bw
(scalar).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #m_fun <- function(x) {sin(2*pi*x)} # True regression function
#n <- 100 # Sample size
#X <- seq(0, 1, length.out = n) # Data for the regressor
#m_X <- m_fun(X) # True values of regression function
#epsilon <- rnorm(n, sd = 0.25) # Error term
#Y <- m_X + epsilon # Data for the regressand
#bw <- 0.2 # Bandwidth
# Local polynomial estimator
#CV_error_fun(X = X, Y = Y, kernel = epanechnikov, bw = bw, degree = 1L,
# kernel_left = epanechnikov_left,
# boundary_left = NA, boundary_right = NA,
# boundary_adjustment = FALSE)
# Boundary-adjusted Nadaraya-Watson estimator
#CV_error_fun(X = X, Y = Y, kernel = epanechnikov, bw = bw, degree = 0L,
# kernel_left = epanechnikov_left,
# boundary_left = 0, boundary_right = 1,
# boundary_adjustment = TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.