高山流水分享 http://blog.sciencenet.cn/u/friendpine 走在科学路上的一位无名侠客,只是静静的走着.........

博文

使用R计算相关系数

已有 51017 次阅读 2009-6-22 14:42 |个人分类:统计学与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




https://m.sciencenet.cn/blog-54276-239625.html

上一篇:发现一个社科类的数据库
下一篇:R语言中的常用函数

3 王水 江白 赵星

发表评论 评论 (4 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-6-2 11:05

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部