1. 相关系数的显著性水平(Correlation significance levels (p-value))
library(Hmisc)
## 计算相关性和显著水平 (as.matrix(data) 表示将 data 转换成矩阵)
rcorr(as.matrix(data))
mpg disp hp drat wt qsec
mpg 1.00 -0.85 -0.78 0.68 -0.87 0.42
disp -0.85 1.00 0.79 -0.71 0.89 -0.43
hp -0.78 0.79 1.00 -0.45 0.66 -0.71
drat 0.68 -0.71 -0.45 1.00 -0.71 0.09
wt -0.87 0.89 0.66 -0.71 1.00 -0.17
qsec 0.42 -0.43 -0.71 0.09 -0.17 1.00
mpg disp hp drat wt qsec
mpg 0.0000 0.0000 0.0000 0.0000 0.0171
disp 0.0000 0.0000 0.0000 0.0000 0.0131
hp 0.0000 0.0000 0.0100 0.0000 0.0000
drat 0.0000 0.0000 0.0100 0.0000 0.6196
wt 0.0000 0.0000 0.0000 0.0000 0.3389
qsec 0.0171 0.0131 0.0000 0.6196 0.3389
2. 相关性热图
## heatmap 可视化
col = colorRampPalette(c("blue", "white", "red"))(20)
heatmap(x = cor_matr, col = col, symm = TRUE)

Heatmap
3. 相关性图
library(corrplot)
corrplot(cor_matr, type="upper", order="hclust", tl.col="black", tl.srt=45)

三角⚪
4. 相关性分布图
library(PerformanceAnalytics)
chart.Correlation(data,histogram = TRUE,pch=19)

相关性
参考链接:
http://www.sthda.com/english/wiki/correlation-matrix-a-quick-start-guide-to-analyze-format-and-visualize-a-correlation-matrix-using-r-software
网友评论