# Chapter 6 Matrix algebra, very briefly

Matrix algebra is well-suited for ecology, because most (if not all) data sets we work with are in a matrix format.

## 6.1 Data sets are matrices

Ecological data tables are obtained as object-observations or sampling units, and are often recorded as this:

Objects $$y_1$$ $$y_2$$ $$\dots$$ $$y_n$$
$$x_1$$ $$y_{1,1}$$ $$y_{1,2}$$ $$\dots$$ $$y_{1,n}$$
$$x_2$$ $$y_{2,1}$$ $$y_{2,2}$$ $$\dots$$ $$y_{2,n}$$
$$\vdots$$ $$\vdots$$ $$\vdots$$ $$\ddots$$ $$\vdots$$
$$x_m$$ $$y_{m,1}$$ $$y_{m,2}$$ $$\dots$$ $$y_{m,n}$$

where $$x_m$$ is the sampling unit $$m$$; and $$y_n$$ is the ecological descripor that can be, for example, species present in a sampling unit, locality, or a chemical variable.

The same ecological data table can be represented in matrix notation like this:

$Y = [y_{m,n}] = \begin{bmatrix} y_{1,1} & y_{1,2} & \cdots & y_{1,n} \\ y_{2,1} & y_{2,2} & \cdots & y_{2,n} \\ \vdots & \vdots & \ddots & \vdots \\ y_{m,1} & y_{m,2} & \cdots & y_{m,n} \end{bmatrix}$

where lowercase letters indicate elements, and the subscript letters indicate the position of these elements in the matrix (and in the table!).

Moreover, any subset of a matrix can be recognized.

We can subset a row matrix, as below:

$\begin{bmatrix} y_{1,1} & y_{1,2} & \cdots & y_{1,n} \\ \end{bmatrix}$

We can also subset a column matrix, as below:

$\begin{bmatrix} y_{1,1} \\ y_{2,2} \\ \vdots \\ y_{m,2} \end{bmatrix}$

## 6.2 Association matrices

Two important matrices can be derived from the ecological data matrix: the association matrix among objects and the association matrix among descriptors.

Using the data from our matrix $$Y$$,

$Y = \begin{array}{cc} \begin{array}{ccc} x_1 \rightarrow\\ x_2 \rightarrow\\ \vdots \\ x_m \rightarrow\\ \end{array} & \begin{bmatrix} y_{1,1} & y_{1,2} & \cdots & y_{1,n} \\ y_{2,1} & y_{2,2} & \cdots & y_{2,n} \\ \vdots & \vdots & \ddots & \vdots \\ y_{m,1} & y_{m,2} & \cdots & y_{m,n} \end{bmatrix} \end{array}$

one can examine the relationship between the first two objects:

$x_1 \rightarrow \begin{bmatrix} y_{1,1} & y_{1,2} & \cdots & y_{1,n} \\ \end{bmatrix}$

$x_2 \rightarrow \begin{bmatrix} y_{2,1} & y_{2,2} & \cdots & y_{2,n} \\ \end{bmatrix}$

and obtain $$a_{1,2}$$.

We can populate the association matrix $$A_{n,n}$$ with the relationships between all objects from $$Y$$:

$A_{n,n} = \begin{bmatrix} a_{1,1} & a_{1,2} & \cdots & a_{1,n} \\ a_{2,1} & a_{2,2} & \cdots & a_{2,n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{n,1} & a_{n,2} & \cdots & a_{n,n} \end{bmatrix}$

Because $$A_{n,n}$$ has the same number of rows and columns, it is denoted a square matrix.

Therefore, $$A_{n,n}$$ has $$n^2$$ elements.

We can also obtain the relationship between the first two descriptors of $$Y$$, $$y_1$$ and $$y_2$$:

$\begin{bmatrix} y_{1,2} \\ y_{2,2} \\ \vdots \\ y_{m,2} \end{bmatrix}$

$\begin{bmatrix} y_{1,1} \\ y_{2,1} \\ \vdots \\ y_{m,1} \end{bmatrix}$

and store it in $$a_{1,2}$$.

We can populate the association matrix $$A_{m,m}$$ with the relationships between all descriptors from $$Y$$:

$A_{m,m} = \begin{bmatrix} a_{1,1} & a_{1,2} & \cdots & a_{1,m} \\ a_{2,1} & a_{2,2} & \cdots & a_{2,m} \\ \vdots & \vdots & \ddots & \vdots \\ a_{m,1} & a_{m,2} & \cdots & a_{m,m} \end{bmatrix}$

This $$A_{m,m}$$ is a square matrix, and it has $$m^2$$ elements.

These matrices, $$A_{n,n}$$ and $$A_{m,m}$$, are the basis of Q-mode and R-mode analyses in ecology.

R-mode constitutes of analyzing the association between descriptors or species, while Q-mode analyzes the association between OTUs, objects or sites.