Читать книгу The Big R-Book - Philippe J. S. De Brouwer - Страница 281
8.3.2 8.3.2 The Spearman Correlation
ОглавлениеThe measure for correlation, as defined in previous section, actually tests for a linear relation. This means that even the presence of a strong non-linear relationship can go undetected.
x <- c(-10:10) df <- data.frame(x=x, x_sq=x∧2, x_abs=abs(x), x_exp=exp(x)) cor(df) ## x x_sq x_abs x_exp ## x 1.000000 0.0000000 0.0000000 0.5271730 ## x_sq 0.000000 1.0000000 0.9671773 0.5491490 ## x_abs 0.000000 0.9671773 1.0000000 0.4663645 ## x_exp 0.527173 0.5491490 0.4663645 1.0000000
The correlation between x and x2 is zero, and the correlation between x and exp(x) is a meagre 0.527173.
correlation – Spearman
The Spearman correlation is the correlation applied to the ranks of the data. It is one if an increase in the variable X is always accompanied with an increase in variable Y.
cor(rank(df$x), rank(df$x_exp)) ## [1] 1
The Spearman correlation checks for a relationship that can bemore general than only linear. It will be one if X increases when Y increases.