pearson与spearman相关系数的比较

作者: 生信编程日常 | 来源:发表于2020-04-17 16:46 被阅读0次

    相关性(correlation)是指两个随机变量之间的关系,可以衡量两个变量间关系的强弱和方向。一般我们常用的是皮尔森相关系数和斯皮尔曼相关系数。

    皮尔森相关系数(pearson correlation coefficient, PCC)是衡量两个连续型变量的线性相关关系。

    pearson_wiki

    斯皮尔曼相关系数(spearman's rank correlation coefficient, SCC)是衡量两变量之间的单调关系,两个变量同时变化,但是并非同样速率变化,即并非一定是线性关系。


    spearman_wiki

    某些情况下两种结果是一致的:


    线性相关 随机

    当不完全是线性关系时:


    另外,当有离群点时,两者的处理是明显不同的。创建一个数据集,并且加上离群点:

    x1 <- rnorm(200)
    y1 <- rnorm(200) + .6 * x1
    
    #  加入离群点
    x2 <- c(x1, 14)
    y2 <- c(y1, 14)
    
    # Plot 
    par(mfrow=c(1,2))
    plot(x1, y1, main="No outlier", col = 4, pch = 7, cex = 0.8)
    plot(x2, y2, main="With outlier", col = 6, pch = 7, cex = 0.8)
    
    
    # Calculate correlations 
    round(cor(x1, y1, method="pearson"), 2)
    round(cor(x1, y1, method="spearman"), 2)
    round(cor(x2, y2, method="pearson"), 2)
    round(cor(x2, y2, method="spearman"), 2)
    

    相关系数输出:


    即在没有离群点的时候,两者都是0.44;但是当存在离群点之后,pearson系数变成了0.69,但是spearman仍是0.44。spearman系数会考虑这种存在离群点的情况,更加稳定。

    参考:
    (1) https://stats.stackexchange.com/questions/11746/what-could-cause-big-differences-in-correlation-coefficient-between-pearsons-an
    (2) https://support.minitab.com/en-us/minitab-express/1/help-and-how-to/modeling-statistics/regression/supporting-topics/basics/a-comparison-of-the-pearson-and-spearman-correlation-methods/

    欢迎大家关注啊!


    相关文章

      网友评论

        本文标题:pearson与spearman相关系数的比较

        本文链接:https://www.haomeiwen.com/subject/gnsyvhtx.html