JuliaStats / StatsBase.jl

Basic statistics for Julia
Other
587 stars 192 forks source link

Kendall tau distance #937

Open frankier opened 1 month ago

frankier commented 1 month ago

It would be nice to export a function for the Kendall tau distance/bubble-sort distance as well as the Kendall tau correlation. In some situations it has a clearer interpretation.

https://en.wikipedia.org/wiki/Kendall_tau_distance

I believe it is already calculated as an intermediate result by the Kendall tau correlation code.

PGS62 commented 1 month ago

A simple solution would be:

using StatsBase

function kendall_distance(x, y=x)
    n = first(size(x))
    return (1 .- corkendall(x, y)) .* (n * (n - 1) / 4)
end