MatrixObject.CovarianceMatrix
The element (i, j) of the covariance matrix is the covariance between column i and j. The covariance matrix is a symmetric matrix.
Error 1321 will be returned if matrix is not yet sized.
The following example demonstrates the use of the CovarianceMatrix Method.
Private Sub MatrixCovarianceMatrix()
Dim M As Matrix, C As Matrix
Set M = New Matrix
M.Size 6, 3
M(0, 0) = 1: M(0, 1) = 0: M(0, 2) = 6
M(1, 0) = 3: M(1, 1) = 6: M(1, 2) = 8
M(2, 0) = 4: M(2, 1) = 3: M(2, 2) = 5
M(3, 0) = 6: M(3, 1) = 5: M(3, 2) = 5
M(4, 0) = 7: M(4, 1) = 2: M(4, 2) = 1
M(5, 0) = 9: M(5, 1) = 8: M(5, 2) = 5
Debug.Print "M="
Debug.Print M.GetString
Set C = M.CovarianceMatrix
Debug.Print "Covariance matrix ="
Debug.Print C.GetString
End Sub
M= | 1.000 0.000 6.000 | | 3.000 6.000 8.000 | | 4.000 3.000 5.000 | | 6.000 5.000 5.000 | | 7.000 2.000 1.000 | | 9.000 8.000 5.000 | Covariance matrix = | 7.000 4.333 -3.000 | | 4.333 7.000 1.667 | | -3.000 1.667 4.333 |