Distance Correlation in Julia

Hi all,
Is there any package in Julia to compute distance correlation just like the package energy in r?

Thank you,

Perhaps this is what you are searching for:

CorrDist corr_dist(x, y) cosine_dist(x - mean(x), y - mean(y))

2 Likes

@lmiq Great! That works for me. Thank you

I don’t think the two functions are calculating the same thing.

julia> using RCall

julia> x = randn(10);

julia> y = randn(10);

julia> R"library(energy)"; rcall(:dcor, x, y)
RObject{RealSxp}
[1] 0.4823483


julia> using Distances

julia> corr_dist(x, y)
0.8597077631762767

I think it is quite easy in julia to implement a simplified (and also more performant) version for distance correlation from scratch. If it is not in a performance critical part, you can also use RCall.jl to use functions from R.

1 Like

No, they are not! In fact, this small example shows that the version of cordist implemented in distances.jl is not always between 0 and 1 unlike the definition in here. Also it seems higher distances are associated with stronger independence - opposite to dcor.

n=50
p = 3
q = 5
Y = randn(n, q)
X = randn(n, p)
Y[:,1] = X[:,1]
pairwise(CorrDist(), Y, X, dims=2)

Currently, I am using RCall (dcor in r) to compute the distance correlation. This is too expensive in an MC simulation. I have not been able to implement a better and fast version.

This one then?

https://juliahub.com/docs/EnergyStatistics/GxpWi/0.2.0/

2 Likes

Yes! That works better. Exactly what I was looking for.
Many thanks!