bw_dir_cv | R Documentation |
Likelihood and least squares cross-validation bandwidth selectors for kernel density estimation with directional data.
bw_dir_lcv(data, h_grid = exp(seq(log(0.05), log(1.5), l = 100)), L = NULL,
plot_it = FALSE, optim = TRUE, optim_par = 0.25, optim_lower = 0.06,
optim_upper = 10)
bw_dir_lscv(data, h_grid = exp(seq(log(0.05), log(1.5), l = 100)),
L = NULL, plot_it = FALSE, optim = TRUE, R_code = FALSE,
optim_par = 0.25, optim_lower = 0.06, optim_upper = 10)
data |
directional data, a matrix of size |
h_grid |
vector of bandwidths for performing a grid search. Defaults
to |
L |
kernel function. Set internally to |
plot_it |
display an informative plot on the optimization's grid search?
Defaults to |
optim |
run an optimization? Defaults to |
optim_par , optim_lower , optim_upper |
parameters passed to |
R_code |
use slower R code when |
data
is not checked to have unit norm, so the user must be careful.
When L = NULL
, faster FORTRAN code is employed.
bw_dir_lscv
employs Monte Carlo integration for q > 2
, which
results in a random output. Use set.seed
before to avoid it.
A list with entries:
h_opt
: selected bandwidth.
h_grid
: h_grid
, if used (otherwise NULL
).
CV_opt
: minimum of the CV loss.
CV_grid
: value of the CV function at h_grid
, if used
(otherwise NULL
).
The function bw_dir_lscv
employs Netlib's subroutine
ribesl
for evaluating
the modified Bessel function of the first kind. The subroutine is based
on a program by Sookne (1973) and was modified by W. J. Cody and L. Stoltz.
An earlier version was published in Cody (1983).
Cody, W. J. (1983). Algorithm 597: Sequence of modified Bessel functions of the first kind. ACM Transactions on Mathematical Software, 9(2):242–245. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1145/357456.357462")}
Hall, P., Watson, G. S., and Cabrera, J. (1987). Kernel density estimation with spherical data. Biometrika, 74(4):751–762. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1093/biomet/74.4.751")}
Sookne, D. J. (1973). Bessel functions of real argument and integer order. Journal of Research of the National Bureau of Standards, 77B:125–132.
# Sample
n <- 25
q <- 2
set.seed(42)
samp <- rotasym::r_vMF(n = n, mu = c(1, rep(0, q)), kappa = 2)
# bw_dir_lcv
bw_dir_lcv(data = samp, optim = TRUE)$h_opt
bw_dir_lcv(data = samp, optim = FALSE, plot_it = TRUE)$h_opt
bw_dir_lcv(data = samp, L = function(x) exp(-x))$h_opt
# bw_dir_lscv
set.seed(42)
bw_dir_lscv(data = samp, optim = TRUE)$h_opt
bw_dir_lscv(data = samp, optim = FALSE, plot_it = TRUE)$h_opt
bw_dir_lscv(data = samp, optim = FALSE, R_code = TRUE)$h_opt
bw_dir_lscv(data = samp, L = function(x) exp(-x))$h_opt
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.