这几个概念不能混淆,估计大部分人都没有完全搞懂这几个概念。

看下这个,非常有用:Interpret the key results for Correlation

euclidean | maximum | manhattan | canberra | binary | minkowski

初级

先演示一下相关性:

a <- c(1,2,3,4)
b <- c(2,4,6,8)
c <- data.frame(x=a,y=b)
plot(c)
cor(t(c))

> cor(t(c))
[,1] [,2] [,3] [,4]
[1,] 1 1 1 1
[2,] 1 1 1 1
[3,] 1 1 1 1
[4,] 1 1 1 1  

初步结论:

1. 相关性是用来度量两个变量之间的线性关系的;

2. 如果在不同的sample中,x随着y的增大而增大,那么x和y就是正相关,反之则是负相关;

接下来求距离:

> dist(c, method = "euclidean")
1 2 3
2 2.236068
3 4.472136 2.236068
4 6.708204 4.472136 2.236068
> sqrt(2^2+1^2)
[1] 2.236068

  

初步结论:

1. 距离是在特定的坐标体系中,两点之间的距离求解;

2. 距离可以用来表征相似度,比如1和2就比1和4更相似;

3. 欧氏距离就是我们最常见的几何距离,比较直观;

  

那么什么时候求相关性,什么时候求相似度呢?

基因表达当然要求相关性了,共表达都是在求相关性,就是基因A和B会在不同样本间同增同减,所以相关性是对变量而言的,暂时还没听说对样品求相关性,没有意义,总不能说在这些基因中,某些样本的表达同增同减吧。

那么样本最常见的应该是求相似度了,我想知道样本A是和样本B更相似,还是和样本C更相似,在共同的基因坐标下求个距离就知道了。

进阶

1. 不同的求相关性的方法有何差异?

2. 不同的距离计算的方法有何差异?

3. 相关性分析有哪些局限性?

简单介绍一下pearson和spearman的区别

x=(1:100)
y=exp(x)
cor(x,y,method = "pearson") # 0.25
cor(x,y,method = "spearman") # 1
plot(x,y)

结论:

pearson判断的是线性相关性,

而spearman还可以判断非线性的。monotonic relationship,更专业的说是单调性。

参考:Correlation (Pearson, Kendall, Spearman)  

outlier对相关性的影响

x = 1:100
y = 1:100
cor(x,y,method = "pearson") # 1
y[100] <- 1000
cor(x,y,method = "pearson") # 0.448793
cor(x,y,method = "spearman") # 1 y[99] <- 0
cor(x,y,method = "spearman") # 0.9417822

结论:

单个的outlier对pearson的影响非常大,但是对spearman的影响则比较小。

皮尔逊相关系数 其实是衡量 两个变量线性相关程度大小的指标,但它的值的大小并不能完全地反映两个变量的真实关系。

只有当两个变量的标准差都不为零,相关系数才有意义。

距离计算方法总结

关于相关系数的一些理解误区

Pearson, Kendall, Spearman三种相关性的差异

distance measure

euclidean | maximum | manhattan | canberra | binary | minkowski

k-NN 4: which distance function?

distance measure euclidean

euclidean:
Usual distance between the two vectors (2 norm aka L_2), sqrt(sum((x_i - y_i)^2)).

maximum:
Maximum distance between two components of x and y (supremum norm)

manhattan:
Absolute distance between the two vectors (1 norm aka L_1).

canberra:
sum(|x_i - y_i| / (|x_i| + |y_i|)). Terms with zero numerator and denominator are omitted from the sum and treated as if the values were missing.

This is intended for non-negative values (e.g., counts), in which case the denominator can be written in various equivalent ways; Originally, R used x_i + y_i, then from 1998 to 2017, |x_i + y_i|, and then the correct |x_i| + |y_i|.

binary:
(aka asymmetric binary): The vectors are regarded as binary bits, so non-zero elements are ‘on’ and zero elements are ‘off’. The distance is the proportion of bits in which only one is on amongst those in which at least one is on.

minkowski:
The p norm, the pth root of the sum of the pth powers of the differences of the components.

待续~

