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

看下这个,非常有用: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. PrimeNG之Validation

    Validation ----primeng输入组件显示验证错误时自动标记为无效值. demo code export class ValidationDemo implements OnInit { ...

  2. java之动态代理

    摘要 相比于静态代理,动态代理避免了开发人员编写各个繁锁的静态代理类,只需简单地指定一组接口及目标类对象就能动态的获得代理对象. 这里说的静态代理可以理解为之前使用的装饰者模式,从之前使用装饰者模式实 ...

  3. python if 和 else

    money = input("请输入你在学校有多少钱?")if int(money) > 5000: print("这个月可以潇洒潇洒了,每天可以出去吃大餐了.&q ...

  4. SpringBoot内置Tomcat缓存文件目录被意外删除导致异常

    在项目中,一般会将文件临时保存到缓存目录 当时使用 File.createTempFile("tmp", ext, (File) request.getServletContext ...

  5. 抓取html 生成图片

      <!DOCTYPE html>   <html>   <head>   <script type="text/javascript" ...

  6. stl string的erase方法

    ; i < s.size(); i++) { ') { s.erase(i,); i--; } } 删除string中的所有0.

  7. 家庭记账本之微信小程序(四)

    json的学习 JSON:JavaScript 对象表示法(JavaScript Object Notation). JSON 是存储和交换文本信息的语法.类似 XML. JSON 比 XML 更小. ...

  8. Python记录9:函数4:名称空间作用域+闭包函数+装饰器

    ''' 一: 名称空间namespaces     名称空间就是存放名字与值绑定关系的内存空间 二: 名称空间分为三种     内置名称空间:         1. 特点: 存放是python解释器自 ...

  9. Python之猴子补丁

    1.在运行时,对属性,方法,函数等进行动态替换 2.其目的往往是为了通过替换,修改来增强,扩展原有代码的能力 #test2.py class Person: def get_score(self): ...

  10. Vue系列之 => 路由匹配

    路由基本使用,加动画切换 1 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...