Nothing
ClusterCalinskiHarabaszIndex = function(Cls, Data) {
# V=ClusterCalinskiHarabaszIndex(Cls,Data)
#
# Calinski-Harabasz Variance-Ratio Criterion [Calinski/Harabasz, 1974]
#
# INPUT
# Cls[1:n] Numeric, character or factor cluster labels; no missing labels
# Data[1:n,1:d] Finite numeric matrix/data.frame; rows match Cls
#
# OUTPUT
# List V with
# CalinskiHarabaszIndex Variance-ratio criterion; larger values are better
# Object List of WithinSS, BetweenSS, Centers, ClusterSizes, ClusterLabels
#
# DETAILS
# Uses squared Euclidean distances to arithmetic centroids:
# (BetweenSS / (k - 1)) / (WithinSS / (n - k)). No scaling is done.
# All labels, including zero, are ordinary clusters. Requires 2 <= k < n.
# Zero WithinSS gives Inf if BetweenSS > 0, otherwise NaN.
# Invalid partitions yield NaN with a warning.
#
# Author: Michael Thrun, 11/2026
#
# [Calinski/Harabasz, 1974] Calinski, T., & Harabasz, J.: A dendrite method for cluster analysis, Communications in Statistics, Vol. 3(1), pp. 1-27, DOI:10.1080/03610927408827101, 1974.
#
Input = internalClusterValidation(Cls, Data, "ClusterCalinskiHarabaszIndex")
Data = Input$Data
Cls = Input$Cls
Labels = Input$Labels
ClusterNo = length(Labels)
if (ClusterNo < 2L || ClusterNo >= nrow(Data)) {
warning("ClusterCalinskiHarabaszIndex: requires between 2 and n-1 clusters")
return(list(CalinskiHarabaszIndex = NaN, Object = NULL))
}
Centers = do.call(rbind, lapply(seq_len(ClusterNo), function(i)
colMeans(Data[Cls == i, , drop = FALSE])))
rownames(Centers) = as.character(Labels)
ClusterSizes = tabulate(Cls, nbins = ClusterNo)
WithinSS = sum((Data - Centers[Cls, , drop = FALSE])^2)
BetweenSS = sum(ClusterSizes * rowSums(sweep(Centers, 2L, colMeans(Data))^2))
Score = (BetweenSS / (ClusterNo - 1L)) / (WithinSS / (nrow(Data) - ClusterNo))
if (WithinSS == 0) warning("ClusterCalinskiHarabaszIndex: within-cluster dispersion is zero")
return(list(CalinskiHarabaszIndex = Score,
Object = list(WithinSS = WithinSS, BetweenSS = BetweenSS,
Centers = Centers, ClusterSizes = ClusterSizes,
ClusterLabels = Labels)))
}
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.