cv_bandwidth {rbbnp} | R Documentation |
Cross-Validation for Bandwidth Selection
Description
Implements least-squares cross-validation for bandwidth selection with any kernel function. Uses the self-convolution approach for accurate estimation of the integral term.
Usage
cv_bandwidth(
X,
h_grid = NULL,
kernel_func,
kernel_type = "normal",
grid_size = 512
)
Arguments
X |
A numerical vector of sample data. |
h_grid |
A numerical vector of bandwidth values to evaluate. If NULL (default), a grid is automatically generated based on the range and distribution of the data. |
kernel_func |
The kernel function to use for cross-validation. |
kernel_type |
A string identifying the kernel type, used only for reference bandwidth. |
grid_size |
Number of grid points for evaluation. Default is 512. |
Value
A scalar representing the optimal bandwidth that minimizes the cross-validation score.
Examples
# Generate sample data
X <- rnorm(100)
# Get optimal bandwidth using cross-validation with a normal kernel
kernel_functions <- create_kernel_functions("normal")
h_opt <- cv_bandwidth(X, kernel_func = kernel_functions$kernel,
kernel_type = kernel_functions$kernel_type)
[Package rbbnp version 0.3.0 Index]