'VBA Function for Correlation matrices WITHOUT invoking any worksheetFunction
i'm looking for a way to calculate a correlation matrix of a bunch ob observations. My trials are so far this:
Function VarCovar(Rng As range) As Variant
Dim i As Integer
Dim j As Integer
Dim numcols As Integer
numcols = Rng.Columns.Count
Dim matrix() As Double
ReDim matrix(numcols - 1, numcols - 1)
For i = 1 To numcols
For j = 1 To numcols
matrix(i - 1, j - 1) = Application.WorksheetFunction.Covar(Rng.Columns(i), Rng.Columns(j))
Next j
Next i
VarCovar = matrix
End Function
However, i'd like to aviod this Application.WorksheetFunction.Covar part and write it explicitly in the code. Would anyone mind to help me?
Thanks a lot
Best regards
Thomas
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
