能给我讲一讲R语言中cor函数的用法吗,以及具体的实现步骤呢?

如题所述

cor.test(X,Y,method="")

method可以为"spearman","pearson" and "kendall",分别对应三种相关系数的计算和检验。

1 perrson相关系数
> n <- 10
> x <- rnorm(n)
> y <- rnorm(n)

> cor(x,y)
[1] -0.4132864

> cor.test(x,y)
Pearson's product-moment correlation
data: x and y
t = -1.2837, df = 8, p-value = 0.2352
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
-0.8275666 0.2924366
sample estimates:
cor
-0.4132864

上面给出了相关系数的可信度区间和P-value

2 spearman相关系数和
kendall相关系数

同上,只要把method改成spearman和kendall
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2017-07-06
x and y are both vectors with the same length. cor(x,y) would return the correlation coefficient.本回答被网友采纳
相似回答