| select_bandwidth | R Documentation |
Minimises one of the criteria in [bcv_criterion()] over m = 1/h in
'm_range' with [stats::optimize()], optionally after a coarse grid search.
select_bandwidth(
x,
fun,
selector = c("bcv", "rlcv", "wbcv"),
m_range = c(10, 50),
loo = NULL,
grid = NULL,
u_scheme = NULL,
optimizer = NULL
)
x |
numeric sample (sorted internally). |
fun |
an estimator with signature 'fun(u, x, h)', e.g. [qdf_kernel()]. Extra arguments (such as 'H' for [qdf_soni()]) should be bound with a closure before calling. |
selector |
'"bcv"', '"rlcv"' or '"wbcv"'. |
m_range |
numeric length-2 range for |
loo |
logical; if 'TRUE' (default) leave-one-out fits are computed
exactly (by refitting without observation |
grid |
search method: '0' (the default, as in the published simulations) runs [stats::optimize()] directly over 'm_range'; an integer 'grid > 0' first evaluates the criterion on that many equally spaced points and then runs 'optimize()' in the bracket around the grid minimum; '"exhaustive"' evaluates the criterion at every integer 'm' in 'm_range' and returns the global minimiser. When a criterion is multimodal in 'm', 'optimize()' can return an interior local minimum, while the global minimiser can lie at an end of 'm_range'; boundary solutions are flagged (see below). 'NULL' is the same as '0'. |
u_scheme |
grid on which the criterion is evaluated: '"i/n"' (the published convention) or '"i/(n+1)"'. |
optimizer |
optional function 'optimizer(f, interval)' used instead of [stats::optimize()]; it must return a list with elements 'minimum' and 'objective'. Useful to plug in a global optimiser for criteria with several local minima, e.g. 'function(f, interval) { g <- seq(interval[1], interval[2], length.out = 200); v <- sapply(g, f); list(minimum = g[which.min(v)], objective = min(v)) }' for an exhaustive grid search. When 'optimizer' is supplied it is used, and 'grid = "exhaustive"' is treated as 'grid = 0'. |
a list with 'h', 'm', 'selector', 'criterion' (the minimised value) and 'm_range'; 'at_boundary' (logical) and 'boundary' ('"lower"', '"upper"' or 'NA'), which record a minimiser at an end of 'm_range'; with 'grid = "exhaustive"' also the evaluated grid 'grid_m' and criterion values 'grid_cv'.
If the minimiser lies at either end of 'm_range', whatever the search method, the criterion did not select a bandwidth in that range. A warning is issued and 'at_boundary = TRUE' is returned; widen 'm_range' or give the bandwidth directly.
x <- rgamma(60, 5, 1)
select_bandwidth(x, qdf_poisson, "bcv", m_range = c(10, 50))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.