Let’s consider the matrix \(\mathbf{X}\) (Equation 13.1), then the vector of means for each column is computed as: \[
\underset{k \times 1}{\bar{\mathbf{x}}} =
\begin{pmatrix}
\bar{x}_1 \\
\vdots \\
\bar{x}_k \\
\end{pmatrix} =
\begin{pmatrix}
\frac{1}{n} \mathbf{J}_{1,n} \mathbf{X}
\end{pmatrix}^{\top} =
\frac{1}{n} \mathbf{X}^{\top} \mathbf{J}_{n,1}
\text{.}
\] where \(\mathbf{J}_{n,1}\) is the matrix of ones (Equation 31.2).
Vector of means
# Vector of ones J_1n <-matrix(1, nrow =1, ncol = n)# Vector of means x_bar <-t((J_1n %*% X)/n)# Standard computation# matrix(apply(X, 2, mean), nrow = k, ncol = 1)
The covariance for a matrix \(\mathbf{X}\) is also a matrix \(k \times k\) of the form: \[
\underset{k \times k }{\boldsymbol{\Sigma}} =
\begin{pmatrix}
\mathbb{V}\{\mathbf{X}_1\} & \dots & \mathbb{C}v\{\mathbf{X}_1, \mathbf{X}_j\} & \dots & \mathbb{C}v\{\mathbf{X}_1, \mathbf{X}_k\} \\
\vdots & & \vdots & & \vdots \\
\mathbb{C}v\{\mathbf{X}_j, \mathbf{X}_1\} & \dots & \mathbb{V}\{\mathbf{X}_j\} & \dots & \mathbb{C}v\{\mathbf{X}_j, \mathbf{X}_k\} \\
\vdots & & \vdots & & \vdots \\
\mathbb{C}v\{\mathbf{X}_k, \mathbf{X}_1\} & \dots & \mathbb{C}v\{\mathbf{X}_k, \mathbf{X}_j\} & \dots & \mathbb{V}\{\mathbf{X}_k\} \\
\end{pmatrix}
\tag{13.3}\] Given a matrix \(\mathbf{X}\), the variance-covariance matrix in matrix notation can be estimated as \[
\begin{aligned}
\boldsymbol{\Sigma} & {} = \frac{1}{n}\widetilde{\mathbf{X}}^{\top} \widetilde{\mathbf{X}} = \\
& = \frac{1}{n} \left( \textbf{A} \mathbf{X} \right)^{\top} \textbf{A} \mathbf{X} = \\
& = \frac{1}{n} \mathbf{X}^{\top} \textbf{A}^{\top} \textbf{A} \mathbf{X}
\end{aligned}
\tag{13.4}\] where \(\mathbf{A}\) is the centering matrix (Equation 13.2). The variance-covariance matrix is:
Squared, i.e. \(k \times k\), and symmetric.
Semi-definite positive.
Has the variances on the diagonal. Hence the trace (Equation 31.8) is \(\text{trace}(\mathbb{C}v\{\mathbf{X}\}) = \sum_{j = 1}^{k} \mathbb{V}\{\mathbf{X}_j\}\).
Covariance matrix
# covariance matrixcv_x <- (t(A %*% X) %*% A %*% X) / (n-1)# In terms of deviation matrix # t(X_tilde) %*% X_tilde / (n-1)# Standard computation# cov(X)
In order to remove the effect of the unit of measure in the different variables it is possible to work under the matrix of standardized variables, i.e. \[
\underset{n \times k}{\mathbf{Z}} =
\begin{pmatrix}
z_{1,1} & \dots & z_{1,j} & \dots & z_{1,k} \\
\vdots & & \vdots & & \vdots \\
z_{i,1} & \dots & z_{i,j} & \dots & z_{i,k} \\
\vdots & & \vdots & & \vdots \\
z_{n,1} & \dots & z_{n,j} & \dots & z_{n,k} \\
\end{pmatrix}
\text{.}
\] where each element \(z_{i,j}\) is defined as: \[
z_{i,j} = \frac{\tilde{x}_{i,j}}{\sqrt{\mathbb{V}\{\mathbf{X}_j\}}} = \frac{x_{i,j} - \bar{x}_j}{\sqrt{\mathbb{V}\{\mathbf{X}_j\}}}
\text{.}
\] In matrix notation, \(\mathbf{Z}\) can be rewritten as: \[
\mathbf{Z} = \widetilde{\mathbf{X}} \cdot \mathbf{D}^{-\frac{1}{2}}
\text{.}
\] where the matrix \(\mathbf{D}\) is defined as: \[
\underset{k \times k}{\mathbf{D}} = \boldsymbol{\Sigma} \cdot \mathbf{I}_{k} =
\begin{pmatrix}
\mathbb{V}\{\mathbf{X}_1\} & \dots & 0 & \dots & 0 \\
\vdots & & \vdots & & \vdots \\
0 & \dots & \mathbb{V}\{\mathbf{X}_j\} & \dots & 0 \\
\vdots & & \vdots & & \vdots \\
0 & \dots & 0 & \dots & \mathbb{V}\{\mathbf{X}_n\} \\
\end{pmatrix}
\text{.}
\tag{13.5}\] where \(\mathbf{I}_{k}\) is the identity matrix (Equation 31.3). The standardized variables have mean equal to zero and unitary variance. Moreover, the numbers do not depend anymore from the unit of measure of the variables.
The correlation is a statistic that measure the linear dependence between two or more variables. The elements of the correlation matrix are: \[
\underset{k \times k}{\boldsymbol{\rho}} =
\begin{pmatrix}
1 & \dots & \mathbb{C}r\{\mathbf{X}_1, \mathbf{X}_j\} & \dots & \mathbb{C}r\{\mathbf{X}_1, \mathbf{X}_k\} \\
\vdots & & \vdots & & \vdots \\
\mathbb{C}r\{\mathbf{X}_j, \mathbf{X}_1\} & \dots & 1 & \dots & \mathbb{C}r\{\mathbf{X}_j, \mathbf{X}_k\} \\
\vdots & & \vdots & & \vdots \\
\mathbb{C}r\{\mathbf{X}_k, \mathbf{X}_1\} & \dots & \mathbb{C}r\{\mathbf{X}_k, \mathbf{X}_j\} & \dots & 1 \\
\end{pmatrix}
\text{.}
\] where each element is the correlation (Equation 5.11) between \(\mathbf{X}_j\) and \(\mathbf{X}_i\) random variables.
In matrix notation, the correlation of a matrix \(\mathbf{X}\) can be estimated from the deviation matrix or from the standardized one, i.e. \[
\begin{aligned}
\boldsymbol{\rho} & {} =
\mathbf{D}^{-\frac{1}{2}} \boldsymbol{\Sigma} \, \mathbf{D}^{-\frac{1}{2}} = \\
& = \frac{1}{n} \mathbf{D}^{-\frac{1}{2}} \widetilde{\mathbf{X}}^{\top} \widetilde{\mathbf{X}} \, \mathbf{D}^{-\frac{1}{2}} = \\
& = \frac{1}{n} \mathbf{Z}^{\top} \mathbf{Z}
\end{aligned}
\] where \(\mathbf{D}\) is defined as in Equation 13.5. The correlation matrix is:
# Correlation matrix cr_x <-t(Z) %*% Z / (n-1)# In terms of covariance matrix # t(D) %*% cv_x %*% D # In terms of deviation matrix # t(X_tilde %*% D) %*% X_tilde %*% D / (n-1)# Standard computation# cor(X)