MatrixObject.CorrelationMatrix
The element (i, j) of the correlation matrix is the correlation between column i and j. The correlation matrix is symmetric and its diagonal elements are 1.
Error 1321 will be returned if matrix is not yet sized.
The following example demonstrates the use of the CorrelationMatrix Method.
Private Sub MatrixCorrelationMatrix()
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.CorrelationMatrix
Debug.Print "Correlation 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 | Correlation matrix = | 1.000 0.619 -0.545 | | 0.619 1.000 0.303 | | -0.545 0.303 1.000 |