#' Bandwidth estimation for CVE. #' #' Estimates a propper 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 number of sample and \eqn{p} its dimension #' (\code{n <- nrow(X); p <- ncol(X)}) and the covariance-matrix \eqn{\Sigma} #' which is given by the standard maximum likelihood estimate. #' #' @param nObs Expected number of points in a slice, see paper. #' @param X data matrix with samples in its rows. #' @param k Dimension of lower dimensional projection. #' #' @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) }