Calculates R squared for different number of clusters
One of the first steps in clustering data is determining the optimal number of clusters. The R2 measure is a common statistic for clustering analysis that compares the proportion of within cluster variance with the total variance. This code follows the introduction at https://documentation.sas.com/doc/en/emref/14.3/n1dm4owbc3ka5jn11yjkod7ov1va.htm to calculate the R2 and show the intermediate matrices that represent the total, between cluster, and within cluster variance.