Select Optimal Bandwidth
select_bandwidth.RdSelects an optimal bandwidth using the specified method.
Usage
select_bandwidth(
X,
Y = NULL,
method = "cv",
kernel.fun = "normal",
if_approx_kernel = TRUE,
kernel.resol = 1000
)Arguments
- X
A numerical vector of sample data.
- Y
Optional. A numerical vector of sample data for conditional expectation estimation.
- method
A string specifying the bandwidth selection method. Options are "cv" for cross-validation and "silverman" for Silverman's rule of thumb. Defaults to "cv".
- kernel.fun
A string specifying the kernel type. Options include "normal", "epanechnikov", "Schennach2004", and "sinc".
- if_approx_kernel
Logical. If TRUE, uses approximations for the kernel function.
- kernel.resol
The resolution for kernel function approximation.
Examples
# Generate sample data
X <- rnorm(100)
# Get optimal bandwidth using cross-validation with normal kernel
h_opt <- select_bandwidth(X, method = "cv", kernel.fun = "normal")
# Get optimal bandwidth using Silverman's rule with Schennach kernel
h_opt <- select_bandwidth(X, method = "silverman", kernel.fun = "Schennach2004")