X and Y values are ranked separately, and the Pearson’s product-moment coefficient (\(r\)) is computed on these ranks
x <- c(0.9, 6.8, 3.2, 2.4, 1.2, 1.1) y <- c(0.1, 4.5, 5.4, 1.5, 1.9, 4.1)
rank_x <- rank(x) rank_y <- rank(y) rank_x
## [1] 1 6 5 4 3 2
rank_y
## [1] 1 5 6 2 3 4
cor(x, y, method = "pearson")
## [1] 0.5590485
cor(x, y, method = "spearman")
## [1] 0.7142857
cor(rank_x, rank_y, method = "pearson")
## [1] 0.7142857
Alternative to Spearman….
cor(var1, var2, method="kendall")
## [1] 0.8222222
Mann-Whitney U, also known as the Wilcoxon Rank-Sum
x <- rnorm(10, mean=5) y <- rnorm(10, mean=7) wilcox.test(x,y)
## ## Wilcoxon rank sum exact test ## ## data: x and y ## W = 9, p-value = 0.00105 ## alternative hypothesis: true location shift is not equal to 0
Kruskal-Wallis
kruskal.test(var~group)
## ## Kruskal-Wallis rank sum test ## ## data: var by group ## Kruskal-Wallis chi-squared = 2.2946, df = 1, p-value = 0.1298
Kolmogorov-Smirnov Test
Non-parametric test to determine whether two distributions differ
ks.test(rnorm(100), "punif")
## ## Asymptotic one-sample Kolmogorov-Smirnov test ## ## data: rnorm(100) ## D = 0.42597, p-value = 3.469e-16 ## alternative hypothesis: two-sided
ks.test(rnorm(100)^2, "pnorm")
## ## Asymptotic one-sample Kolmogorov-Smirnov test ## ## data: rnorm(100)^2 ## D = 0.50003, p-value < 2.2e-16 ## alternative hypothesis: two-sided
ks.test(runif(100), rnorm(100))
## ## Asymptotic two-sample Kolmogorov-Smirnov test ## ## data: runif(100) and rnorm(100) ## D = 0.5, p-value = 2.778e-11 ## alternative hypothesis: two-sided