一、基本原理
在stat包中实现了皮尔逊(Pearson)与 斯皮尔曼(Spearman)两类相关系数的计算
(1)Pearson: (x,y)协方差/[(x标准方差)*(y标准方差)]
- 详情可以参考: http://zh.wikipedia.org/wiki/%E7%9A%AE%E5%B0%94%E9%80%8A%E7%A7%AF%E7%9F%A9%E7%9B%B8%E5%85%B3%E7%B3%BB%E6%95%B0
- 协方差:
- 方差:
- 标准方差:
- 协方差与方差关系:
- 协方差矩阵:
- 因此,pearson相关系数的关键就是计算协方差矩阵即可
- (2)Spearman : 等级变量之间的 皮尔逊相关系数。将向量x、y根据值大小排序,然后根据排序后的序号计算Pearson相关系数