Chapter 8 dist()

Community resemblance is almost always assessed on the basis of species composition data in the form of a site-by-species data table \(Y_{m,n}\).

We can obtain an association matrix \(A_{m,m}\) in the form of pairwise distances or dissimilarities \(D_{m,m}\) (or similarities \(S_{m,m}\)) and then analyse those distances. Association matrices between objects or among descriptors allow for calculations of similarity or distances between objects or descriptors (Legendre and Legendre 2012).

In R, we can compute distance or dissimilarity matrices using stats::dist(). For simplicity, let us do this without specifying arguments:

dist(spe)

Run dist(spe) from your end, and you should observe that the output from `dist(spe) is a lower triangular matrix representing pairwise associations between the columns of your original matrix.

Let us see what the commands below show us:

class(dist(spe))
## [1] "dist"

The output from dist() is a dist class object by default. This object is composed of a vector that contains the lower triangle of the distance matrix, distributed across columns. You can coerce it into a matrix with as.matrix(), as seen below:

as.matrix(dist(spe))

Notably, you can coerce a matrix that contains distances (\(D_{m,m}\)) using as.dist().

You can also explore the structure and dimensions of our dist-class object and distance matrix:

str(dist(spe))
dim(as.matrix(dist(spe)))
## [1] 30 30