Session Ready
Exercise

Calculating the correlation matrix

Almost at the finish line! Using the sums of squares and the sums of cross products matrix S you can calculate the variance-covariance matrix C:

$$\begin{aligned} C_{XX} &= S_{XX}N^{-1} \end{aligned}$$

with \(C_{XX}\) the variance-covariance matrix, \(S_{XX}\) the matrix of sum of squares and sum of cross products, and \(N^{-1}\) the inverse number of observations for each variable.

Next, you can standardize this variance-covariance matrix by multiplying it with the standard deviation matrix SD. This gives us the correlation matrix R:

$$\begin{aligned}R_{XX} &= (SD_{XX})^{-1}C_{XX}(SD_{XX})^{-1}\end{aligned}$$

with \(R_{XX}\) the correlation matrix, \(C_{XX}\) the variance-covariance matrix, and \(SD_{XX}\) the standard deviation matrix.

Instructions
100 XP
  • Calculate the variance-covariance matrix and assign the result to C.
  • Use the variance-covariance matrix to obtain the standard deviations matrix SD. SD should be a 3-by-3 matrix having the standard deviations as diagonal elements and zero as off-diagonal elements. Have a look at the function diag() to construct such a matrix.
  • Standardize the variance-covariance matrix by the standard deviations matrix to obtain the correlation matrix and assign the result to R. Have a look at the solve() function.