Why am I getting different results for Pearson and Spearman correlation, although I am already comparing ranks?
a <- c(1,2,3,1,2,3)
b <- c(1,2,2,1,2,3)
cor(a, b, method="pearson")
# [1] 0.8911328
cor(a, b, method="spearman")
# [1] 0.9036961
Formula to use when there are tied ranks seems identical to formula for pearson correlation.
- Spearman correlation (at the very bottom)
- Pearson correlation
As far as I understand, spearman correlation is just pearson correlation on the ranks. Right?
a
as if it represented positions in a race among six people: two people tied for each position. There are various ways to assign ranks with ties, but typically the ranks that would be given to the top two places--namely 1 and 2--would be averaged, giving a rank of 1.5 to the first two finishers. Similarly, the next two would have equal ranks of 3.5 and the last two would have ranks of 5.5. $\endgroup$ – whuber♦ Jun 4 '18 at 15:03