Description Usage Arguments Value See Also Examples
Selection of the bandwidth that yields the smallest leave-one-out cross-validation (LOOCV) error over a supplied grid.
1 2 3 4 5 6 7 8 9 10 11 12 | bw_CV_fun(
X,
Y,
kernel = epanechnikov,
bw_grid,
degree = 1L,
kernel_left = epanechnikov_left,
boundary_left = NA,
boundary_right = NA,
boundary_adjustment = FALSE,
plot = TRUE
)
|
X |
Data for the regressor (vector). |
Y |
Data for the regressand (vector). |
kernel |
Kernel (function). Default is |
bw_grid |
Bandwidth grid to find global minimum of CV error (vector). |
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 |
plot |
Plot CV error over bandwidth grid (boolean). Default is |
CV optimal bandwidth (scalar) and plot of CV errors if plot == TRUE.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 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_grid <- seq(0.05, 0.2, length.out = 200)
# Local polynomial estimator
bw_CV_fun(X = X, Y = Y, kernel = epanechnikov, bw_grid = bw_grid, degree = 1L,
kernel_left = epanechnikov_left,
boundary_left = NA, boundary_right = NA,
boundary_adjustment = FALSE,
plot = TRUE)
# Boundary-adjusted Nadaraya-Watson estimator
bw_CV_fun(X = X, Y = Y, kernel = epanechnikov, bw_grid = bw_grid, degree = 0L,
kernel_left = epanechnikov_left,
boundary_left = 0, boundary_right = 1,
boundary_adjustment = TRUE,
plot = TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.