biostatistics

Pearson相关系数 Vs Spearman相关系数

2017-08-25  本文已影响62人  xiiao蜗牛

统计术语中,相关系数一词经常被滥用,同时也困扰着我。相关系数描述一个变量随着另一个变量的增加而增加,也可以理解为单调递增。变量之间的这个单调趋势很值得去探索,但是大多数人习惯使用标准相关系数导致无法发现这一趋势。在我的印象中,老师在课堂上经常强调:我们现在所说的、以及以后所说的相关都指线性相关。所以,每当我们一提到相关性或者探寻变量间的相关性时,脑海里便跳出了线性相关。把变量间的相关性限制成了线性相关

Pearson相关系数,通常是学生们学到的计算相关系数的唯一,此方法倾向于研究线性趋势。只有Spearman相关系数,实际上用于检测一般单调趋势,而这种方法通常在课堂上老师没有讲解。

我们可以借助R软件,模拟随着x的多项式次数的增加,PearsonSpearman相关系数的变化规律。代码如下:

corTest <- function(degree, method){
  x <- 1:50
  y <- x ** degree
  corr <- cor(x, y, method=method)
  return(corr)
}

degree <- 1:50
pearson <- sapply(degree, corTest, method='pearson')
spearman <- sapply(degree, corTest, method='spearman')
types <- rep(c('pearson', 'spearman'), each = 50)

data <- data.frame(degree, types, corr=c(pearson, spearman))
colors=c(rgb(0.7,0.3,0.1,0.5) , rgb(0.2,0.2,0.9,0.5))

library(lattice)
xyplot(corr ~ degree, data, groups = types, type = "a",
       auto.key=list(corner=c(0.1,0.9), points=FALSE, lines=FALSE, col=colors, cex=1.3),
       lwd=5, col=colors,
       xlab="Degree of Polynomial",
       ylab="Correlation Coefficient",
       main="Pearson vs. Spearman Correlaton")

从下图中我们可以看出:如果Pearson相关系数确实检测到了单调趋势,那么随着x多项式次数的增加,Pearson相关系数会向0靠拢,但不会为0。此时,使用Spearman相关系数会更加精确。

上一篇下一篇

猜你喜欢

热点阅读