# 1.4 Sums of squares from a distance matrix

We can now consider the structure of a distance/dissimilarity matrix and how sums of squares for a one-way multivariate ANOVA partitioning would be calculated (Fig. 1.4).

[![Fig1.4.png](https://learninghub.primer-e.com/uploads/images/gallery/2022-08/scaled-1680-/fig1-4.png)](https://learninghub.primer-e.com/uploads/images/gallery/2022-08/fig1-4.png)
**Fig. 1.4.** Calculation of sums of squares directly from a distance/dissimilarity matrix. 

If we let $d _ {ij}$ be the dissimilarity (or distance) between sample *i* and sample *j*, then the total sum of squares is the sum of the inter-point dissimilarities among all samples, divided by *N*:

$$ SS _ T = \frac{1}{N} \sum _ {i=1} ^ {N-1} \sum _ {j=i+1} ^ {N} d _ {ij} ^2  \tag{1.1} $$

and the residual (within-group) sum of squares (assuming, for now, a balanced design having an equal sample size of *n* per group) is:

$$ SS _ {Res} = \frac{1}{n} \sum _ {i=1} ^ {N-1} \sum _ {j=i+1} ^ {N} d _ {ij} ^2 \omega _ {ij} \tag{1.2} $$

where $\omega _ {ij}$ takes the value of 1 if samples *i* and *j* are in the same group, otherwise it takes the value of zero. This amounts to adding up the squares of all the dissimilarities between samples that occur within the same group. These quantities are shown schematically in Fig. 1.4. The among-group sum of squares  can also be calculated directly or, more simply, as the difference: $SS _A = SS _T - SS _ {Res}$. Partitioning of distance matrices having Euclidean metric properties according to ANOVA experimental designs has been discussed previously by {{@324#bkmrk-edgington1995a}}, {{@324#bkmrk-pillar1996a}} and {{@324#bkmrk-excoffier1992a}}, whereas {{@324#bkmrk-gower1999a}} extended this idea to semi-metric dissimilarities having only the properties of symmetry (i.e., $d _{ij} = d _{ji}$) and that $d _ {ij} \ge 0$ and $d _ {ii} = 0$ for all samples.  

A related point is that PERMANOVA (or any of the other methods that partition variability in the routines offered by the PERMANOVA+ add-on) does *not* suffer from the problems recently identified by {{@324#bkmrk-legendre2005a}} for the Mantel and partial Mantel test ({{@324#bkmrk-mantel1967a}}, {{@324#bkmrk-smouse1986a}})<sup>9</sup>.  Confusion might arise because {{@324#bkmrk-legendre2005a}} used the words “variation partitioning on distance matrices” to describe the general Mantel approach. PERMANOVA, however, is not a Mantel test. The essential issue regarding the partial Mantel approach (known for some time to be potentially problematic, see {{@324#bkmrk-dutilleul2000a}}, {{@324#bkmrk-legendre2000a}}, {{@324#bkmrk-raufaste2001a}} and {{@324#bkmrk-rousset2002a}}) is that it works on “unwound” distance matrices, where inter-point distance values are treated independently as a single vector. In contrast, the methods in the PERMANOVA+ add-on all work on the distance/dissimilarity matrix directly but, importantly, they *retain* its inherent structure; the values in the matrix are *not* unwound nor are they treated or modelled as independent of one another.  The PERMANOVA+ methods are therefore directly akin to the so-called “canonical partitioning”  methods referred to by {{@324#bkmrk-legendre2005a}}, and are correct for partitioning and analysing the actual variability inherent in multivariate data clouds. 

---
<sup>9</sup> The original simple Mantel test ({{@324#bkmrk-mantel1967a}})  to relate two distance matrices, from which several of the PRIMER routines (RELATE, BIOENV, BEST, BVSTEP and 2-stage MDS) all drew some inspiration, *is* valid and does have utility in appropriate applications, as pointed out by {{@324#bkmrk-legendre2005a}}.