Semipartial Correlation UDF

Juggler_IN

Active Member
Joined
Nov 19, 2014
Messages
349
Office Version
  1. 2003 or older
Platform
  1. 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:

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
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Further to add an example, if the correlation matrix for three variables is:

1.000000
0.920000
0.870000
0.920000
1.000000
0.810000
0.870000
0.810000
1.000000

<tbody>
</tbody>

... the array function pCorrel() gives the following output.

-1.00000
0.744621
0.543004
0.744621
-1.00000
0.049680
0.543004
0.049680
-1.00000

<tbody>
</tbody>

.. Now, instead of Partial, I am looking for Semipartial UDF.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,461
Messages
6,124,957
Members
449,200
Latest member
indiansth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top