I would like to use a distance correlation/covariance analysis to detect (non-linear) dependencies in my data in R. However, my data has a lot of NAs so, after filter them (because dcor/dcov implementation in R does not face with NAs), I obtain vectors with different lengths.

I read the distance correlations could lead with different length vectors. However, I have this error:

dcor.test(variable1[which(!is.na(variable1))],variable2[which(!is.na(variable2))], R=50)
  Error in dcov.test(x, y, index = 1, R) : Sample sizes must agree

  Error in DCOR(dat$Demográficas.Age.[which(!is.na(dat$Demográficas.Age.))],  : 

Sample sizes must agree

length(variable1[which(!is.na(variable1))]) = 4000
length(variable2[which(!is.na(variable2))]) = 1000

It is not possible to compare different length vectors also with distance correlation? How can I deal with that?

Thank you so much!

Here are some principal references of distance correlation: Szekely et al.(2007): http://citeseerx.ist.psu.edu/viewdoc/download?doi= The package of R I am using: https://cran.r-project.org/web/packages/energy/energy.pdf


I tried with bcdcor (bias-corrected distance correlation), implemented in Energy and Rfast packages, and he can work with different length vectors. However, I can't understand why and how this "bias-correction" affect in the analysis/results. Some ideas?

  • $\begingroup$ I think no. Distance covariance/correlation can handle different number of variables (dimensions) in the being correlated two sets, by they should have the same cardinality. Try to impute missing observations. $\endgroup$ – ttnphns Nov 23 '17 at 11:11
  • $\begingroup$ Hi @ttnphns, thank for your answer! I updated the post with the results of the bcdcor. Do you know something about that? $\endgroup$ – JP Manzano Nov 23 '17 at 11:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.