#' Bandwidth estimation for CVE. #' #' Estimates a bandwidth \code{h} according #' \deqn{% #' h = \chi_{k}^{-1}\left(\frac{nObs - 1}{n-1}\right)\frac{2 tr(\Sigma)}{p}}{% #' h = qchisq( (nObs - 1)/(n - 1), k ) * (2 tr(\Sigma) / p)} #' with \eqn{n} the sample size, \eqn{p} its dimension #' (\code{n <- nrow(X); p <- ncol(X)}) and the covariance-matrix \eqn{\Sigma} #' which is \code{(n-1)/n} times the sample covariance estimate. #' #' @param X data matrix with samples in its rows. #' @param k Dimension of lower dimensional projection. #' @param nObs number of points in a slice, see \eqn{nObs} in CVE paper. #' #' @seealso [\code{\link{qchisq}}] #' @export estimate.bandwidth <- function(X, k, nObs) { n <- nrow(X) p <- ncol(X) X_centered <- scale(X, center = TRUE, scale = FALSE) Sigma <- (1 / n) * t(X_centered) %*% X_centered quantil <- qchisq((nObs - 1) / (n - 1), k) return(2 * quantil * sum(diag(Sigma)) / p) }