生信喵 发表于 2022-9-4 20:09:24

相关性检验

       利用 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])
页: [1]
查看完整版本: 相关性检验