Calculates Total Within Cluster Variance(TWCV) of 3D points. This function is normally only used indirectly through `validate_get_twcv`.

total_within_cluster_variance(point_matrix, cluster_vector)



An n-by-3 numerical matrix where each row corresponds to a single point in 3D space.


A numerical vector of cluster assignments, of length n (ie one assignment per point).


A one-element numeric vector holding calculated variance


TWCV is a synr-specific term for a measure that aims to describe spread of points in 3D space while taking into account that points belong to distinct clusters. TWCV is calculated in a multi-step process:

  1. Each cluster's centroid is calculated.

  2. All points' squared distances to their corresponding centroids are calculated.

  3. The point-to-centroid squared distances are summed up.

  4. The sum of squared distances is divided by the total number of points, minus the number of clusters (to account for decreased degrees of freedom).