2
0
Fork 0
CVE/CVE_C/R/estimateBandwidth.R

27 lines
950 B
R
Raw Normal View History

2019-10-18 07:06:36 +00:00
#' Bandwidth estimation for CVE.
#'
#' Estimates a propper bandwidth \code{h} according
#' \deqn{%
2019-10-18 07:06:36 +00:00
#' 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.
#'
2019-10-18 07:06:36 +00:00
#' @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)
2019-10-18 07:06:36 +00:00
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)
}