利用 R 进行数据挖掘,数据来源于著名的 state.x77 数据集。这个数据集提供了美国 50 个州在 1997 年人口、收 入、文盲率、预期寿命、谋杀率和高中毕业率、气温以及土地面积的数据。通过数据搜集的信息,想知道哪些因素与谋杀率相关性较高。
计算相关性系数
R 可以计算多种相关系数,包括 Pearson 相关系数、Spearman 相关系数、Kendall 相关系数、偏相关系数等。直接利 用 cor()函数即可计算,输入数据必须是一个矩阵。
例如可以计算基因与表型之间的关联。一般绝对值大于0.5认为相关。
#计算相关性矩阵
colnames(state.x77)
cor.test(state.x77[,5], state.x77[,1])
plot(state.x77[,5], state.x77[,1])
cor.test(state.x77[,5], state.x77[,2])
cor.test(state.x77[,5], state.x77[,3])
cor.test(state.x77[,5], state.x77[,4])
cor.test(state.x77[,5], state.x77[,4],method = 'spearman')
cor(state.x77)
round(cor(state.x77),digits = 2)
cor.test(state.x77[,5], state.x77[,6])
写在最后:有时间我们会努力更新的。大家互动交流可以前去论坛,地址在下面,复制去浏览器即可访问,弥补下公众号没有留言功能的缺憾。原地址暂未启用(bioinfoer.com)。
sx.voiceclouds.cn
有些板块也可以预设为大家日常趣事的分享等,欢迎大家来提建议。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有