相似性 similarity | Pearson | Spearman | p-value | 相关性 correlation | 距离 distance | distance measure的更多相关文章

  1. 三大相关系数: pearson, spearman, kendall(python示例实现)

    三大相关系数:pearson, spearman, kendall 统计学中的三大相关性系数:pearson, spearman, kendall,他们反应的都是两个变量之间变化趋势的方向以及程度,其 ...

  2. Kendall’s tau-b,pearson、spearman三种相关性的区别(有空整理信息检索评价指标)

    同样可参考: http://blog.csdn.net/wsywl/article/details/5889419 http://wenku.baidu.com/link?url=pEBtVQFzTx ...

  3. 相关性分析 -pearson spearman kendall相关系数

    先说独立与相关的关系:对于两个随机变量,独立一定不相关,不相关不一定独立.有这么一种直观的解释(不一定非常准确):独立代表两个随机变量之间没有任何关系,而相关仅仅是指二者之间没有线性关系,所以不难推出 ...

  4. 【转】Pearson,Spearman,Kendall相关系数的具体分析

    测量相关程度的相关系数很多,各种参数的计算方法及特点各异. 连续变量的相关指标: 此时一般用积差相关系数,又称pearson相关系数来表示其相关性的大小,积差相关系数只适用于两变量呈线性相关时.其数值 ...

  5. 统计学三大相关性系数:pearson,spearman,kendall

    目录 person correlation coefficient(皮尔森相关性系数-r) spearman correlation coefficient(斯皮尔曼相关性系数-p) kendall ...

  6. Jaccard similarity(杰卡德相似度)和Abundance correlation(丰度相关性)

    杰卡德距离(Jaccard Distance) 是用来衡量两个集合差异性的一种指标,它是杰卡德相似系数的补集,被定义为1减去Jaccard相似系数.而杰卡德相似系数(Jaccard similarit ...

  7. 【概率论】4-6:协方差和相关性(Covariance and Correlation)

    title: [概率论]4-6:协方差和相关性(Covariance and Correlation) categories: - Mathematic - Probability keywords: ...

  8. 相似性度量(Similarity Measurement)与“距离”(Distance)

    在做分类时常常需要估算不同样本之间的相似性度量(Similarity Measurement),这时通常采用的方法就是计算样本间的“距离”(Distance).采用什么样的方法计算距离是很讲究,甚至关 ...

  9. 机器学习中的相似性度量(Similarity Measurement)

    机器学习中的相似性度量(Similarity Measurement) 在做分类时常常需要估算不同样本之间的相似性度量(Similarity Measurement),这时通常采用的方法就是计算样本间 ...

随机推荐

  1. centos7更改网卡名称

    1.编辑/etc/sysconfig/grub文件,加入net.ifnames=0 biosdevname=0 2.执行命令grub2-mkconfig -o /boot/grub2/grub.cfg ...

  2. c->log技巧

    介绍: 在C代码里,有时会加入一些打印信息方便分析问题,可用如下代码替代打印函数,更加方便. // // Created by lady on 18-12-10. // #include <st ...

  3. Cestos7安装Elasticsearch5.4.3

    Elasticsearch及配件下载地址:https://www.elastic.co/cn/downloads 为了简单起见,我们使用tar文件. 在/usl下创建elk目录 一.安装elastic ...

  4. linux出现tmp空间满的情况解决

    cd命令tab补全的时候报错: cd /ro-bash: cannot create temp file for here-document: No space left on device-bash ...

  5. 16.2-uC/OS-III同步 (事件标志组)

    事件标志组 1.当任务要与多个事件同步时可以使用事件标志.若其中的任意一个事件发生时任务被就绪, 叫做逻辑或(OR).若所有的事件都发生时任务被就绪,叫做逻辑与( AND). 2.用户可以创建任意个事 ...

  6. Python3学习之路~5.12 hashlib & hmac & md5 & sha模块

    hashlib模块用于加密相关的操作,3.x里代替了md5模块和sha模块,主要提供 SHA1, SHA224, SHA256, SHA384, SHA512 ,MD5 算法 import md5 h ...

  7. Java的反射机制的详细应用

    package com.at221; import java.io.Serializable; import java.lang.reflect.*; import org.junit.Test; p ...

  8. php中获取中文首字母程序代码

    年会抽奖,要求一等奖的中奖概率是0.12%,二等奖中奖概率是3%,三等奖中奖概率是12%,其他中奖概率是都是谢谢惠顾. <?php /** * 抽奖 * @param int $total */ ...

  9. Lua 求当前月份的最大天数

    [1]实现代码 -- 第一种方式:简写 , day = })) print('The first way result : dayAmount = ' .. dayAmount) -- 第二种方式:分 ...

  10. 用java生成32位全球唯一的id编号

    GUID是一个128位长的数字,一般用16进制表示.算法的核心思想是结合机器的网卡.当地时间.一个随即数来生成GUID.从理论上讲,如果一台机器每秒产生10000000个GUID,则可以保证(概率意义 ...