R/hellinger.dist.R

Defines functions hellinger.dist

Documented in hellinger.dist

#' Hellinger Distance Between Distributions
#'
#' Calculates the Hellinger distance between two probability distributions.
#'
#' @param p A probability vector.
#' @param q Another probability vector of same length as p.
#' @return Hellinger distance between p and q.
#' @export
hellinger.dist <- function(p, q) {
  sum = 0
  for (i in 1:length(p)) {
    sum = sum + (sqrt(p[i]) - sqrt(q[i]))^2
  }
  result = (1 / sqrt(2)) * sqrt(sum)
  return(result)
}

Try the GTRT package in your browser

Any scripts or data that you put into this service are public.

GTRT documentation built on Sept. 9, 2025, 5:38 p.m.