R/Ecluster.R

Defines functions energy.hclust

Documented in energy.hclust

energy.hclust <-
function(dst, alpha = 1) {
    if (!inherits(dst, "dist"))
      stop("The first argument must be a dist object.")
    d <- dst
    n <- attr(d, "Size")
    if (!isTRUE(all.equal(alpha, 1))) {
    	if (alpha > 2)
    	    warning("Exponent alpha should be in (0,2]")
      if (alpha < 0)
        stop("Cannot use negative exponent on distance.")
    	d <- d^alpha
    }
    ## heights of hclust are half of energy; otherwise equivalent
    return(hclust(d, method = "ward.D"))
}

Try the energy package in your browser

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

energy documentation built on Dec. 28, 2022, 1:43 a.m.