不同的系数 corrplot() 和 cor.test()

different coefficient corrplot() and cor.test()

我计算了航班数据集所有可能组合的相关系数。我首先使用 corrplot 做到了这一点。组合小时和 sched_dep_time 的系数为 1。但是使用 cor.test() 它告诉我值接近 1 但为 0.9906496.

这是我的代码:

# the corrplot
a <- flights %>% select(year, month, day, dep_time, sched_dep_time, dep_delay, arr_time, sched_arr_time, arr_delay, flight, air_time, distance, hour, minute)
corrplot(cor(na.omit(a)), method = "number")
# using cor.test
cor.test(flights$hour, flights$sched_dep_time, method = "pearson")

这种差异的解释是什么?

这似乎是一个四舍五入的问题。当你做

library("corrplot")
corrplot(cor(na.omit(a)), method = "number", number.digits=4, number.cex=.5)

系数匹配得更好。