Juggler_IN
Active Member
- Joined
- Nov 19, 2014
- Messages
- 358
- Office Version
- 2003 or older
- Platform
- Windows
I need help in modifying the appended Partial Correlation UDF to Semipartial Correlation UDF.
A note on Semipartial Correlation (and Partial) can be found at http://www.listendata.com/2017/03/partial-correlation.html
The Partial Correlation UDF is:
A note on Semipartial Correlation (and Partial) can be found at http://www.listendata.com/2017/03/partial-correlation.html
The Partial Correlation UDF is:
Code:
Function pCorrel(R)
Dim iRows As Integer, iCols As Integer
Dim Identity() As Double, RDiag() As Double, RDiagSQRT() As Double, Part_Correl() As Double
iRows = R.Rows.Count
iCols = R.Columns.Count
RInverse = Application.MInverse(R)
ReDim Identity(1 To iRows, 1 To iCols)
ReDim RDiag(1 To iRows, 1 To iCols)
ReDim RDiagSQRT(1 To iRows, 1 To iCols)
ReDim Part_Correl(1 To iRows, 1 To iCols)
For i = 1 To iRows
For j = 1 To iCols
Identity(i, j) = 0
RDiag(i, j) = 0
If i = j Then
Identity(i, j) = 1
RDiag(i, j) = 1 / RInverse(i, j)
RDiagSQRT(i, j) = RDiag(i, j) ^ 0.5
End If
Next j
Next i
P2_Neg = (Application.MMult(RDiagSQRT, Application.MMult(RInverse, RDiagSQRT)))
For i = 1 To iRows
For j = 1 To iCols
Part_Correl(i, j) = Identity(i, j) - P2_Neg(i, j)
Part_Correl(i, i) = -1
Next j
Next i
pCorrel = Part_Correl
End Function