算法交流群纯数学:232875138
spearman 优化算法
set.seed(0)
x <- runif(100)
y <- runif(100)
cor(x, y, method="spearman") # our reference value
## [1] 0.01018902
ranked.x <- scale(rank(x)) / sqrt(length(x) - 1) / 2
ranked.y <- scale(rank(y)) / sqrt(length(y) - 1) / 2
1 - 2 *sum((ranked.x - ranked.y)^2) # based on the Euclidean distance
## [1] 0.01018902