Kendall Tau with empty cells

G Angie

New Member
Joined
May 6, 2022
Messages
6
Office Version
  1. 2016
  2. 2013
Platform
  1. Windows
Hello, I have a question regarding voids. Kendall's rate is normally calculated when all cells are filled. But, as soon as there is a gap, it displays an error. And in my database, there are columns that are filtered, which means that we have blanks in certain columns. Is there an additional line of code that could work around this problem?

Option Explicit

' Example data from
' Kendall's Rank Correlation - StatsDirect

' --A--- --B-- C --D--- -----------E-----------
' 1 Career Psych
' 2 4 5 0.5111 D2: =KendallTau(A2:B11)
' 3 10 8
' 4 3 6
' 5 1 2
' 6 9 10
' 7 2 3
' 8 6 9
' 9 7 4
' 10 8 7
' 11 5 1

Function KendallTau(r As Range) As Variant
If WorksheetFunction.Count(r.Value) <> r.Count Then
KendallTau = CVErr(xlErrValue)
Else
KendallTau = dKendallTau(r.Value)
End If
End Function

Function dKendallTau(avXY As Variant) As Double
' shg 2010

Dim n As Long ' number of pairs
Dim i As Long ' outer loop index
Dim j As Long ' inner loop index
Dim nCon As Long ' number of concordant pairs
Dim nDis As Long ' dumber of discordant pairs
Dim nX As Long ' number of X ties
Dim nY As Long ' number of Y ties
Dim nC2 As Long ' n Choose 2

n = UBound(avXY)

For i = 1 To n - 1
For j = i + 1 To n
Select Case Choose(Sgn(avXY(i, 1) - avXY(j, 1)) + 2, "<", "=", ">") & _
Choose(Sgn(avXY(i, 2) - avXY(j, 2)) + 2, "<", "=", ">")
Case ">>", "<<"
nCon = nCon + 1
Case "<>", "><"
nDis = nDis + 1
Case "=<", "=>"
nX = nX + 1
Case "<=", ">="
nY = nY + 1
Case "=="
nX = nX + 1
nY = nY + 1

End Select
Next j
Next i
nC2 = n * (n - 1) / 2
dKendallTau = (nCon - nDis) / Sqr((CDbl(nC2 - nX) * CDbl(nC2 - nY)))
End Function
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,213,489
Messages
6,113,954
Members
448,535
Latest member
alrossman

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