Pearson correlation is cool, but…
You know what’s even cooler? Spearman correlation — sometimes, depending on your use case.
Spearman correlation is rank-based. So, it asks the question of how similarly positioned in two vectors the highest/middle/lowest values are. One handy result of this methodology is that it outliers tend not to sway Spearman correlation as much as they might Pearson correlation. Here’s a short example of how to use Spearman correlation in R.
spearman_correlation = cor.test(X1,X2 ,use="complete.obs" # optional -- ignore pairs with NAs ,method = "spearman") spearman_correlation