# Robust correlation in R? [closed]

I would like to perform a robust correlation on a small sample (n<30). What is the best estimation method to use?

I tried to get an overview over the plenty methods for robust statistics provided in R - I would be happy if anyone could give me some recommendations

• "Best" for what purpose? How do you intend to use the correlation estimate once you have it? What are the potential consequences of making an estimation error due to the influence of a few outlying data? Are you trying to estimate Pearson correlation or do you just want a quantitative assessment of a strength of (linear?) relationship between two variables?
– whuber
Sep 5, 2012 at 18:19
• Robust to violations of which assumptions? Do you believe your data are non-normally distributed, have restricted range, are rank data? The best method will depend on the process which generated the data - often a simple rank order correlation is a good option in these cases. Sep 23, 2012 at 4:42

MASS::cov.rob (link to man page) has two methods for robust covariances, which you can standardize to correlations with cov2cor. @whuber is right that the "best" method will depend on what you want to do with it, though..
I implemented these correlation measures in R, it is super easy using robustbase package:
The assessment of performance for contaminated sample case is provided in the end of the article (for n=20 and n=1000). You may concentrate on $$Q_n$$ correlation, it works the best according to the assessment.
UPD: I recently found myself googling for a robust correlation code in R and found out this thread again. Here is the code:  robust_correlation <- function(robust_std, estimation_of_center_x, estimation_of_center_y, x, y) { square_root_of_two <- sqrt(2) std_of_x <- robust_std(x) std_of_y <- robust_std(y) first_component = (x - estimation_of_center_x) / (square_root_of_two * std_of_x) second_component = (y - estimation_of_center_y) / (square_root_of_two * std_of_y) u = first_component + second_component v = first_component - second_component var_of_u = robust_std(u) ** 2 var_of_v = robust_std(v) ** 2 r = (var_of_u - var_of_v) / (var_of_u + var_of_v + 10**-10) return® }