select_bandwidth: Select the smoothing parameter of a quantile density...

View source: R/bandwidth.R

select_bandwidthR Documentation

Select the smoothing parameter of a quantile density estimator

Description

Minimises one of the criteria in [bcv_criterion()] over m = 1/h in 'm_range' with [stats::optimize()], optionally after a coarse grid search.

Usage

select_bandwidth(
  x,
  fun,
  selector = c("bcv", "rlcv", "wbcv"),
  m_range = c(10, 50),
  loo = NULL,
  grid = NULL,
  u_scheme = NULL,
  optimizer = NULL
)

Arguments

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 m = 1/h.

loo

logical; if 'TRUE' (default) leave-one-out fits are computed exactly (by refitting without observation i, or by the index shift of [qdf_bernstein_loo()] for the Bernstein estimator). If 'FALSE' the scaling approximation \hat q_{-i} \approx \hat q\,(n-1)/n is used. The approximation is not valid for estimators built from order statistics: removing X_{(i)} shifts every higher quantile position, and with it least-squares criteria select the roughest fit in 'm_range'. It is kept only for backward compatibility.

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'.

Value

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'.

Boundary solutions

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.

Examples

x <- rgamma(60, 5, 1)
select_bandwidth(x, qdf_poisson, "bcv", m_range = c(10, 50))

qdfauction documentation built on Nov. 10, 2026, 5:07 p.m.