使用R计算相关系数

http://zoonek2.free.fr/UNIX/48_R/09.html
使用R计算相关系数的函数为:

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


转载自:http://blog.sciencenet.cn/blog-54276-239625.html


学习链接:

http://zoonek2.free.fr/UNIX/48_R/09.html

http://www.cnblogs.com/zhangchaoyang/articles/2631907.html

http://blog.csdn.net/qq_33683364/article/details/53992564


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值