加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

使用R做相关性分析和计算相关系数

(2019-01-14 11:31:52)
分类: 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

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有