Get startedGet started for free

Variance/Covariance Calculations

In the last exercise you pre-processed the combine data into a matrix A. We now use A to create the variance-covariance matrix of this dataset.

This exercise is part of the course

Linear Algebra for Data Science in R

View Course

Exercise instructions

  • Create the matrix \(\frac{A^TA}{n-1}\). Call this matrix B.
  • Show that the [1,1] element of B is the same as the variance of the first column of A.
  • Show that the [1,2] and [2,1] elements of B are the same as the covariance between the first and second columns of A.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Create matrix B from equation in instructions
B <- ___(A)%*%A/(___(A) - 1)

# Compare 1st element of the 1st column of B to the variance of the first column of A
B[1,1]
____(A[, 1])

# Compare 1st element of 2nd column of B to the 1st element of the 2nd row of B to the covariance between the first two columns of A
B[1, 2]
B[2, 1]
___(A[, 1], A[, 2])
Edit and Run Code